1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Prevent crash

This commit is contained in:
M66B 2019-05-04 11:16:33 +02:00
parent 10c4deef60
commit af51ad6968

View file

@ -956,24 +956,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
pbBody.setVisibility(suitable || message.content ? View.VISIBLE : View.GONE); pbBody.setVisibility(suitable || message.content ? View.VISIBLE : View.GONE);
tvNoInternetBody.setVisibility(suitable || message.content ? View.GONE : View.VISIBLE); tvNoInternetBody.setVisibility(suitable || message.content ? View.GONE : View.VISIBLE);
if (message.content) if (show_html)
if (show_html) onShowHtmlConfirmed(message);
onShowHtmlConfirmed(message); else {
else { Spanned body = properties.getBody(message.id);
Spanned body = properties.getBody(message.id); tvBody.setText(body);
tvBody.setText(body); tvBody.setMovementMethod(null);
tvBody.setMovementMethod(null);
boolean show_images = properties.getValue("images", message.id); showText(message);
boolean show_quotes = properties.getValue("quotes", message.id); }
Bundle args = new Bundle();
args.putSerializable("message", message);
args.putBoolean("show_images", show_images);
args.putBoolean("show_quotes", show_quotes);
args.putInt("zoom", zoom);
bodyTask.execute(context, owner, args, "message:body");
}
} }
private void bindAttachments(final TupleMessageEx message, @Nullable List<EntityAttachment> attachments) { private void bindAttachments(final TupleMessageEx message, @Nullable List<EntityAttachment> attachments) {
@ -1033,20 +1024,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
adapterImage.set(images); adapterImage.set(images);
boolean show_html = properties.getValue("html", message.id); boolean show_html = properties.getValue("html", message.id);
if (message.content) if (show_html)
if (show_html) onShowHtmlConfirmed(message);
onShowHtmlConfirmed(message); else
else { showText(message);
boolean show_images = properties.getValue("images", message.id);
boolean show_quotes = properties.getValue("quotes", message.id);
Bundle args = new Bundle();
args.putSerializable("message", message);
args.putBoolean("show_images", show_images);
args.putBoolean("show_quotes", show_quotes);
args.putInt("zoom", zoom);
bodyTask.execute(context, owner, args, "message:body");
}
} }
private TupleMessageEx getMessage() { private TupleMessageEx getMessage() {
@ -1466,6 +1447,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (TextUtils.isEmpty(html)) { if (TextUtils.isEmpty(html)) {
webView.loadUrl("about:blank"); webView.loadUrl("about:blank");
if (!message.content)
return;
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
@ -1542,19 +1526,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvBody.setVisibility(View.INVISIBLE); tvBody.setVisibility(View.INVISIBLE);
vwBody.setVisibility(View.GONE); vwBody.setVisibility(View.GONE);
Spanned body = properties.getBody(message.id); showText(message);
tvBody.setText(body);
tvBody.setMovementMethod(null);
boolean show_images = properties.getValue("images", message.id);
boolean show_quotes = properties.getValue("quotes", message.id);
Bundle args = new Bundle();
args.putSerializable("message", message);
args.putBoolean("show_images", show_images);
args.putBoolean("show_quotes", show_quotes);
args.putInt("zoom", zoom);
bodyTask.execute(context, owner, args, "message:body");
} }
private class OriginalMessage { private class OriginalMessage {
@ -1685,24 +1657,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private void onShowImagesConfirmed(final TupleMessageEx message) { private void onShowImagesConfirmed(final TupleMessageEx message) {
properties.setValue("images", message.id, true); properties.setValue("images", message.id, true);
boolean show_images = properties.getValue("images", message.id); ibImages.setVisibility(View.GONE);
boolean show_quotes = properties.getValue("quotes", message.id);
Bundle args = new Bundle();
args.putSerializable("message", message);
args.putBoolean("show_images", show_images);
args.putBoolean("show_quotes", show_quotes);
args.putInt("zoom", zoom);
boolean show_html = properties.getValue("html", message.id); boolean show_html = properties.getValue("html", message.id);
if (show_html) if (show_html)
onShowHtmlConfirmed(message); onShowHtmlConfirmed(message);
else { else
ibImages.setVisibility(View.GONE); showText(message);
bodyTask.execute(context, owner, args, "message:body");
}
// Download inline images // Download inline images
Bundle args = new Bundle();
args.putSerializable("message", message);
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
@ -1732,24 +1698,30 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "show:images"); }.execute(context, owner, args, "show:images");
} }
private void showText(TupleMessageEx message) {
if (message.content) {
boolean show_images = properties.getValue("images", message.id);
boolean show_quotes = properties.getValue("quotes", message.id);
Bundle args = new Bundle();
args.putSerializable("message", message);
args.putBoolean("show_images", show_images);
args.putBoolean("show_quotes", show_quotes);
args.putInt("zoom", zoom);
bodyTask.execute(context, owner, args, "message:body");
}
}
private SimpleTask<SpannableStringBuilder> bodyTask = new SimpleTask<SpannableStringBuilder>() { private SimpleTask<SpannableStringBuilder> bodyTask = new SimpleTask<SpannableStringBuilder>() {
@Override @Override
protected SpannableStringBuilder onExecute(final Context context, final Bundle args) { protected SpannableStringBuilder onExecute(final Context context, final Bundle args) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
final TupleMessageEx message = (TupleMessageEx) args.getSerializable("message"); final TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
final boolean show_images = args.getBoolean("show_images"); final boolean show_images = args.getBoolean("show_images");
boolean show_quotes = args.getBoolean("show_quotes"); boolean show_quotes = args.getBoolean("show_quotes");
int zoom = args.getInt("zoom"); int zoom = args.getInt("zoom");
String body; String body = Helper.readText(message.getFile(context));
try {
body = Helper.readText(message.getFile(context));
} catch (IOException ex) {
Log.e(ex);
db.message().setMessageContent(message.id, false, null, null);
db.message().setMessageSize(message.id, null);
return null;
}
if (!show_quotes) { if (!show_quotes) {
Document document = Jsoup.parse(body); Document document = Jsoup.parse(body);
@ -1901,13 +1873,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
DynamicDrawableSpan[] ddss = buffer.getSpans(off, off, DynamicDrawableSpan.class); DynamicDrawableSpan[] ddss = buffer.getSpans(off, off, DynamicDrawableSpan.class);
if (ddss.length > 0) { if (ddss.length > 0) {
properties.setValue("quotes", message.id, true); properties.setValue("quotes", message.id, true);
showText(message);
Bundle args = new Bundle();
args.putSerializable("message", message);
args.putBoolean("show_images", show_images);
args.putBoolean("show_quotes", true);
args.putInt("zoom", zoom);
bodyTask.execute(context, owner, args, "message:body");
} }
} }