Added undo timeout setting

This commit is contained in:
M66B
2020-07-18 11:21:24 +02:00
parent 78ab6f5908
commit 91cd5fa20c
4 changed files with 106 additions and 36 deletions

View File

@@ -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<MessageTarget> 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

View File

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