Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed May 3, 2019
1 parent 295fe02 commit 858280d
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions app/src/main/java/eu/faircode/email/AdapterMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,12 @@ protected void onException(Bundle args, Throwable ex) {
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");
Expand Down Expand Up @@ -1032,10 +1034,12 @@ public void onChanged(@Nullable List<EntityAttachment> attachments) {
if (show_html)
onShowHtmlConfirmed(message);
else {
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");
Expand Down Expand Up @@ -1539,10 +1543,12 @@ private void onHideHtml(TupleMessageEx 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");
Expand Down Expand Up @@ -1674,10 +1680,12 @@ public void onClick(DialogInterface dialog, int which) {
private void onShowImagesConfirmed(final TupleMessageEx message) {
properties.setValue("images", message.id, true);

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);

Expand Down Expand Up @@ -1723,7 +1731,8 @@ protected void onException(Bundle args, Throwable ex) {
@Override
protected SpannableStringBuilder onExecute(final Context context, final Bundle args) {
DB db = DB.getInstance(context);
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
final TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
final boolean show_images = args.getBoolean("show_images");
boolean show_quotes = args.getBoolean("show_quotes");
int zoom = args.getInt("zoom");

Expand All @@ -1744,9 +1753,18 @@ protected SpannableStringBuilder onExecute(final Context context, final Bundle a
body = document.html();
}

Spanned html = decodeHtml(context, message, body);
String html = HtmlHelper.sanitize(context, body);
if (debug)
html += "<pre>" + Html.escapeHtml(html) + "</pre>";

SpannableStringBuilder builder = new SpannableStringBuilder(html);
Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(source, message.id, show_images, tvBody);
}
}, null);

SpannableStringBuilder builder = new SpannableStringBuilder(spanned);
QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
builder.setSpan(
Expand Down Expand Up @@ -1814,21 +1832,6 @@ protected void onException(Bundle args, Throwable ex) {
}
};

private Spanned decodeHtml(final Context context, final EntityMessage message, String body) {
final boolean show_images = properties.getValue("images", message.id);

String html = HtmlHelper.sanitize(context, body);
if (debug)
html += "<pre>" + Html.escapeHtml(html) + "</pre>";

return HtmlHelper.fromHtml(html, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(source, message.id, show_images, tvBody);
}
}, null);
}

private class TouchHandler extends ArrowKeyMovementMethod {
private TupleMessageEx message;

Expand Down Expand Up @@ -1881,8 +1884,11 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event
if (ddss.length > 0) {
properties.setValue("quotes", message.id, true);

boolean show_images = properties.getValue("images", message.id);

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");
Expand Down

0 comments on commit 858280d

Please sign in to comment.