Swipe from outbox to drafts

pull/184/head
M66B 4 years ago
parent bbf074e341
commit 9cb50456dc

@ -2770,7 +2770,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
break;
case R.id.ibUndo:
onActionUndo(message);
FragmentMessages.onActionUndo(message, context, owner, parentFragment.getParentFragmentManager());
break;
case R.id.ibRule:
onMenuCreateRule(message);
@ -3647,81 +3647,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
fragment.show(parentFragment.getParentFragmentManager(), "message:move");
}
private void onActionUndo(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<EntityMessage>() {
@Override
protected EntityMessage onExecute(Context context, Bundle args) {
long id = args.getLong("id");
EntityMessage message;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
message = db.message().getMessage(id);
if (message == null)
return null;
db.folder().setFolderError(message.folder, null);
if (message.identity != null)
db.identity().setIdentityError(message.identity, null);
File source = message.getFile(context);
// Insert into drafts
EntityFolder drafts = db.folder().getFolderByType(message.account, EntityFolder.DRAFTS);
message.id = null;
message.folder = drafts.id;
message.fts = false;
message.ui_snoozed = null;
message.error = null;
message.id = db.message().insertMessage(message);
File target = message.getFile(context);
source.renameTo(target);
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
for (EntityAttachment attachment : attachments)
db.attachment().setMessage(attachment.id, message.id);
EntityOperation.queue(context, message, EntityOperation.ADD);
// Delete from outbox
db.message().deleteMessage(id); // will delete operation too
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ServiceSynchronize.eval(context, "outbox/drafts");
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + id, 1);
return message;
}
@Override
protected void onExecuted(Bundle args, EntityMessage draft) {
if (draft != null)
context.startActivity(
new Intent(context, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", draft.id));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "message:move:draft");
}
private void onActionArchive(TupleMessageEx message) {
properties.move(message.id, EntityFolder.ARCHIVE);
}

@ -1725,10 +1725,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null)
return 0;
if (message.folderReadOnly)
return 0;
if (EntityFolder.OUTBOX.equals(message.folderType))
return makeMovementFlags(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
if (message.folderReadOnly)
return 0;
TupleAccountSwipes swipes = accountSwipes.get(message.account);
@ -1783,9 +1783,18 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null)
return;
TupleAccountSwipes swipes = accountSwipes.get(message.account);
TupleAccountSwipes swipes;
if (EntityFolder.OUTBOX.equals(message.folderType)) {
swipes = new TupleAccountSwipes();
swipes.swipe_right = 0L;
swipes.right_type = EntityFolder.DRAFTS;
swipes.swipe_left = 0L;
swipes.left_type = EntityFolder.DRAFTS;
} else {
swipes = accountSwipes.get(message.account);
if (swipes == null)
return;
}
if (message.accountProtocol != EntityAccount.TYPE_IMAP) {
if (swipes.swipe_right == null)
@ -1878,6 +1887,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return;
}
if (EntityFolder.OUTBOX.equals(message.folderType)) {
FragmentMessages.onActionUndo(message, getContext(), getViewLifecycleOwner(), getParentFragmentManager());
return;
}
TupleAccountSwipes swipes = accountSwipes.get(message.account);
if (swipes == null) {
adapter.notifyDataSetChanged();
@ -1935,14 +1949,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return null;
TupleMessageEx message = list.get(pos);
if (message == null ||
(message.uid == null && message.accountProtocol == EntityAccount.TYPE_IMAP))
if (message == null)
return null;
if (iProperties.getValue("expanded", message.id))
if (message.uid == null &&
!EntityFolder.OUTBOX.equals(message.folderType) &&
message.accountProtocol == EntityAccount.TYPE_IMAP)
return null;
if (EntityFolder.OUTBOX.equals(message.folderType))
if (iProperties.getValue("expanded", message.id))
return null;
return message;
@ -3101,6 +3116,81 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "messages:move");
}
static void onActionUndo(TupleMessageEx message, final Context context, final LifecycleOwner owner, final FragmentManager manager) {
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<EntityMessage>() {
@Override
protected EntityMessage onExecute(Context context, Bundle args) {
long id = args.getLong("id");
EntityMessage message;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
message = db.message().getMessage(id);
if (message == null)
return null;
db.folder().setFolderError(message.folder, null);
if (message.identity != null)
db.identity().setIdentityError(message.identity, null);
File source = message.getFile(context);
// Insert into drafts
EntityFolder drafts = db.folder().getFolderByType(message.account, EntityFolder.DRAFTS);
message.id = null;
message.folder = drafts.id;
message.fts = false;
message.ui_snoozed = null;
message.error = null;
message.id = db.message().insertMessage(message);
File target = message.getFile(context);
source.renameTo(target);
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
for (EntityAttachment attachment : attachments)
db.attachment().setMessage(attachment.id, message.id);
EntityOperation.queue(context, message, EntityOperation.ADD);
// Delete from outbox
db.message().deleteMessage(id); // will delete operation too
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ServiceSynchronize.eval(context, "outbox/drafts");
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + id, 1);
return message;
}
@Override
protected void onExecuted(Bundle args, EntityMessage draft) {
if (draft != null)
context.startActivity(
new Intent(context, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", draft.id));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(manager, ex);
}
}.execute(context, owner, args, "message:move:draft");
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean("fair:reset", reset);

Loading…
Cancel
Save