From 504c0897e95da9441b55d7772530afa8cd378ab4 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 6 Mar 2020 20:05:42 +0100 Subject: [PATCH] Flow message actions --- .../eu/faircode/email/AdapterMessage.java | 214 ++++++------------ .../faircode/email/FragmentOptionsMisc.java | 2 +- .../res/layout/include_message_navigation.xml | 137 +++++------ app/src/main/res/values/strings.xml | 1 - 4 files changed, 129 insertions(+), 225 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 2b6ca8521e..18098a63f0 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -387,10 +387,8 @@ public class AdapterMessage extends RecyclerView.Adapter= 9 * 39 - 3); - vSeparator.setVisibility(View.VISIBLE); ibFull.setEnabled(false); ibFull.setVisibility(View.VISIBLE); @@ -1328,17 +1316,80 @@ public class AdapterMessage extends RecyclerView.Adapter>() { + @Override + protected void onPreExecute(Bundle args) { + ibUnsubscribe.setVisibility(View.GONE); + ibAnswer.setVisibility(View.GONE); + ibMove.setVisibility(View.GONE); + ibArchive.setVisibility(View.GONE); + ibTrash.setVisibility(View.GONE); + ibJunk.setVisibility(View.GONE); + } + + @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; - if (normal) - onActionRemove(message, true); + boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); + boolean inTrash = EntityFolder.TRASH.equals(message.folderType); + boolean inJunk = EntityFolder.JUNK.equals(message.folderType); + boolean outbox = EntityFolder.OUTBOX.equals(message.folderType); + + boolean move = !(message.folderReadOnly || message.uid == null); + boolean archive = (move && (hasArchive && !inArchive)); + boolean trash = (move || outbox || debug); + boolean junk = (move && (hasJunk && !inJunk)); + boolean unjunk = (move && inJunk); + + final boolean delete = (inTrash || !hasTrash || outbox || message.uid == null); + + ibTrash.setTag(delete); + ibJunk.setImageResource(unjunk ? R.drawable.baseline_inbox_24 : R.drawable.baseline_flag_24); + String title = context.getString(unjunk ? R.string.title_no_junk : R.string.title_spam); + ibJunk.setContentDescription(title); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + ibJunk.setTooltipText(title); + + ibUnsubscribe.setVisibility(message.unsubscribe == null ? View.GONE : View.VISIBLE); + ibAnswer.setVisibility(outbox ? View.GONE : View.VISIBLE); + ibMove.setVisibility(move ? View.VISIBLE : View.GONE); + ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE); + ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE); + ibJunk.setVisibility(junk || unjunk ? View.VISIBLE : View.GONE); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.setLog(false).execute(context, owner, sargs, "message:more"); ibMore.setVisibility(EntityFolder.OUTBOX.equals(message.folderType) ? View.GONE : View.VISIBLE); tvSignedData.setVisibility(View.GONE); @@ -2330,6 +2381,7 @@ 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); - boolean outbox = EntityFolder.OUTBOX.equals(message.folderType); - - boolean move = !(message.folderReadOnly || message.uid == null); - boolean archive = (move && (hasArchive && !inArchive)); - boolean trash = (move || outbox || debug); - boolean junk = (move && (hasJunk && !inJunk)); - boolean unjunk = (move && inJunk); - - final boolean delete = (inTrash || !hasTrash || outbox || message.uid == null); - - if (normal) { - ibTrash.setTag(delete); - ibJunk.setImageResource(unjunk ? R.drawable.baseline_inbox_24 : R.drawable.baseline_flag_24); - String title = context.getString(unjunk ? R.string.title_no_junk : R.string.title_spam); - ibJunk.setContentDescription(title); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - ibJunk.setTooltipText(title); - - ibUnsubscribe.setVisibility(message.unsubscribe == null ? View.GONE : View.VISIBLE); - ibAnswer.setVisibility(outbox ? View.GONE : View.VISIBLE); - ibMove.setVisibility(move ? View.VISIBLE : View.GONE); - ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE); - ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE); - ibJunk.setVisibility(junk || unjunk ? View.VISIBLE : View.GONE); - } else { - if (!hasArchive && !hasJunk) { - if (delete) - onActionDelete(message); - else - properties.move(message.id, EntityFolder.TRASH); - return; - } - - PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibMore); - popupMenu.inflate(R.menu.popup_message_remove); - popupMenu.getMenu().findItem(R.id.menu_archive).setEnabled(archive); - popupMenu.getMenu().findItem(R.id.menu_trash).setEnabled(trash); - popupMenu.getMenu().findItem(R.id.menu_junk).setEnabled(junk); - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem target) { - switch (target.getItemId()) { - case R.id.menu_archive: - onActionArchive(message); - return true; - case R.id.menu_trash: - onActionTrash(message, delete); - 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:more"); - } - private void onActionArchive(TupleMessageEx message) { properties.move(message.id, EntityFolder.ARCHIVE); } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index a2493ac179..f5064f8aec 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -81,7 +81,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc }; private final static String[] RESET_QUESTIONS = new String[]{ - "welcome", "crash_reports_asked", "review_asked", "review_later", "cross_hint", "answer_hint", "why", + "welcome", "crash_reports_asked", "review_asked", "review_later", "why", "reply_hint", "html_always_images", "print_html_confirmed", "move_1_confirmed", "move_n_confirmed", "identities_asked", "cc_bcc", "inline_image_hint", "compose_reference", "send_dialog", "setup_advanced" diff --git a/app/src/main/res/layout/include_message_navigation.xml b/app/src/main/res/layout/include_message_navigation.xml index 8df8be8150..2b64f0bcff 100644 --- a/app/src/main/res/layout/include_message_navigation.xml +++ b/app/src/main/res/layout/include_message_navigation.xml @@ -1,6 +1,7 @@ @@ -22,6 +23,19 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/vSeparator" /> + + - - + app:srcCompat="@drawable/baseline_more_vert_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_flag_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_delete_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_archive_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_folder_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_reply_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_unsubscribe_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_undo_24" + tools:ignore="MissingConstraints" /> + app:srcCompat="@drawable/baseline_gesture_24" /> + app:srcCompat="@drawable/baseline_lock_open_24" /> + android:tooltipText="@string/title_legend_show_images" + app:layout_constraintEnd_toStartOf="@+id/ibFull" + app:layout_constraintTop_toBottomOf="@id/vSeparator" + app:srcCompat="@drawable/baseline_image_24" /> + app:layout_constraintTop_toBottomOf="@id/vSeparator" + app:srcCompat="@drawable/baseline_fullscreen_24" /> - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd4ce7b6ca..1434504541 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -744,7 +744,6 @@ Help improve FairEmail Send error reports? Error reporting will help improve FairEmail - Tap the cross icon to archive, delete or report a message as spam and to remove this notice Please review FairEmail