From 91cd5fa20c72664db101c238ccfb722901e03319 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 18 Jul 2020 11:21:24 +0200 Subject: [PATCH] Added undo timeout setting --- .../eu/faircode/email/FragmentMessages.java | 75 ++++++++++--------- .../email/FragmentOptionsBehavior.java | 26 ++++++- .../res/layout/fragment_options_behavior.xml | 24 +++++- app/src/main/res/values/strings.xml | 17 +++++ 4 files changed, 106 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 308b4e82f2..c0855afb92 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -310,7 +310,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private NumberFormat NF = NumberFormat.getNumberInstance(); private static final int MAX_MORE = 100; // messages - private static final int UNDO_TIMEOUT = 5000; // milliseconds private static final int SWIPE_DISABLE_SELECT_DURATION = 1500; // milliseconds private static final float LUMINANCE_THRESHOLD = 0.7f; @@ -4681,6 +4680,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void moveUndo(ArrayList result) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + final int undo_timeout = prefs.getInt("undo_timeout", 5000); + Bundle args = new Bundle(); args.putParcelableArrayList("result", result); @@ -4692,7 +4694,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. DB db = DB.getInstance(context); long now = new Date().getTime(); - long busy = now + UNDO_TIMEOUT * 2; + long busy = now + undo_timeout * 2; try { db.beginTransaction(); @@ -4722,6 +4724,42 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } } + final Context context = getContext().getApplicationContext(); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + for (MessageTarget target : result) { + EntityMessage message = db.message().getMessage(target.id); + if (message == null || !message.ui_hide) + continue; + + Log.i("Move id=" + target.id + " target=" + target.folder.name); + db.message().setMessageUiBusy(target.id, null); + db.message().setMessageLastAttempt(target.id, new Date().getTime()); + EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id); + } + + db.setTransactionSuccessful(); + } catch (Throwable ex) { + Log.e(ex); + } finally { + db.endTransaction(); + } + + ServiceSynchronize.eval(context, "move"); + } + }, "messages:movetimeout"); + thread.setPriority(THREAD_PRIORITY_BACKGROUND); + + if (undo_timeout == 0) { + thread.start(); + return; + } + FragmentActivity factivity = getActivity(); if (!(factivity instanceof ActivityView)) { Log.e("Undo: activity missing"); @@ -4803,8 +4841,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. }); snackbar.show(); - final Context context = getContext().getApplicationContext(); - // Wait new Handler().postDelayed(new Runnable() { @Override @@ -4818,38 +4854,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. if (snackbar.isShown()) snackbar.dismiss(); - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - DB db = DB.getInstance(context); - try { - db.beginTransaction(); - - for (MessageTarget target : result) { - EntityMessage message = db.message().getMessage(target.id); - if (message == null || !message.ui_hide) - continue; - - Log.i("Move id=" + target.id + " target=" + target.folder.name); - db.message().setMessageUiBusy(target.id, null); - db.message().setMessageLastAttempt(target.id, new Date().getTime()); - EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id); - } - - db.setTransactionSuccessful(); - } catch (Throwable ex) { - Log.e(ex); - } finally { - db.endTransaction(); - } - - ServiceSynchronize.eval(context, "move"); - } - }, "messages:movetimeout"); - thread.setPriority(THREAD_PRIORITY_BACKGROUND); thread.start(); } - }, UNDO_TIMEOUT); + }, undo_timeout); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index e933b0f517..ddd910bbf3 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -73,6 +73,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private SwitchCompat swExpandOne; private SwitchCompat swAutoClose; private Spinner spOnClose; + private Spinner spUndoTimeout; private SwitchCompat swCollapseMultiple; private SwitchCompat swAutoRead; private SwitchCompat swFlagSnoozed; @@ -87,7 +88,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe "pull", "autoscroll", "quick_filter", "quick_scroll", "doubletap", "swipenav", "volumenav", "reversed", "autoexpand", "expand_all", "expand_one", "collapse_multiple", - "autoclose", "onclose", + "autoclose", "onclose", "undo_timeout", "autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance" }; @@ -121,6 +122,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swCollapseMultiple = view.findViewById(R.id.swCollapseMultiple); swAutoClose = view.findViewById(R.id.swAutoClose); spOnClose = view.findViewById(R.id.spOnClose); + spUndoTimeout = view.findViewById(R.id.spUndoTimeout); swAutoRead = view.findViewById(R.id.swAutoRead); swFlagSnoozed = view.findViewById(R.id.swFlagSnoozed); swAutoUnflag = view.findViewById(R.id.swAutoUnflag); @@ -307,6 +309,20 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe } }); + spUndoTimeout.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + int[] values = getResources().getIntArray(R.array.undoValues); + int value = values[position]; + prefs.edit().putInt("undo_timeout", value).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("undo_timeout").apply(); + } + }); + swAutoRead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -430,6 +446,14 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe spOnClose.setEnabled(!swAutoClose.isChecked()); + int undo_timeout = prefs.getInt("undo_timeout", 5000); + int[] undoValues = getResources().getIntArray(R.array.undoValues); + for (int pos = 0; pos < undoValues.length; pos++) + if (undoValues[pos] == undo_timeout) { + spUndoTimeout.setSelection(pos); + break; + } + swAutoRead.setChecked(prefs.getBoolean("autoread", false)); swFlagSnoozed.setChecked(prefs.getBoolean("flag_snoozed", false)); swAutoUnflag.setChecked(prefs.getBoolean("autounflag", false)); diff --git a/app/src/main/res/layout/fragment_options_behavior.xml b/app/src/main/res/layout/fragment_options_behavior.xml index cbf2ba2a0d..e28101869b 100644 --- a/app/src/main/res/layout/fragment_options_behavior.xml +++ b/app/src/main/res/layout/fragment_options_behavior.xml @@ -367,6 +367,28 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvOnClose" /> + + + + Collapse messages in a conversation with multiple messages on \'back\' Automatically close conversations On closing a conversation + Undo timeout Show non-obtrusive quick filter icons Show non-obtrusive quick scroll up/down icons Automatically mark messages read on moving messages @@ -1608,6 +1609,22 @@ 50000000 + + Off + 2.5 s + 5 s + 7.5 s + 10 s + + + + 0 + 2500 + 5000 + 7500 + 10000 + + Cursive Serif