From c16d9c0c89c5bb67e840bca48014c5dc7a9cea62 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 25 Apr 2022 11:54:07 +0200 Subject: [PATCH] Auto save after paragraphs --- .../eu/faircode/email/FragmentCompose.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index cfeda1152e..96c0801c92 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -740,6 +740,12 @@ public class FragmentCompose extends FragmentBase { if (renum) StyleHelper.renumber(text, false, etBody.getContext()); + + etBody.setTag(null); + + Bundle extras = new Bundle(); + extras.putBoolean("silent", true); + onAction(R.id.action_save, extras, "paragraph"); } catch (Throwable ex) { Log.e(ex); } finally { @@ -4113,7 +4119,6 @@ public class FragmentCompose extends FragmentBase { args.putBoolean("ime", ime); args.putBundle("extras", extras); - Log.i("Run execute id=" + working + " reason=" + reason); actionLoader.execute(this, args, "compose:action:" + getActionName(action)); } @@ -5597,11 +5602,17 @@ public class FragmentCompose extends FragmentBase { private SimpleTask actionLoader = new SimpleTask() { @Override protected void onPreExecute(Bundle args) { + if (args.getBundle("extras").getBoolean("silent")) + return; + setBusy(true); } @Override protected void onPostExecute(Bundle args) { + if (args.getBundle("extras").getBoolean("silent")) + return; + int action = args.getInt("action"); boolean needsEncryption = args.getBoolean("needsEncryption"); if (action != R.id.action_check || needsEncryption) @@ -5627,6 +5638,8 @@ public class FragmentCompose extends FragmentBase { boolean notext = args.getBoolean("notext"); Bundle extras = args.getBundle("extras"); + boolean silent = extras.getBoolean("silent"); + boolean dirty = false; String body = HtmlHelper.toHtml(spanned, context); EntityMessage draft; @@ -5800,7 +5813,7 @@ public class FragmentCompose extends FragmentBase { Elements ref = doc.select("div[fairemail=reference]"); ref.remove(); - if (extras != null && extras.containsKey("html")) + if (extras.containsKey("html")) dirty = true; if (below != write_below && @@ -5832,7 +5845,7 @@ public class FragmentCompose extends FragmentBase { // Get saved body Document d; - if (extras != null && extras.containsKey("html")) { + if (extras.containsKey("html")) { // Save current revision Document c = JsoupEx.parse(body); @@ -5947,6 +5960,12 @@ public class FragmentCompose extends FragmentBase { db.message().setMessageSent(draft.id, draft.sent); } + if (silent) { + // Skip storing on the server, etc + db.setTransactionSuccessful(); + return draft; + } + // Execute action boolean encrypted = extras.getBoolean("encrypted"); boolean shouldEncrypt = EntityMessage.PGP_SIGNENCRYPT.equals(draft.ui_encrypt) || @@ -6268,6 +6287,12 @@ public class FragmentCompose extends FragmentBase { if (draft == null) return; + bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(draft.revision > 1); + bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision < draft.revisions); + + if (args.getBundle("extras").getBoolean("silent")) + return; + boolean needsEncryption = args.getBoolean("needsEncryption"); int action = args.getInt("action"); Log.i("Loaded action id=" + draft.id + @@ -6298,9 +6323,6 @@ public class FragmentCompose extends FragmentBase { if (show) showDraft(draft, refedit, null, -1); - bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(draft.revision > 1); - bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision < draft.revisions); - if (needsEncryption) { if (ActivityBilling.isPro(getContext()) || EntityMessage.PGP_SIGNONLY.equals(draft.ui_encrypt) ||