Added undo timeout setting

pull/184/head
M66B 5 years ago
parent 78ab6f5908
commit 91cd5fa20c

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

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

@ -367,6 +367,28 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOnClose" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvUndoTimeout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_undo"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spOnClose" />
<Spinner
android:id="@+id/spUndoTimeout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:entries="@array/undoNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUndoTimeout" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoRead"
android:layout_width="0dp"
@ -375,7 +397,7 @@
android:text="@string/title_advanced_autoread"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spOnClose"
app:layout_constraintTop_toBottomOf="@id/spUndoTimeout"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -390,6 +390,7 @@
<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_onclose">On closing a conversation</string>
<string name="title_advanced_undo">Undo timeout</string>
<string name="title_advanced_quick_filter">Show non-obtrusive quick filter icons</string>
<string name="title_advanced_quick_scroll">Show non-obtrusive quick scroll up/down icons</string>
<string name="title_advanced_autoread">Automatically mark messages read on moving messages</string>
@ -1608,6 +1609,22 @@
<item>50000000</item>
</integer-array>
<string-array name="undoNames">
<item>Off</item>
<item>2.5 s</item>
<item>5 s</item>
<item>7.5 s</item>
<item>10 s</item>
</string-array>
<integer-array name="undoValues" translatable="false">
<item>0</item>
<item>2500</item>
<item>5000</item>
<item>7500</item>
<item>10000</item>
</integer-array>
<string-array name="fontNameNames">
<item>Cursive</item>
<item>Serif</item>

Loading…
Cancel
Save