From 5b9a2446b5915680f3cb3d56bd9f13e97f39724c Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 1 Mar 2020 20:49:46 +0100 Subject: [PATCH] Added remove button --- .../eu/faircode/email/AdapterMessage.java | 179 ++++++++++-------- .../drawable/baseline_remove_circle_24.xml | 10 + .../res/layout/include_message_navigation.xml | 35 ++-- app/src/main/res/menu/popup_message_move.xml | 14 ++ 4 files changed, 146 insertions(+), 92 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_remove_circle_24.xml create mode 100644 app/src/main/res/menu/popup_message_move.xml diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 4dc27b4239..61aa0e0908 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -379,10 +379,10 @@ public class AdapterMessage extends RecyclerView.Adapter>() { - @Override - protected List onExecute(Context context, Bundle args) { - long account = args.getLong("account"); - return DB.getInstance(context).folder().getSystemFolders(account); - } - - @Override - protected void onExecuted(Bundle args, List folders) { - long id = args.getLong("id"); - TupleMessageEx amessage = getMessage(); - if (amessage == null || !amessage.id.equals(id)) - return; - - boolean hasArchive = false; - boolean hasTrash = false; - hasJunk = false; - if (folders != null) - for (EntityFolder folder : folders) { - if (EntityFolder.ARCHIVE.equals(folder.type)) - hasArchive = true; - else if (EntityFolder.TRASH.equals(folder.type)) - hasTrash = true; - else if (EntityFolder.JUNK.equals(folder.type)) - hasJunk = true; - } - - boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType); - boolean inTrash = EntityFolder.TRASH.equals(message.folderType); - - delete = (inTrash || !hasTrash || inOutbox); - - ibJunk.setEnabled(hasJunk); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); - } - }.setLog(false).execute(context, owner, sargs, "message:actions"); - // Message text tvNoInternetBody.setVisibility(suitable || message.content ? View.GONE : View.VISIBLE); @@ -1856,10 +1806,6 @@ public class AdapterMessage extends RecyclerView.Adapter>() { + @Override + protected List onExecute(Context context, Bundle args) { + long account = args.getLong("account"); + return DB.getInstance(context).folder().getSystemFolders(account); + } + + @Override + protected void onExecuted(Bundle args, List folders) { + long id = args.getLong("id"); + TupleMessageEx amessage = getMessage(); + if (amessage == null || !amessage.id.equals(id)) + return; + + boolean hasArchive = false; + boolean hasTrash = false; + boolean hasJunk = false; + if (folders != null) + for (EntityFolder folder : folders) + if (EntityFolder.ARCHIVE.equals(folder.type)) + hasArchive = true; + else if (EntityFolder.TRASH.equals(folder.type)) + hasTrash = true; + else if (EntityFolder.JUNK.equals(folder.type)) + hasJunk = true; + + boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); + boolean inTrash = EntityFolder.TRASH.equals(message.folderType); + boolean inJunk = EntityFolder.JUNK.equals(message.folderType); + final boolean delete = (inTrash || !hasTrash); + + PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibMore); + popupMenu.inflate(R.menu.popup_message_move); + popupMenu.getMenu().findItem(R.id.menu_archive).setEnabled(message.uid != null && (hasArchive && !inArchive)); + popupMenu.getMenu().findItem(R.id.menu_trash).setEnabled(message.uid != null); + popupMenu.getMenu().findItem(R.id.menu_junk).setEnabled(message.uid != null && (hasJunk && !inJunk)); + + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem target) { + switch (target.getItemId()) { + case R.id.menu_archive: + properties.move(message.id, EntityFolder.ARCHIVE); + return true; + case R.id.menu_trash: + if (delete) + onActionDelete(message); + else + properties.move(message.id, EntityFolder.TRASH); + return true; + case R.id.menu_junk: + onActionJunk(message); + return true; + default: + return false; + } + } + }); + popupMenu.show(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.setLog(false).execute(context, owner, sargs, "message:actions"); + } + + private void onActionDelete(TupleMessageEx message) { + Bundle aargs = new Bundle(); + aargs.putString("question", context.getString(R.string.title_ask_delete)); + aargs.putLong("id", message.id); + + FragmentDialogAsk ask = new FragmentDialogAsk(); + ask.setArguments(aargs); + ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_DELETE); + ask.show(parentFragment.getParentFragmentManager(), "message:delete"); + } + + private void onActionJunk(TupleMessageEx message) { + Bundle aargs = new Bundle(); + aargs.putLong("id", message.id); + aargs.putString("from", MessageHelper.formatAddresses(message.from)); + + FragmentDialogJunk ask = new FragmentDialogJunk(); + ask.setArguments(aargs); + ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_JUNK); + ask.show(parentFragment.getParentFragmentManager(), "message:junk"); + } + private void onActionMore(TupleMessageEx message) { boolean show_headers = properties.getValue("headers", message.id); boolean full = properties.getValue("full", message.id); diff --git a/app/src/main/res/drawable/baseline_remove_circle_24.xml b/app/src/main/res/drawable/baseline_remove_circle_24.xml new file mode 100644 index 0000000000..2c986ca0bf --- /dev/null +++ b/app/src/main/res/drawable/baseline_remove_circle_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/include_message_navigation.xml b/app/src/main/res/layout/include_message_navigation.xml index 491110baf8..699c50731d 100644 --- a/app/src/main/res/layout/include_message_navigation.xml +++ b/app/src/main/res/layout/include_message_navigation.xml @@ -17,7 +17,6 @@ android:id="@+id/ibMore" android:layout_width="36dp" android:layout_height="36dp" - android:layout_marginEnd="12dp" android:background="?android:attr/selectableItemBackgroundBorderless" android:contentDescription="@string/title_more" android:foregroundTint="?android:attr/textColorSecondary" @@ -28,6 +27,21 @@ app:layout_constraintTop_toBottomOf="@id/vSeparator" app:srcCompat="@drawable/baseline_more_vert_24" /> + + - - + app:srcCompat="@drawable/baseline_lock_open_24" /> + + + + + + +