diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index d19d0683e1..5210d66a17 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -1274,40 +1274,8 @@ public class AdapterMessage extends PagedListAdapter() { - @Override - protected Void onLoad(Context context, Bundle args) { - long id = args.getLong("id"); - DB db = DB.getInstance(context); - try { - db.beginTransaction(); - - db.message().setMessageUiHide(id, true); - - EntityMessage message = db.message().getMessage(id); - EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH); - EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - - EntityOperation.process(context); - - return null; - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(context, ex); - } - }.load(context, owner, args); - } + } else + properties.move(data.message.id, EntityFolder.TRASH, true); } private void onMove(ActionData data) { @@ -1348,29 +1316,17 @@ public class AdapterMessage extends PagedListAdapter() { + new SimpleTask() { @Override - protected Void onLoad(Context context, Bundle args) { - long id = args.getLong("id"); + protected String onLoad(Context context, Bundle args) { long target = args.getLong("target"); + return DB.getInstance(context).folder().getFolder(target).name; + } - DB db = DB.getInstance(context); - try { - db.beginTransaction(); - - db.message().setMessageUiHide(id, true); - - EntityMessage message = db.message().getMessage(id); - EntityOperation.queue(db, message, EntityOperation.MOVE, target); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - - EntityOperation.process(context); - - return null; + @Override + protected void onLoaded(Bundle args, String folderName) { + long id = args.getLong("id"); + properties.move(id, folderName, false); } @Override @@ -1389,39 +1345,7 @@ public class AdapterMessage extends PagedListAdapter() { - @Override - protected Void onLoad(Context context, Bundle args) { - long id = args.getLong("id"); - - DB db = DB.getInstance(context); - try { - db.beginTransaction(); - - db.message().setMessageUiHide(id, true); - - EntityMessage message = db.message().getMessage(id); - EntityFolder archive = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE); - EntityOperation.queue(db, message, EntityOperation.MOVE, archive.id); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - - EntityOperation.process(context); - - return null; - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(context, ex); - } - }.load(context, owner, args); + properties.move(data.message.id, EntityFolder.ARCHIVE, true); } private void onReply(ActionData data) { @@ -1516,5 +1440,7 @@ public class AdapterMessage extends PagedListAdapter() { + @Override + protected MessageTarget onLoad(Context context, Bundle args) { + long id = args.getLong("id"); + String name = args.getString("name"); + boolean type = args.getBoolean("type"); + + MessageTarget result = new MessageTarget(); + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessage(id); + if (type) + result.target = db.folder().getFolderByType(message.account, name); + else + result.target = db.folder().getFolderByName(message.account, name); + result.ids.add(message.id); + + db.message().setMessageUiHide(id, true); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + return result; + } + + @Override + protected void onLoaded(Bundle args, MessageTarget result) { + moveUndo(result); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getContext(), ex); + } + }.load(FragmentMessages.this, args); + } }); + rvMessage.setAdapter(adapter); if (viewType == AdapterMessage.ViewType.FOLDER) {