From 9d53085249c0068831473890573b748793d16038 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 23 Oct 2018 17:44:36 +0000 Subject: [PATCH] Added move sent menu --- .../java/eu/faircode/email/DaoMessage.java | 5 ++ .../eu/faircode/email/FragmentMessages.java | 51 +++++++++++++++++++ app/src/main/res/menu/menu_messages.xml | 5 ++ app/src/main/res/values/strings.xml | 2 + 4 files changed, 63 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 52eb3e60..f194ce13 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -152,6 +152,11 @@ public interface DaoMessage { " AND ui_found = :found") List getMessageByMsgId(long account, String msgid, String reference, boolean found); + @Query("SELECT * FROM message" + + " WHERE folder = :folder" + + " AND ui_seen") + List getMessageSeen(long folder); + @Query("SELECT message.*" + ", account.name AS accountName, account.color AS accountColor" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" + diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index a1cf5c5b..3efb712e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -86,6 +86,7 @@ public class FragmentMessages extends FragmentEx { private String search = null; private long primary = -1; + private boolean outbox = false; private boolean connected = false; private AdapterMessage adapter; private List archives = new ArrayList<>(); @@ -577,6 +578,9 @@ public class FragmentMessages extends FragmentEx { setSubtitle(getString(R.string.title_folder_unseen, name, folder.unseen)); else setSubtitle(name); + + outbox = EntityFolder.OUTBOX.equals(folder.type); + getActivity().invalidateOptionsMenu(); } } }); @@ -716,6 +720,7 @@ public class FragmentMessages extends FragmentEx { menu.findItem(R.id.menu_sort_on).setVisible(TextUtils.isEmpty(search)); menu.findItem(R.id.menu_folders).setVisible(primary >= 0); menu.findItem(R.id.menu_folders).setIcon(connected ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24); + menu.findItem(R.id.menu_move_sent).setVisible(outbox); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); String sort = prefs.getString("sort", "time"); @@ -758,6 +763,10 @@ public class FragmentMessages extends FragmentEx { loadMessages(); return true; + case R.id.menu_move_sent: + onMenuMoveSent(); + return true; + default: return super.onOptionsItemSelected(item); } @@ -777,6 +786,48 @@ public class FragmentMessages extends FragmentEx { fragmentTransaction.commit(); } + private void onMenuMoveSent() { + Bundle args = new Bundle(); + args.putLong("folder", folder); + + new SimpleTask() { + @Override + protected Void onLoad(Context context, Bundle args) throws Throwable { + long outbox = args.getLong("folder"); + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + for (EntityMessage message : db.message().getMessageSeen(outbox)) { + EntityIdentity identity = db.identity().getIdentity(message.identity); + EntityFolder sent = db.folder().getFolderByType(identity.account, EntityFolder.SENT); + if (sent != null) { + message.folder = sent.id; + message.uid = null; + db.message().updateMessage(message); + Log.i(Helper.TAG, "Appending sent msgid=" + message.msgid); + EntityOperation.queue(db, message, EntityOperation.ADD); // Could already exist + } + } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + EntityOperation.process(context); + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getContext(), ex); + } + }.load(this, args); + } + private void loadMessages() { final DB db = DB.getInstance(getContext()); diff --git a/app/src/main/res/menu/menu_messages.xml b/app/src/main/res/menu/menu_messages.xml index bb42025d..96ac6dd9 100644 --- a/app/src/main/res/menu/menu_messages.xml +++ b/app/src/main/res/menu/menu_messages.xml @@ -34,4 +34,9 @@ android:icon="@drawable/baseline_folder_open_24" android:title="@string/title_folder_primary" app:showAsAction="ifRoom" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b7d7d680..0415df43 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -235,6 +235,8 @@ Unread Starred + Move to sent + Previous Next