diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index ec5ef7454a..57f426a27e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -3817,12 +3817,6 @@ public class FragmentCompose extends FragmentBase { Editable e = etBody.getText(); boolean notext = e.toString().trim().isEmpty(); - boolean formatted = false; - for (Object span : e.getSpans(0, e.length(), Object.class)) - if (span instanceof CharacterStyle || span instanceof ParagraphStyle) { - formatted = true; - break; - } Bundle args = new Bundle(); args.putLong("id", working); @@ -3839,7 +3833,6 @@ public class FragmentCompose extends FragmentBase { args.putBoolean("signature", cbSignature.isChecked()); args.putBoolean("empty", isEmpty()); args.putBoolean("notext", notext); - args.putBoolean("formatted", formatted); args.putBoolean("interactive", getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)); args.putInt("focus", focus == null ? -1 : focus.getId()); if (focus instanceof EditText) { @@ -5792,6 +5785,9 @@ public class FragmentCompose extends FragmentBase { d.select("div[fairemail=reference]").isEmpty()) args.putBoolean("remind_text", true); + boolean styled = HtmlHelper.isStyled(d); + args.putBoolean("styled", styled); + int attached = 0; for (EntityAttachment attachment : attachments) if (!attachment.available) @@ -6029,7 +6025,7 @@ public class FragmentCompose extends FragmentBase { boolean remind_subject = args.getBoolean("remind_subject", false); boolean remind_text = args.getBoolean("remind_text", false); boolean remind_attachment = args.getBoolean("remind_attachment", false); - boolean formatted = args.getBoolean("formatted", false); + boolean styled = args.getBoolean("styled", false); int recipients = (draft.to == null ? 0 : draft.to.length) + (draft.cc == null ? 0 : draft.cc.length) + @@ -6039,7 +6035,7 @@ public class FragmentCompose extends FragmentBase { remind_dsn || remind_size || remind_pgp || remind_smime || remind_to || remind_noreply || remind_external || recipients > RECIPIENTS_WARNING || - (formatted && draft.isPlainOnly()) || + (styled && draft.isPlainOnly()) || (send_reminders && (remind_extra || remind_subject || remind_text || remind_attachment))) { setBusy(false); @@ -6841,7 +6837,7 @@ public class FragmentCompose extends FragmentBase { final boolean remind_subject = args.getBoolean("remind_subject", false); final boolean remind_text = args.getBoolean("remind_text", false); final boolean remind_attachment = args.getBoolean("remind_attachment", false); - final boolean formatted = args.getBoolean("formatted", false); + final boolean styled = args.getBoolean("styled", false); final long size = args.getLong("size", -1); final long max_size = args.getLong("max_size", -1); @@ -6972,7 +6968,7 @@ public class FragmentCompose extends FragmentBase { cbPlainOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - tvPlainHint.setVisibility(checked && formatted ? View.VISIBLE : View.GONE); + tvPlainHint.setVisibility(checked && styled ? View.VISIBLE : View.GONE); Bundle args = new Bundle(); args.putLong("id", id); diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index e9604d020f..70f4431f70 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -2291,6 +2291,49 @@ public class HtmlHelper { return false; } + static boolean isStyled(Document d) { + ObjectHolder result = new ObjectHolder<>(false); + + d.body().filter(new NodeFilter() { + private final List STRUCTURE = Collections.unmodifiableList(Arrays.asList( + "body", "div", "p", "span", "br", + "strong", "b", "em", "i", "blockquote", "hr" + )); + + @Override + public FilterResult head(Node node, int depth) { + if (node instanceof Element) { + Element e = (Element) node; + + if (STRUCTURE.contains(e.tagName())) + return FilterResult.CONTINUE; + + if (!TextUtils.isEmpty(e.attr("fairemail"))) + return FilterResult.CONTINUE; + + //Element p = e.parent(); + //if ("blockquote".equals(e.tagName()) && + // p != null && + // !TextUtils.isEmpty(p.attr("fairemail"))) + // return FilterResult.CONTINUE; + + Log.i("Style element=" + node); + result.value = true; + return FilterResult.STOP; + + } else + return FilterResult.CONTINUE; + } + + @Override + public FilterResult tail(Node node, int depth) { + return FilterResult.CONTINUE; + } + }); + + return result.value; + } + static void collapseQuotes(Document document) { document.body().filter(new NodeFilter() { private int level = 0;