Refactoring

pull/147/head
M66B 6 years ago
parent 4df54faed6
commit d515f1aafa

@ -816,7 +816,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
@Override
protected SpannableStringBuilder onLoad(final Context context, final Bundle args) {
protected SpannableStringBuilder onLoad(Context context, final Bundle args) {
DB db = DB.getInstance(context);
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
if (body == null)
try {
@ -824,7 +825,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} catch (IOException ex) {
Log.e(ex);
body = ex.toString();
DB.getInstance(context).message().setMessageContent(message.id, false, null);
db.message().setMessageContent(message.id, false, null);
}
Spanned html = decodeHtml(message, body);

@ -1241,9 +1241,8 @@ public class FragmentCompose extends FragmentEx {
result.draft.id = db.message().insertMessage(result.draft);
result.draft.write(context, body == null ? "" : body);
String text = (body == null ? null : Jsoup.parse(body).text());
String preview = (text == null ? null : text.substring(0, Math.min(text.length(), 250)));
db.message().setMessageContent(result.draft.id, true, preview);
db.message().setMessageContent(
result.draft.id, true, HtmlHelper.getPreview(body));
if ("new".equals(action)) {
ArrayList<Uri> uris = args.getParcelableArrayList("attachments");
@ -1657,9 +1656,8 @@ public class FragmentCompose extends FragmentEx {
if (dirty) {
db.message().updateMessage(draft);
draft.write(context, body);
String text = (body == null ? null : Jsoup.parse(body).text());
String preview = (text == null ? null : text.substring(0, Math.min(text.length(), 250)));
db.message().setMessageContent(draft.id, true, preview);
db.message().setMessageContent(
draft.id, true, HtmlHelper.getPreview(body));
}
// Execute action

@ -41,8 +41,6 @@ import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Spinner;
import org.jsoup.Jsoup;
import java.io.IOException;
import androidx.annotation.NonNull;
@ -229,10 +227,9 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
EntityMessage message = db.message().getMessage(id);
try {
Log.i("Building preview id=" + id);
String html = message.read(context);
String text = (html == null ? null : Jsoup.parse(html).text());
String preview = (text == null ? null : text.substring(0, Math.min(text.length(), 250)));
db.message().setMessageContent(message.id, true, preview);
String body = message.read(context);
db.message().setMessageContent(
message.id, true, HtmlHelper.getPreview(body));
} catch (IOException ex) {
Log.e(ex);
db.message().setMessageContent(message.id, false, null);

@ -247,4 +247,9 @@ public class HtmlHelper {
Html.escapeHtml(MessageHelper.getFormattedAddresses(message.from, true)),
sanitize ? sanitize(html, true) : getBody(html));
}
static String getPreview(String body) {
String text = (body == null ? null : Jsoup.parse(body).text());
return (text == null ? null : text.substring(0, Math.min(text.length(), 250)));
}
}

@ -2475,11 +2475,10 @@ public class ServiceSynchronize extends LifecycleService {
if (!message.content)
if (!metered || (message.size != null && message.size < download)) {
String html = helper.getHtml();
String text = (html == null ? null : Jsoup.parse(html).text());
String preview = (text == null ? null : text.substring(0, Math.min(text.length(), PREVIEW_SIZE)));
message.write(context, html);
db.message().setMessageContent(message.id, true, preview);
String body = helper.getHtml();
message.write(context, body);
db.message().setMessageContent(
message.id, true, HtmlHelper.getPreview(body));
Log.i(folder.name + " downloaded message id=" + message.id + " size=" + message.size);
}

Loading…
Cancel
Save