Added batch move undo

pull/167/head
M66B 5 years ago
parent 1b7aed0b02
commit 46dd99e82e

@ -1668,7 +1668,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
args.putLong("id", message.id); args.putLong("id", message.id);
args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD); args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD);
args.putLong("target", target); args.putLong("target", target);
args.putLong("busy", new Date().getTime() + UNDO_TIMEOUT * 2);
new SimpleTask<ArrayList<MessageTarget>>() { new SimpleTask<ArrayList<MessageTarget>>() {
@Override @Override
@ -1676,7 +1675,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
long id = args.getLong("id"); long id = args.getLong("id");
boolean thread = args.getBoolean("thread"); boolean thread = args.getBoolean("thread");
long tid = args.getLong("target"); long tid = args.getLong("target");
long busy = args.getLong("busy");
ArrayList<MessageTarget> result = new ArrayList<>(); ArrayList<MessageTarget> result = new ArrayList<>();
@ -1696,13 +1694,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
EntityAccount account = db.account().getAccount(target.account); EntityAccount account = db.account().getAccount(target.account);
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading && thread ? null : id, message.folder); message.account, message.thread, threading && thread ? null : id, message.folder);
for (EntityMessage threaded : messages) { for (EntityMessage threaded : messages)
result.add(new MessageTarget(threaded, account, target)); result.add(new MessageTarget(threaded, account, target));
db.message().setMessageUiBusy(threaded.id, busy);
db.message().setMessageUiHide(threaded.id, true);
// Prevent new message notification on undo
db.message().setMessageUiIgnored(threaded.id, true);
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -3497,7 +3490,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (prefs.getBoolean("automove", false)) { if (prefs.getBoolean("automove", false)) {
moveAskConfirmed(result); moveUndo(result);
return; return;
} }
@ -3557,7 +3550,29 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "messages:move"); }.execute(this, args, "messages:move");
} }
private void moveUndo(final ArrayList<MessageTarget> result) { private void moveUndo(ArrayList<MessageTarget> result) {
Bundle args = new Bundle();
args.putParcelableArrayList("result", result);
new SimpleTask<ArrayList<MessageTarget>>() {
@Override
protected ArrayList<MessageTarget> onExecute(Context context, Bundle args) throws Throwable {
ArrayList<MessageTarget> result = args.getParcelableArrayList("result");
DB db = DB.getInstance(context);
long busy = new Date().getTime() + UNDO_TIMEOUT * 2;
for (MessageTarget target : result) {
db.message().setMessageUiBusy(target.id, busy);
db.message().setMessageUiHide(target.id, true);
// Prevent new message notification on undo
db.message().setMessageUiIgnored(target.id, true);
}
return result;
}
@Override
protected void onExecuted(Bundle args, final ArrayList<MessageTarget> result) {
// Show undo snackbar // Show undo snackbar
final Snackbar snackbar = Snackbar.make( final Snackbar snackbar = Snackbar.make(
view, view,
@ -3576,12 +3591,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context); ArrayList<MessageTarget> result = args.getParcelableArrayList("result");
DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
ArrayList<MessageTarget> result = args.getParcelableArrayList("result");
for (MessageTarget target : result) { for (MessageTarget target : result) {
Log.i("Move undo id=" + target.id); Log.i("Move undo id=" + target.id);
db.message().setMessageUiBusy(target.id, null); db.message().setMessageUiBusy(target.id, null);
@ -3600,7 +3615,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getParentFragmentManager(), ex); Helper.unexpectedError(getParentFragmentManager(), ex);
} }
}.execute(FragmentMessages.this, args, "messages:undo"); }.execute(FragmentMessages.this, args, "messages:moveundo");
} }
}); });
snackbar.show(); snackbar.show();
@ -3644,13 +3659,20 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
} }
}, "messages:timeout"); }, "messages:movetimeout");
thread.setPriority(THREAD_PRIORITY_BACKGROUND); thread.setPriority(THREAD_PRIORITY_BACKGROUND);
thread.start(); thread.start();
} }
}, UNDO_TIMEOUT); }, UNDO_TIMEOUT);
} }
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "messages:movehide");
}
private String getDisplay(ArrayList<MessageTarget> result) { private String getDisplay(ArrayList<MessageTarget> result) {
boolean across = false; boolean across = false;
for (MessageTarget target : result) for (MessageTarget target : result)

Loading…
Cancel
Save