From 47b04a9a13531b8a1a300bf734dc261eb9b2b51a Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 5 Feb 2020 14:01:52 +0100 Subject: [PATCH] Allow empty drafts explicitly saved --- .../java/eu/faircode/email/FragmentCompose.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index a534d0593a..1012b4279a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -240,6 +240,7 @@ public class FragmentCompose extends FragmentBase { private boolean show_images = false; private boolean autosave = false; private boolean busy = false; + private boolean saved = false; private Uri photoURI = null; @@ -2451,7 +2452,7 @@ public class FragmentCompose extends FragmentBase { private void onExit() { if (state != State.LOADED) finish(); - else if (isEmpty()) + else if (isEmpty() && !saved) onAction(R.id.action_delete); else { autosave = false; @@ -3277,6 +3278,8 @@ public class FragmentCompose extends FragmentBase { for (EntityAttachment attachment : attachments) if (!attachment.available) EntityOperation.queue(context, data.draft, EntityOperation.ATTACHMENT, attachment.id); + + args.putBoolean("saved", true); } db.setTransactionSuccessful(); @@ -3291,8 +3294,9 @@ public class FragmentCompose extends FragmentBase { @Override protected void onExecuted(Bundle args, final DraftData data) { + saved = args.getBoolean("saved"); final String action = getArguments().getString("action"); - Log.i("Loaded draft id=" + data.draft.id + " action=" + action); + Log.i("Loaded draft id=" + data.draft.id + " action=" + action + " saved=" + saved); working = data.draft.id; encrypt = data.draft.encrypt; @@ -3765,6 +3769,8 @@ public class FragmentCompose extends FragmentBase { } } } else { + args.putBoolean("saved", true); + Handler handler = new Handler(context.getMainLooper()); handler.post(new Runnable() { public void run() { @@ -3857,8 +3863,13 @@ public class FragmentCompose extends FragmentBase { @Override protected void onExecuted(Bundle args, EntityMessage draft) { + boolean wasSaved = args.getBoolean("saved"); int action = args.getInt("action"); - Log.i("Loaded action id=" + (draft == null ? null : draft.id) + " action=" + getActionName(action)); + Log.i("Loaded action id=" + (draft == null ? null : draft.id) + + " action=" + getActionName(action) + " saved=" + wasSaved); + + if (wasSaved) + saved = true; etTo.setText(MessageHelper.formatAddressesCompose(draft.to)); etCc.setText(MessageHelper.formatAddressesCompose(draft.cc));