From 1f83f4a9c164766c62fc5a53396484b7e55aebab Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 25 Jan 2019 08:26:18 +0000 Subject: [PATCH] Warn messages not identical when moving across accounts --- .../eu/faircode/email/FragmentMessages.java | 45 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 42498ac68a..26b1cf5f81 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -548,7 +548,7 @@ public class FragmentMessages extends FragmentBase { if (target != null) { EntityAccount account = db.account().getAccount(target.account); - result.add(new MessageTarget(id, account, target)); + result.add(new MessageTarget(message, account, target)); } db.setTransactionSuccessful(); @@ -678,7 +678,7 @@ public class FragmentMessages extends FragmentBase { List messages = db.message().getMessageByThread( message.account, message.thread, threading && thread ? null : id, message.folder); for (EntityMessage threaded : messages) { - result.add(new MessageTarget(threaded.id, account, target)); + result.add(new MessageTarget(threaded, account, target)); db.message().setMessageUiHide(threaded.id, true); // Prevent new message notification on undo db.message().setMessageUiIgnored(threaded.id, true); @@ -762,7 +762,7 @@ public class FragmentMessages extends FragmentBase { (!EntityFolder.SENT.equals(folder.type) || EntityFolder.TRASH.equals(target.type)) && !EntityFolder.TRASH.equals(folder.type) && !EntityFolder.JUNK.equals(folder.type)) - result.add(new MessageTarget(threaded.id, account, target)); + result.add(new MessageTarget(threaded, account, target)); } } @@ -1192,7 +1192,7 @@ public class FragmentMessages extends FragmentBase { for (EntityMessage threaded : messages) { EntityFolder target = db.folder().getFolderByType(message.account, type); EntityAccount account = db.account().getAccount(target.account); - result.add(new MessageTarget(threaded.id, account, target)); + result.add(new MessageTarget(threaded, account, target)); } } } @@ -1245,7 +1245,7 @@ public class FragmentMessages extends FragmentBase { List messages = db.message().getMessageByThread( message.account, message.thread, threading ? null : id, message.folder); for (EntityMessage threaded : messages) - result.add(new MessageTarget(threaded.id, account, target)); + result.add(new MessageTarget(threaded, account, target)); } } } @@ -2041,7 +2041,7 @@ public class FragmentMessages extends FragmentBase { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); if (prefs.getBoolean("automove", false)) { - moveAskConfirmed(result); + moveAskAcross(result); return; } @@ -2059,13 +2059,36 @@ public class FragmentMessages extends FragmentBase { public void onClick(DialogInterface dialog, int which) { if (cbNotAgain.isChecked()) prefs.edit().putBoolean("automove", true).apply(); - moveAskConfirmed(result); + moveAskAcross(result); } }) .setNegativeButton(android.R.string.cancel, null) .show(); } + private void moveAskAcross(final ArrayList result) { + boolean across = false; + for (MessageTarget target : result) + if (target.across) { + across = true; + break; + } + + if (across) + new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) + .setMessage(R.string.title_accross_remark) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + moveAskConfirmed(result); + } + }) + .setNegativeButton(android.R.string.cancel, null) + .show(); + else + moveAskConfirmed(result); + } + private void moveAskConfirmed(ArrayList result) { Bundle args = new Bundle(); args.putParcelableArrayList("result", result); @@ -2243,17 +2266,20 @@ public class FragmentMessages extends FragmentBase { private static class MessageTarget implements Parcelable { long id; + boolean across; EntityAccount account; EntityFolder folder; - MessageTarget(long id, EntityAccount account, EntityFolder folder) { - this.id = id; + MessageTarget(EntityMessage message, EntityAccount account, EntityFolder folder) { + this.id = message.id; + this.across = !folder.account.equals(message.account); this.account = account; this.folder = folder; } protected MessageTarget(Parcel in) { id = in.readLong(); + across = (in.readInt() != 0); account = (EntityAccount) in.readSerializable(); folder = (EntityFolder) in.readSerializable(); } @@ -2261,6 +2287,7 @@ public class FragmentMessages extends FragmentBase { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeLong(id); + dest.writeInt(across ? 1 : 0); dest.writeSerializable(account); dest.writeSerializable(folder); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 06f54d1ac6..0a9a6d67a2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -307,6 +307,7 @@ Contact picker not available No internet connection Moving across accounts requires all message content to be downloaded + Messages moved across accounts will not be identical after moving Raw message saved Attachment saved Attachments saved