Add option to automatically close conversations after sending messages

pull/212/head
M66B 2 years ago
parent d9dd4843bb
commit 31f6fedb31

@ -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<String, List<TupleMessageEx>> duplicates = new HashMap<>();
for (TupleMessageEx message : messages) {

@ -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);

@ -624,12 +624,12 @@
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoCloseReply"
android:id="@+id/swAutoCloseSend"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_autoclose_reply"
android:text="@string/title_advanced_autoclose_send"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoCloseUnseen"
@ -644,7 +644,7 @@
android:text="@string/title_advanced_collapse_marked"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoCloseReply"
app:layout_constraintTop_toBottomOf="@id/swAutoCloseSend"
app:switchPadding="12dp" />
<TextView

@ -638,7 +638,7 @@
<string name="title_advanced_expand_one">Expand only one message at a time</string>
<string name="title_advanced_collapse_multiple">Collapse messages in a conversation with multiple messages on \'back\'</string>
<string name="title_advanced_autoclose">Automatically close conversations</string>
<string name="title_advanced_autoclose_reply">Automatically close conversations on reply</string>
<string name="title_advanced_autoclose_send">Automatically close conversations after sending messages</string>
<string name="title_advanced_onclose">On closing a conversation</string>
<string name="title_advanced_autoclose_unread">Close conversations on marking messages as unread</string>
<string name="title_advanced_collapse_marked">Collapse messages which are manually marked as read or unread</string>

Loading…
Cancel
Save