|
|
@ -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,98 +3550,127 @@ 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) {
|
|
|
|
// Show undo snackbar
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
final Snackbar snackbar = Snackbar.make(
|
|
|
|
args.putParcelableArrayList("result", result);
|
|
|
|
view,
|
|
|
|
|
|
|
|
getString(R.string.title_moving, getDisplay(result)),
|
|
|
|
new SimpleTask<ArrayList<MessageTarget>>() {
|
|
|
|
Snackbar.LENGTH_INDEFINITE);
|
|
|
|
|
|
|
|
snackbar.setAction(R.string.title_undo, new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
protected ArrayList<MessageTarget> onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
snackbar.dismiss();
|
|
|
|
ArrayList<MessageTarget> result = args.getParcelableArrayList("result");
|
|
|
|
snackbar.getView().setTag(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
args.putParcelableArrayList("result", result);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Show message again
|
|
|
|
return result;
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@Override
|
|
|
|
db.beginTransaction();
|
|
|
|
protected void onExecuted(Bundle args, final ArrayList<MessageTarget> result) {
|
|
|
|
|
|
|
|
// Show undo snackbar
|
|
|
|
|
|
|
|
final Snackbar snackbar = Snackbar.make(
|
|
|
|
|
|
|
|
view,
|
|
|
|
|
|
|
|
getString(R.string.title_moving, getDisplay(result)),
|
|
|
|
|
|
|
|
Snackbar.LENGTH_INDEFINITE);
|
|
|
|
|
|
|
|
snackbar.setAction(R.string.title_undo, new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
snackbar.dismiss();
|
|
|
|
|
|
|
|
snackbar.getView().setTag(true);
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<MessageTarget> result = args.getParcelableArrayList("result");
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
for (MessageTarget target : result) {
|
|
|
|
args.putParcelableArrayList("result", result);
|
|
|
|
Log.i("Move undo id=" + target.id);
|
|
|
|
|
|
|
|
db.message().setMessageUiBusy(target.id, null);
|
|
|
|
|
|
|
|
db.message().setMessageUiHide(target.id, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
// Show message again
|
|
|
|
} finally {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
db.endTransaction();
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
|
|
|
|
ArrayList<MessageTarget> result = args.getParcelableArrayList("result");
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
for (MessageTarget target : result) {
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Log.i("Move undo id=" + target.id);
|
|
|
|
Helper.unexpectedError(getParentFragmentManager(), ex);
|
|
|
|
db.message().setMessageUiBusy(target.id, null);
|
|
|
|
}
|
|
|
|
db.message().setMessageUiHide(target.id, false);
|
|
|
|
}.execute(FragmentMessages.this, args, "messages:undo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
snackbar.show();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Context context = getContext().getApplicationContext();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Wait
|
|
|
|
return null;
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
Log.i("Move timeout");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (snackbar.getView().getTag() != null)
|
|
|
|
@Override
|
|
|
|
return;
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Helper.unexpectedError(getParentFragmentManager(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.execute(FragmentMessages.this, args, "messages:moveundo");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
snackbar.show();
|
|
|
|
|
|
|
|
|
|
|
|
// Remove snackbar
|
|
|
|
final Context context = getContext().getApplicationContext();
|
|
|
|
if (snackbar.isShown())
|
|
|
|
|
|
|
|
snackbar.dismiss();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
// Wait
|
|
|
|
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
Log.i("Move timeout");
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (MessageTarget target : result) {
|
|
|
|
if (snackbar.getView().getTag() != null)
|
|
|
|
EntityMessage message = db.message().getMessage(target.id);
|
|
|
|
return;
|
|
|
|
if (message == null || !message.ui_hide)
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Move id=" + id + " target=" + target.folder.name);
|
|
|
|
// Remove snackbar
|
|
|
|
db.message().setMessageUiBusy(target.id, null);
|
|
|
|
if (snackbar.isShown())
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id);
|
|
|
|
snackbar.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
@Override
|
|
|
|
Log.e(ex);
|
|
|
|
public void run() {
|
|
|
|
} finally {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
db.endTransaction();
|
|
|
|
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=" + id + " target=" + target.folder.name);
|
|
|
|
|
|
|
|
db.message().setMessageUiBusy(target.id, null);
|
|
|
|
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, "messages:movetimeout");
|
|
|
|
|
|
|
|
thread.setPriority(THREAD_PRIORITY_BACKGROUND);
|
|
|
|
|
|
|
|
thread.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "messages:timeout");
|
|
|
|
}, UNDO_TIMEOUT);
|
|
|
|
thread.setPriority(THREAD_PRIORITY_BACKGROUND);
|
|
|
|
}
|
|
|
|
thread.start();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Helper.unexpectedError(getParentFragmentManager(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, UNDO_TIMEOUT);
|
|
|
|
}.execute(this, args, "messages:movehide");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getDisplay(ArrayList<MessageTarget> result) {
|
|
|
|
private String getDisplay(ArrayList<MessageTarget> result) {
|
|
|
|