Improved plain text only check

pull/194/merge
M66B 3 years ago
parent c56151750b
commit 721be14b4d

@ -3817,12 +3817,6 @@ public class FragmentCompose extends FragmentBase {
Editable e = etBody.getText(); Editable e = etBody.getText();
boolean notext = e.toString().trim().isEmpty(); 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(); Bundle args = new Bundle();
args.putLong("id", working); args.putLong("id", working);
@ -3839,7 +3833,6 @@ public class FragmentCompose extends FragmentBase {
args.putBoolean("signature", cbSignature.isChecked()); args.putBoolean("signature", cbSignature.isChecked());
args.putBoolean("empty", isEmpty()); args.putBoolean("empty", isEmpty());
args.putBoolean("notext", notext); args.putBoolean("notext", notext);
args.putBoolean("formatted", formatted);
args.putBoolean("interactive", getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)); args.putBoolean("interactive", getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED));
args.putInt("focus", focus == null ? -1 : focus.getId()); args.putInt("focus", focus == null ? -1 : focus.getId());
if (focus instanceof EditText) { if (focus instanceof EditText) {
@ -5792,6 +5785,9 @@ public class FragmentCompose extends FragmentBase {
d.select("div[fairemail=reference]").isEmpty()) d.select("div[fairemail=reference]").isEmpty())
args.putBoolean("remind_text", true); args.putBoolean("remind_text", true);
boolean styled = HtmlHelper.isStyled(d);
args.putBoolean("styled", styled);
int attached = 0; int attached = 0;
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (!attachment.available) if (!attachment.available)
@ -6029,7 +6025,7 @@ public class FragmentCompose extends FragmentBase {
boolean remind_subject = args.getBoolean("remind_subject", false); boolean remind_subject = args.getBoolean("remind_subject", false);
boolean remind_text = args.getBoolean("remind_text", false); boolean remind_text = args.getBoolean("remind_text", false);
boolean remind_attachment = args.getBoolean("remind_attachment", 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) + int recipients = (draft.to == null ? 0 : draft.to.length) +
(draft.cc == null ? 0 : draft.cc.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_dsn || remind_size || remind_pgp || remind_smime ||
remind_to || remind_noreply || remind_external || remind_to || remind_noreply || remind_external ||
recipients > RECIPIENTS_WARNING || recipients > RECIPIENTS_WARNING ||
(formatted && draft.isPlainOnly()) || (styled && draft.isPlainOnly()) ||
(send_reminders && (send_reminders &&
(remind_extra || remind_subject || remind_text || remind_attachment))) { (remind_extra || remind_subject || remind_text || remind_attachment))) {
setBusy(false); setBusy(false);
@ -6841,7 +6837,7 @@ public class FragmentCompose extends FragmentBase {
final boolean remind_subject = args.getBoolean("remind_subject", false); final boolean remind_subject = args.getBoolean("remind_subject", false);
final boolean remind_text = args.getBoolean("remind_text", false); final boolean remind_text = args.getBoolean("remind_text", false);
final boolean remind_attachment = args.getBoolean("remind_attachment", 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 size = args.getLong("size", -1);
final long max_size = args.getLong("max_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() { cbPlainOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { 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(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);

@ -2291,6 +2291,49 @@ public class HtmlHelper {
return false; return false;
} }
static boolean isStyled(Document d) {
ObjectHolder<Boolean> result = new ObjectHolder<>(false);
d.body().filter(new NodeFilter() {
private final List<String> 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) { static void collapseQuotes(Document document) {
document.body().filter(new NodeFilter() { document.body().filter(new NodeFilter() {
private int level = 0; private int level = 0;

Loading…
Cancel
Save