1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-28 02:37:16 +00:00

Move message with undo

This commit is contained in:
M66B 2018-11-20 09:44:13 +01:00
parent a61ab0ea1c
commit 60656a4920
2 changed files with 63 additions and 87 deletions

View file

@ -1274,40 +1274,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
})
.setNegativeButton(android.R.string.cancel, null)
.show();
} else {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
new SimpleTask<Void>() {
@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<TupleMessageEx, AdapterMess
public boolean onMenuItemClick(final MenuItem target) {
args.putLong("target", target.getItemId());
new SimpleTask<Void>() {
new SimpleTask<String>() {
@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<TupleMessageEx, AdapterMess
}
private void onArchive(ActionData data) {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
new SimpleTask<Void>() {
@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<TupleMessageEx, AdapterMess
boolean showHeaders(long id);
boolean showImages(long id);
void move(long id, String target, boolean type);
}
}

View file

@ -274,7 +274,57 @@ public class FragmentMessages extends FragmentEx {
public boolean showImages(long id) {
return images.contains(id);
}
@Override
public void move(long id, String name, boolean type) {
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", name);
args.putBoolean("type", type);
new SimpleTask<MessageTarget>() {
@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) {