From bfed7f9a5340181734acb02300938da00ca43e2b Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 10 Jan 2023 16:09:33 +0100 Subject: [PATCH] Added option to disable quick actions --- .../eu/faircode/email/FragmentMessages.java | 228 +++++++++--------- .../eu/faircode/email/FragmentOptions.java | 2 +- .../email/FragmentOptionsBehavior.java | 12 +- .../res/layout/fragment_options_behavior.xml | 14 +- app/src/main/res/values/strings.xml | 1 + 5 files changed, 142 insertions(+), 115 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 5ddc6ff4ec..e700bb65de 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -360,6 +360,7 @@ public class FragmentMessages extends FragmentBase private boolean quick_scroll; private boolean addresses; private boolean swipe_reply; + private boolean quick_actions; private int colorPrimary; private int colorAccent; @@ -503,6 +504,7 @@ public class FragmentMessages extends FragmentBase quick_scroll = prefs.getBoolean("quick_scroll", true); addresses = prefs.getBoolean("addresses", false); swipe_reply = prefs.getBoolean("swipe_reply", false); + quick_actions = prefs.getBoolean("quick_actions", true); colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary); colorAccent = Helper.resolveColor(getContext(), R.attr.colorAccent); @@ -6275,137 +6277,139 @@ public class FragmentMessages extends FragmentBase tvSelectedCount.setCompoundDrawablesRelative(null, null, null, null); tvSelectedCount.setVisibility(View.VISIBLE); - Bundle args = new Bundle(); - args.putLongArray("ids", selection); - args.putBoolean("threading", threading); + if (quick_actions) { + Bundle args = new Bundle(); + args.putLongArray("ids", selection); + args.putBoolean("threading", threading); - new SimpleTask() { - @Override - protected MoreResult onExecute(Context context, Bundle args) { - long[] ids = args.getLongArray("ids"); - boolean threading = args.getBoolean("threading"); - return MoreResult.get(context, ids, threading, true); - } + new SimpleTask() { + @Override + protected MoreResult onExecute(Context context, Bundle args) { + long[] ids = args.getLongArray("ids"); + boolean threading = args.getBoolean("threading"); + return MoreResult.get(context, ids, threading, true); + } - @Override - protected void onExecuted(Bundle args, MoreResult result) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean more_seen = prefs.getBoolean("more_seen", true); - boolean more_unseen = prefs.getBoolean("more_unseen", false); - boolean more_snooze = prefs.getBoolean("more_snooze", false); - boolean more_hide = prefs.getBoolean("more_hide", false); - boolean more_flag = prefs.getBoolean("more_flag", false); - boolean more_flag_color = prefs.getBoolean("more_flag_color", false); - boolean more_importance_high = prefs.getBoolean("more_importance_high", false); - boolean more_importance_normal = prefs.getBoolean("more_importance_normal", false); - boolean more_importance_low = prefs.getBoolean("more_importance_low", false); - boolean more_inbox = prefs.getBoolean("more_inbox", true); - boolean more_archive = prefs.getBoolean("more_archive", true); - boolean more_junk = prefs.getBoolean("more_junk", true); - boolean more_trash = prefs.getBoolean("more_trash", true); - boolean more_delete = prefs.getBoolean("more_delete", false); - boolean more_move = prefs.getBoolean("more_move", true); - - boolean inTrash = EntityFolder.TRASH.equals(type); - boolean inJunk = EntityFolder.JUNK.equals(type); - - int count = 0; - - boolean move = (more_move && count < MAX_QUICK_ACTIONS && result.canMove()); - if (move) - count++; + @Override + protected void onExecuted(Bundle args, MoreResult result) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean more_seen = prefs.getBoolean("more_seen", true); + boolean more_unseen = prefs.getBoolean("more_unseen", false); + boolean more_snooze = prefs.getBoolean("more_snooze", false); + boolean more_hide = prefs.getBoolean("more_hide", false); + boolean more_flag = prefs.getBoolean("more_flag", false); + boolean more_flag_color = prefs.getBoolean("more_flag_color", false); + boolean more_importance_high = prefs.getBoolean("more_importance_high", false); + boolean more_importance_normal = prefs.getBoolean("more_importance_normal", false); + boolean more_importance_low = prefs.getBoolean("more_importance_low", false); + boolean more_inbox = prefs.getBoolean("more_inbox", true); + boolean more_archive = prefs.getBoolean("more_archive", true); + boolean more_junk = prefs.getBoolean("more_junk", true); + boolean more_trash = prefs.getBoolean("more_trash", true); + boolean more_delete = prefs.getBoolean("more_delete", false); + boolean more_move = prefs.getBoolean("more_move", true); + + boolean inTrash = EntityFolder.TRASH.equals(type); + boolean inJunk = EntityFolder.JUNK.equals(type); + + int count = 0; + + boolean move = (more_move && count < MAX_QUICK_ACTIONS && result.canMove()); + if (move) + count++; - boolean delete = (more_delete && count < MAX_QUICK_ACTIONS && result.canDelete()); - if (delete) - count++; + boolean delete = (more_delete && count < MAX_QUICK_ACTIONS && result.canDelete()); + if (delete) + count++; - boolean trash = (more_trash && count < MAX_QUICK_ACTIONS && result.canTrash()); - if (trash) - count++; + boolean trash = (more_trash && count < MAX_QUICK_ACTIONS && result.canTrash()); + if (trash) + count++; - if (!delete && !trash && (inTrash || inJunk) && - more_trash && count < MAX_QUICK_ACTIONS && result.canDelete()) { - delete = true; - count++; - } + if (!delete && !trash && (inTrash || inJunk) && + more_trash && count < MAX_QUICK_ACTIONS && result.canDelete()) { + delete = true; + count++; + } - boolean junk = (more_junk && count < MAX_QUICK_ACTIONS && result.canJunk()); - if (junk) - count++; + boolean junk = (more_junk && count < MAX_QUICK_ACTIONS && result.canJunk()); + if (junk) + count++; - boolean archive = (more_archive && count < MAX_QUICK_ACTIONS && result.canArchive()); - if (archive) - count++; + boolean archive = (more_archive && count < MAX_QUICK_ACTIONS && result.canArchive()); + if (archive) + count++; - boolean inbox = ((more_inbox || (more_junk && inJunk)) && count < MAX_QUICK_ACTIONS && result.canInbox()); - if (inbox) - count++; + boolean inbox = ((more_inbox || (more_junk && inJunk)) && count < MAX_QUICK_ACTIONS && result.canInbox()); + if (inbox) + count++; - boolean importance_high = (more_importance_high && count < MAX_QUICK_ACTIONS && - !EntityMessage.PRIORITIY_HIGH.equals(result.importance)); - if (importance_high) - count++; + boolean importance_high = (more_importance_high && count < MAX_QUICK_ACTIONS && + !EntityMessage.PRIORITIY_HIGH.equals(result.importance)); + if (importance_high) + count++; - boolean importance_normal = (more_importance_normal && count < MAX_QUICK_ACTIONS && - !EntityMessage.PRIORITIY_NORMAL.equals(result.importance)); - if (importance_normal) - count++; + boolean importance_normal = (more_importance_normal && count < MAX_QUICK_ACTIONS && + !EntityMessage.PRIORITIY_NORMAL.equals(result.importance)); + if (importance_normal) + count++; - boolean importance_low = (more_importance_low && count < MAX_QUICK_ACTIONS && - !EntityMessage.PRIORITIY_LOW.equals(result.importance)); - if (importance_low) - count++; + boolean importance_low = (more_importance_low && count < MAX_QUICK_ACTIONS && + !EntityMessage.PRIORITIY_LOW.equals(result.importance)); + if (importance_low) + count++; - boolean flag = (more_flag && count < MAX_QUICK_ACTIONS && result.unflagged); - if (flag) - count++; + boolean flag = (more_flag && count < MAX_QUICK_ACTIONS && result.unflagged); + if (flag) + count++; - boolean flag_color = (more_flag_color && count < MAX_QUICK_ACTIONS && (result.unflagged || result.flagged)); - if (flag_color) - count++; + boolean flag_color = (more_flag_color && count < MAX_QUICK_ACTIONS && (result.unflagged || result.flagged)); + if (flag_color) + count++; - boolean hide = (more_hide && count < MAX_QUICK_ACTIONS && result.visible); - if (hide) - count++; + boolean hide = (more_hide && count < MAX_QUICK_ACTIONS && result.visible); + if (hide) + count++; - boolean snooze = (more_snooze && count < MAX_QUICK_ACTIONS); - if (snooze) - count++; + boolean snooze = (more_snooze && count < MAX_QUICK_ACTIONS); + if (snooze) + count++; - boolean unseen = (more_unseen && count < MAX_QUICK_ACTIONS && result.seen); - if (unseen) - count++; + boolean unseen = (more_unseen && count < MAX_QUICK_ACTIONS && result.seen); + if (unseen) + count++; - boolean seen = (more_seen && count < MAX_QUICK_ACTIONS && result.unseen); - if (seen) - count++; + boolean seen = (more_seen && count < MAX_QUICK_ACTIONS && result.unseen); + if (seen) + count++; - ibInbox.setImageResource(inJunk ? R.drawable.twotone_report_off_24 : R.drawable.twotone_inbox_24); - - ibBatchSeen.setVisibility(seen ? View.VISIBLE : View.GONE); - ibBatchUnseen.setVisibility(unseen ? View.VISIBLE : View.GONE); - ibBatchSnooze.setVisibility(snooze ? View.VISIBLE : View.GONE); - ibBatchHide.setVisibility(hide ? View.VISIBLE : View.GONE); - ibBatchFlag.setVisibility(flag ? View.VISIBLE : View.GONE); - ibBatchFlagColor.setVisibility(flag_color ? View.VISIBLE : View.GONE); - ibLowImportance.setVisibility(importance_low ? View.VISIBLE : View.GONE); - ibNormalImportance.setVisibility(importance_normal ? View.VISIBLE : View.GONE); - ibHighImportance.setVisibility(importance_high ? View.VISIBLE : View.GONE); - ibInbox.setVisibility(inbox ? View.VISIBLE : View.GONE); - ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE); - ibJunk.setVisibility(junk ? View.VISIBLE : View.GONE); - ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE); - ibDelete.setVisibility(delete ? View.VISIBLE : View.GONE); - ibMove.setVisibility(move ? View.VISIBLE : View.GONE); - cardMore.setTag(fabMore.isOrWillBeShown() ? result : null); - cardMore.setVisibility(fabMore.isOrWillBeShown() ? View.VISIBLE : View.GONE); - } + ibInbox.setImageResource(inJunk ? R.drawable.twotone_report_off_24 : R.drawable.twotone_inbox_24); + + ibBatchSeen.setVisibility(seen ? View.VISIBLE : View.GONE); + ibBatchUnseen.setVisibility(unseen ? View.VISIBLE : View.GONE); + ibBatchSnooze.setVisibility(snooze ? View.VISIBLE : View.GONE); + ibBatchHide.setVisibility(hide ? View.VISIBLE : View.GONE); + ibBatchFlag.setVisibility(flag ? View.VISIBLE : View.GONE); + ibBatchFlagColor.setVisibility(flag_color ? View.VISIBLE : View.GONE); + ibLowImportance.setVisibility(importance_low ? View.VISIBLE : View.GONE); + ibNormalImportance.setVisibility(importance_normal ? View.VISIBLE : View.GONE); + ibHighImportance.setVisibility(importance_high ? View.VISIBLE : View.GONE); + ibInbox.setVisibility(inbox ? View.VISIBLE : View.GONE); + ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE); + ibJunk.setVisibility(junk ? View.VISIBLE : View.GONE); + ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE); + ibDelete.setVisibility(delete ? View.VISIBLE : View.GONE); + ibMove.setVisibility(move ? View.VISIBLE : View.GONE); + cardMore.setTag(fabMore.isOrWillBeShown() ? result : null); + cardMore.setVisibility(fabMore.isOrWillBeShown() ? View.VISIBLE : View.GONE); + } - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(getParentFragmentManager(), ex); - } - }.serial().setId("messages:" + FragmentMessages.this.hashCode()).execute(this, args, "quickactions"); + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.serial().setId("messages:" + FragmentMessages.this.hashCode()).execute(this, args, "quickactions"); + } } else { fabMore.hide(); tvSelectedCount.setVisibility(View.GONE); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index e9366b139a..069a627b17 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 { "autoscroll", "swipenav", "reversed", "swipe_close", "swipe_move", "autoexpand", "autoclose", "onclose", "swipe_reply", "language_detection", - "quick_filter", "quick_scroll", + "quick_filter", "quick_scroll", "quick_actions", "experiments", "debug", "log_level", "test1", "test2", "test3", "test4", "test5", "webview_legacy", "browser_zoom", "fake_dark", "show_recent", diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index dabc62ad35..e1d30dc4d6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -72,6 +72,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private SwitchCompat swAutoScroll; private SwitchCompat swQuickFilter; private SwitchCompat swQuickScroll; + private SwitchCompat swQuickActions; private Button btnSwipes; private SeekBar sbSwipeSensitivity; private SwitchCompat swFolderNav; @@ -107,7 +108,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private final static String[] RESET_OPTIONS = new String[]{ "restore_on_launch", "sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection", "photo_picker", "default_snooze", - "pull", "autoscroll", "quick_filter", "quick_scroll", "swipe_sensitivity", "foldernav", + "pull", "autoscroll", "quick_filter", "quick_scroll", "quick_actions", "swipe_sensitivity", "foldernav", "doubletap", "swipenav", "volumenav", "reversed", "swipe_close", "swipe_move", "autoexpand", "expand_first", "expand_all", "expand_one", "collapse_multiple", "autoclose", "onclose", "autoclose_unseen", "collapse_marked", @@ -140,6 +141,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swAutoScroll = view.findViewById(R.id.swAutoScroll); swQuickFilter = view.findViewById(R.id.swQuickFilter); swQuickScroll = view.findViewById(R.id.swQuickScroll); + swQuickActions = view.findViewById(R.id.swQuickActions); btnSwipes = view.findViewById(R.id.btnSwipes); sbSwipeSensitivity = view.findViewById(R.id.sbSwipeSensitivity); swFolderNav = view.findViewById(R.id.swFolderNav); @@ -289,6 +291,13 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe } }); + swQuickActions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("quick_actions", checked).apply(); + } + }); + btnSwipes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -574,6 +583,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false)); swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false)); swQuickScroll.setChecked(prefs.getBoolean("quick_scroll", true)); + swQuickActions.setChecked(prefs.getBoolean("quick_actions", true)); int swipe_sensitivity = prefs.getInt("swipe_sensitivity", DEFAULT_SWIPE_SENSITIVITY); sbSwipeSensitivity.setProgress(swipe_sensitivity); diff --git a/app/src/main/res/layout/fragment_options_behavior.xml b/app/src/main/res/layout/fragment_options_behavior.xml index 7c37f53899..af6745a635 100644 --- a/app/src/main/res/layout/fragment_options_behavior.xml +++ b/app/src/main/res/layout/fragment_options_behavior.xml @@ -296,6 +296,18 @@ app:layout_constraintTop_toBottomOf="@id/swQuickFilter" app:switchPadding="12dp" /> + +