From b8219720c7de558911e6cc38a1fbc0716d21c982 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 30 Mar 2019 09:19:33 +0000 Subject: [PATCH] Show images for original message only if having images --- .../eu/faircode/email/AdapterMessage.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 42bf7ab164..5ec7332908 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -1408,8 +1408,7 @@ public class AdapterMessage extends RecyclerView.Adapter() { + new SimpleTask() { @Override - protected String onExecute(Context context, Bundle args) throws IOException { + protected OriginalMessage onExecute(Context context, Bundle args) throws IOException { long id = args.getLong("id"); - return HtmlHelper.removeTracking(context, getHtmlEmbedded(id)); + + OriginalMessage original = new OriginalMessage(); + original.html = HtmlHelper.removeTracking(context, getHtmlEmbedded(id)); + + Document doc = Jsoup.parse(original.html); + for (Element img : doc.select("img")) { + Uri uri = Uri.parse(img.attr("src")); + if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) { + original.has_images = true; + break; + } + } + + return original; } @Override - protected void onExecuted(Bundle args, String html) { + protected void onExecuted(Bundle args, OriginalMessage original) { long id = args.getLong("id"); - properties.setHtml(id, html); + properties.setHtml(id, original.html); + if (!original.has_images) + properties.setValue("images", id, true); TupleMessageEx amessage = getMessage(); if (amessage == null || !amessage.id.equals(id)) return; - webView.loadDataWithBaseURL("email://", html, "text/html", "UTF-8", null); + boolean show_images = properties.getValue("images", id); + ibImages.setVisibility(show_images ? View.GONE : View.VISIBLE); + + webView.loadDataWithBaseURL("email://", original.html, "text/html", "UTF-8", null); boolean expanded = properties.getValue("expanded", id); pbBody.setVisibility(View.GONE); + tvBody.setVisibility(View.GONE); webView.setVisibility(expanded ? View.VISIBLE : View.GONE); } @@ -1557,6 +1575,11 @@ public class AdapterMessage extends RecyclerView.Adapter