From a2f7f3996bcd6da11378856b1bfc2d69d1c89066 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 11 Dec 2022 21:12:44 +0100 Subject: [PATCH] Added option to swap archive/delete button --- .../eu/faircode/email/FragmentMessages.java | 47 ++++++++++++------- .../eu/faircode/email/FragmentOptions.java | 2 +- .../email/FragmentOptionsDisplay.java | 14 +++++- .../res/layout/fragment_options_display.xml | 14 +++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 57 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 7d11eed0cc..d3bf4775fe 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -350,6 +350,8 @@ public class FragmentMessages extends FragmentBase private boolean swipenav; private boolean seekbar; private boolean actionbar; + private int actionbar_delete_id; + private int actionbar_archive_id; private boolean actionbar_color; private boolean autoexpand; private boolean autoclose; @@ -491,6 +493,9 @@ public class FragmentMessages extends FragmentBase args.getBoolean("force_threading")); seekbar = prefs.getBoolean("seekbar", false); actionbar = prefs.getBoolean("actionbar", true); + boolean actionbar_swap = prefs.getBoolean("actionbar_swap", false); + actionbar_delete_id = (actionbar_swap ? R.id.action_archive : R.id.action_delete); + actionbar_archive_id = (actionbar_swap ? R.id.action_delete : R.id.action_archive); actionbar_color = prefs.getBoolean("actionbar_color", false); autoexpand = prefs.getBoolean("autoexpand", true); autoclose = prefs.getBoolean("autoclose", true); @@ -1274,7 +1279,7 @@ public class FragmentMessages extends FragmentBase public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { ActionData data = (ActionData) bottom_navigation.getTag(); int itemId = menuItem.getItemId(); - if (itemId == R.id.action_delete) { + if (itemId == actionbar_delete_id) { if (data.delete) onActionDelete(); else @@ -1283,7 +1288,7 @@ public class FragmentMessages extends FragmentBase } else if (itemId == R.id.action_snooze) { onActionSnooze(); return true; - } else if (itemId == R.id.action_archive) { + } else if (itemId == actionbar_archive_id) { onActionMove(EntityFolder.ARCHIVE); return true; } else if (itemId == R.id.action_prev) { @@ -6884,20 +6889,26 @@ public class FragmentMessages extends FragmentBase bottom_navigation.setTag(data); - bottom_navigation.getMenu().findItem(R.id.action_delete).setIcon( - data.forever ? R.drawable.twotone_delete_forever_24 : R.drawable.twotone_delete_24); - bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(data.trashable); - bottom_navigation.getMenu().findItem(R.id.action_snooze).setVisible(data.snoozable); - bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(data.archivable); + bottom_navigation.getMenu().findItem(actionbar_delete_id) + .setIcon(data.forever ? R.drawable.twotone_delete_forever_24 : R.drawable.twotone_delete_24) + .setTitle(data.forever ? R.string.title_delete_permanently : R.string.title_trash) + .setVisible(data.trashable); + bottom_navigation.getMenu().findItem(R.id.action_snooze) + .setVisible(data.snoozable); + bottom_navigation.getMenu().findItem(actionbar_archive_id) + .setIcon(R.drawable.twotone_archive_24) + .setTitle(R.string.title_archive) + .setVisible(data.archivable); bottom_navigation.setVisibility(View.VISIBLE); - bottom_navigation.findViewById(R.id.action_delete).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - onActionDelete(); - return true; - } - }); + bottom_navigation.findViewById(actionbar_delete_id) + .setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + onActionDelete(); + return true; + } + }); } @Override @@ -7687,10 +7698,10 @@ public class FragmentMessages extends FragmentBase !bottom_navigation.isEnabled() || bottom_navigation.getVisibility() != View.VISIBLE) return false; - MenuItem archive = bottom_navigation.getMenu().findItem(R.id.action_archive); + MenuItem archive = bottom_navigation.getMenu().findItem(actionbar_archive_id); if (archive == null || !archive.isVisible() || !archive.isEnabled()) return false; - bottom_navigation.getMenu().performIdentifierAction(R.id.action_archive, 0); + bottom_navigation.getMenu().performIdentifierAction(actionbar_archive_id, 0); return true; } @@ -7699,10 +7710,10 @@ public class FragmentMessages extends FragmentBase !bottom_navigation.isEnabled() || bottom_navigation.getVisibility() != View.VISIBLE) return false; - MenuItem delete = bottom_navigation.getMenu().findItem(R.id.action_delete); + MenuItem delete = bottom_navigation.getMenu().findItem(actionbar_delete_id); if (delete == null || !delete.isVisible() || !delete.isEnabled()) return false; - bottom_navigation.getMenu().performIdentifierAction(R.id.action_delete, 0); + bottom_navigation.getMenu().performIdentifierAction(actionbar_delete_id, 0); return true; } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 1fa5b133cd..09534047b5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -149,7 +149,7 @@ public class FragmentOptions extends FragmentBase { "list_count", "bundled_fonts", "parse_classes", "background_color", "text_color", "text_size", "text_font", "text_align", "text_titles", "text_separators", "collapse_quotes", "image_placeholders", "inline_images", - "seekbar", "actionbar", "actionbar_color", "group_category", + "seekbar", "actionbar", "actionbar_swap", "actionbar_color", "group_category", "autoscroll", "swipenav", "reversed", "swipe_close", "swipe_move", "autoexpand", "autoclose", "onclose", "swipe_reply", "language_detection", diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index 0432db0127..7cd0bef858 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -98,6 +98,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private SwitchCompat swIndentation; private SwitchCompat swSeekbar; private SwitchCompat swActionbar; + private SwitchCompat swActionbarSwap; private SwitchCompat swActionbarColor; private SwitchCompat swHighlightUnread; @@ -195,7 +196,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer "cards", "beige", "tabular_card_bg", "shadow_unread", "shadow_highlight", "dividers", "portrait2", "portrait2c", "landscape", "close_pane", "column_width", "nav_options", "nav_categories", "nav_count", "nav_unseen_drafts", "nav_count_pinned", "navbar_colorize", - "threading", "threading_unread", "indentation", "seekbar", "actionbar", "actionbar_color", + "threading", "threading_unread", "indentation", "seekbar", "actionbar", "actionbar_swap", "actionbar_color", "highlight_unread", "highlight_color", "color_stripe", "color_stripe_wide", "avatars", "bimi", "gravatars", "libravatars", "favicons", "favicons_partial", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold", @@ -259,6 +260,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer swIndentation = view.findViewById(R.id.swIndentation); swSeekbar = view.findViewById(R.id.swSeekbar); swActionbar = view.findViewById(R.id.swActionbar); + swActionbarSwap = view.findViewById(R.id.swActionbarSwap); swActionbarColor = view.findViewById(R.id.swActionbarColor); swHighlightUnread = view.findViewById(R.id.swHighlightUnread); @@ -647,10 +649,18 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("actionbar", checked).apply(); + swActionbarSwap.setEnabled(checked); swActionbarColor.setEnabled(checked); } }); + swActionbarSwap.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("actionbar_swap", checked).apply(); + } + }); + swActionbarColor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -1400,6 +1410,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer swIndentation.setEnabled(swCards.isChecked() && swThreading.isChecked()); swSeekbar.setChecked(prefs.getBoolean("seekbar", false)); swActionbar.setChecked(prefs.getBoolean("actionbar", true)); + swActionbarSwap.setChecked(prefs.getBoolean("actionbar_swap", false)); + swActionbarSwap.setEnabled(swActionbar.isChecked()); swActionbarColor.setChecked(prefs.getBoolean("actionbar_color", false)); swActionbarColor.setEnabled(swActionbar.isChecked()); diff --git a/app/src/main/res/layout/fragment_options_display.xml b/app/src/main/res/layout/fragment_options_display.xml index 95b35c3045..4839c2ede3 100644 --- a/app/src/main/res/layout/fragment_options_display.xml +++ b/app/src/main/res/layout/fragment_options_display.xml @@ -707,6 +707,18 @@ app:layout_constraintTop_toBottomOf="@id/swSeekbar" app:switchPadding="12dp" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b7bdc2cc8b..c13f880d7b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -592,6 +592,7 @@ Show extra buttons at the bottom of a message Show relative conversation position with a dot Show conversation action bar + Swap trash and archive button Use account color as background color for conversation action bar Group by account category Colorize the Android navigation bar