From 31f6fedb310fd47f5a484d1747bf0f61aeb805a4 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 20 Jan 2023 07:49:38 +0100 Subject: [PATCH] Add option to automatically close conversations after sending messages --- .../eu/faircode/email/FragmentMessages.java | 32 +++++++++++++++---- .../email/FragmentOptionsBehavior.java | 12 +++---- .../res/layout/fragment_options_behavior.xml | 6 ++-- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 60a767a112..849029aed7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -243,6 +243,7 @@ import java.util.Map; import java.util.Objects; import java.util.Properties; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.function.Consumer; @@ -388,6 +389,7 @@ public class FragmentMessages extends FragmentBase private Long next = null; private Long closeId = null; private int autoCloseCount = 0; + private int lastSentCount = 0; private boolean autoExpanded = true; private Long lastSync = null; @@ -406,6 +408,9 @@ public class FragmentMessages extends FragmentBase private NumberFormat NF = NumberFormat.getNumberInstance(); + private static final ExecutorService executor = + Helper.getBackgroundExecutor(1, "more"); + private static final int MAX_MORE = 100; // messages private static final int MAX_SEND_RAW = 50; // messages private static final int SWIPE_DISABLE_SELECT_DURATION = 1500; // milliseconds @@ -3575,12 +3580,6 @@ public class FragmentMessages extends FragmentBase .putExtra("reference", message.id) .putExtra("selected", selected); startActivity(reply); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean autoclose_reply = prefs.getBoolean("autoclose_reply", false); - if (autoclose_reply && - ("reply".equals(action) || "reply_all".equals(action))) - finish(); } private void onMenuResend(TupleMessageEx message) { @@ -4591,6 +4590,7 @@ public class FragmentMessages extends FragmentBase outState.putBoolean("fair:reset", reset); outState.putBoolean("fair:autoExpanded", autoExpanded); outState.putInt("fair:autoCloseCount", autoCloseCount); + outState.putInt("fair:lastSentCount", lastSentCount); outState.putStringArray("fair:values", values.keySet().toArray(new String[0])); for (String name : values.keySet()) @@ -4617,6 +4617,7 @@ public class FragmentMessages extends FragmentBase reset = savedInstanceState.getBoolean("fair:reset"); autoExpanded = savedInstanceState.getBoolean("fair:autoExpanded"); autoCloseCount = savedInstanceState.getInt("fair:autoCloseCount"); + lastSentCount = savedInstanceState.getInt("fair:lastSentCount"); for (String name : savedInstanceState.getStringArray("fair:values")) if (!"selected".equals(name)) { @@ -6423,7 +6424,7 @@ public class FragmentMessages extends FragmentBase protected void onException(Bundle args, Throwable ex) { Log.unexpectedError(getParentFragmentManager(), ex); } - }.serial().setId("messages:" + FragmentMessages.this.hashCode()).execute(this, args, "quickactions"); + }.setExecutor(executor).setId("messages:" + FragmentMessages.this.hashCode()).execute(this, args, "quickactions"); } } else { fabMore.hide(); @@ -6671,9 +6672,26 @@ public class FragmentMessages extends FragmentBase SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean expand_first = prefs.getBoolean("expand_first", true); boolean expand_all = prefs.getBoolean("expand_all", false); + boolean autoclose_send = prefs.getBoolean("autoclose_send", false); long download = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE); boolean dup_msgids = prefs.getBoolean("dup_msgids", false); + if (autoclose_send) { + int sent = 0; + for (TupleMessageEx message : messages) + if (message != null && + (EntityFolder.OUTBOX.equals(message.folderType) || + EntityFolder.SENT.equals(message.folderType))) + sent++; + + if (lastSentCount > 0 && sent > lastSentCount) { + finish(); + return true; + } + + lastSentCount = sent; + } + // Mark duplicates Map> duplicates = new HashMap<>(); for (TupleMessageEx message : messages) { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index a15ae816f5..3628f8ad6a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -91,7 +91,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private TextView tvOnClose; private Spinner spOnClose; private SwitchCompat swAutoCloseUnseen; - private SwitchCompat swAutoCloseReply; + private SwitchCompat swAutoCloseSend; private SwitchCompat swCollapseMarked; private Spinner spUndoTimeout; private SwitchCompat swCollapseMultiple; @@ -113,7 +113,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe "pull", "autoscroll", "quick_filter", "quick_scroll", "quick_actions", "swipe_sensitivity", "foldernav", "doubletap", "swipenav", "volumenav", "reversed", "swipe_close", "swipe_move", "autoexpand", "expand_first", "expand_all", "expand_one", "collapse_multiple", - "autoclose", "onclose", "autoclose_unseen", "autoclose_reply", "collapse_marked", + "autoclose", "onclose", "autoclose_unseen", "autoclose_send", "collapse_marked", "undo_timeout", "autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance", "reset_snooze", "auto_block_sender", "swipe_reply" @@ -163,7 +163,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe tvOnClose = view.findViewById(R.id.tvOnClose); spOnClose = view.findViewById(R.id.spOnClose); swAutoCloseUnseen = view.findViewById(R.id.swAutoCloseUnseen); - swAutoCloseReply = view.findViewById(R.id.swAutoCloseReply); + swAutoCloseSend = view.findViewById(R.id.swAutoCloseSend); swCollapseMarked = view.findViewById(R.id.swCollapseMarked); spUndoTimeout = view.findViewById(R.id.spUndoTimeout); swAutoRead = view.findViewById(R.id.swAutoRead); @@ -455,10 +455,10 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe } }); - swAutoCloseReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + swAutoCloseSend.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("autoclose_reply", checked).apply(); + prefs.edit().putBoolean("autoclose_send", checked).apply(); } }); @@ -636,7 +636,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe spOnClose.setEnabled(!swAutoClose.isChecked()); swAutoCloseUnseen.setChecked(prefs.getBoolean("autoclose_unseen", false)); - swAutoCloseReply.setChecked(prefs.getBoolean("autoclose_reply", false)); + swAutoCloseSend.setChecked(prefs.getBoolean("autoclose_send", false)); swCollapseMarked.setChecked(prefs.getBoolean("collapse_marked", true)); int undo_timeout = prefs.getInt("undo_timeout", 5000); diff --git a/app/src/main/res/layout/fragment_options_behavior.xml b/app/src/main/res/layout/fragment_options_behavior.xml index b339017eab..6da21433ed 100644 --- a/app/src/main/res/layout/fragment_options_behavior.xml +++ b/app/src/main/res/layout/fragment_options_behavior.xml @@ -624,12 +624,12 @@ app:switchPadding="12dp" /> Expand only one message at a time Collapse messages in a conversation with multiple messages on \'back\' Automatically close conversations - Automatically close conversations on reply + Automatically close conversations after sending messages On closing a conversation Close conversations on marking messages as unread Collapse messages which are manually marked as read or unread