From ff9803e07589be187dd63a13acbef6ecb4857c58 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 11 Sep 2019 12:37:50 +0200 Subject: [PATCH] Prevent filtering snoozed drafts --- .../java/eu/faircode/email/ActivityView.java | 14 +++++--- .../java/eu/faircode/email/AdapterFolder.java | 3 +- .../eu/faircode/email/AdapterNavFolder.java | 3 +- .../eu/faircode/email/AdapterOperation.java | 3 +- .../java/eu/faircode/email/DaoMessage.java | 9 ++--- .../eu/faircode/email/FragmentAccounts.java | 3 +- .../eu/faircode/email/FragmentFolders.java | 3 +- .../eu/faircode/email/FragmentMessages.java | 33 +++++++++---------- 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index cc00349372..5f8310569e 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -836,16 +836,19 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private void onMenuOutbox() { Bundle args = new Bundle(); - new SimpleTask() { + new SimpleTask() { @Override - protected Long onExecute(Context context, Bundle args) { + protected EntityFolder onExecute(Context context, Bundle args) { DB db = DB.getInstance(context); EntityFolder outbox = db.folder().getOutbox(); - return (outbox == null ? -1 : outbox.id); + return outbox; } @Override - protected void onExecuted(Bundle args, Long folder) { + protected void onExecuted(Bundle args, EntityFolder outbox) { + if (outbox == null) + return; + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("unified", 0); @@ -853,7 +856,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_MESSAGES) .putExtra("account", -1L) - .putExtra("folder", folder)); + .putExtra("folder", outbox.id) + .putExtra("type", outbox.type)); } @Override diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 1f7366bba7..105c0cde2a 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -317,7 +317,8 @@ public class AdapterFolder extends RecyclerView.Adapter 0 END)" + " AND (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0)" + " AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0)" + - " AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL)" + + " AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_drafts + ")" + " ORDER BY CASE" + " WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" + " WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" + @@ -86,8 +89,6 @@ public interface DaoMessage { boolean found, boolean debug); - String is_outbox = "folder.type = '" + EntityFolder.OUTBOX + "'"; - @Query("SELECT message.*" + ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + @@ -112,7 +113,7 @@ public interface DaoMessage { " HAVING SUM(CASE WHEN folder.id = :folder THEN 1 ELSE 0 END) > 0" + " AND (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0 OR " + is_outbox + ")" + " AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0 OR " + is_outbox + ")" + - " AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_outbox + ")" + + " AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_outbox + " OR " + is_drafts + ")" + " ORDER BY CASE" + " WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" + " WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" + diff --git a/app/src/main/java/eu/faircode/email/FragmentAccounts.java b/app/src/main/java/eu/faircode/email/FragmentAccounts.java index c53ebfb937..7c673f013b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccounts.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccounts.java @@ -143,7 +143,8 @@ public class FragmentAccounts extends FragmentBase { lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_MESSAGES) .putExtra("account", drafts.account) - .putExtra("folder", drafts.id)); + .putExtra("folder", drafts.id) + .putExtra("type", drafts.type)); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index 7f303e2795..fd2a5f91c6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -207,7 +207,8 @@ public class FragmentFolders extends FragmentBase { lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_MESSAGES) .putExtra("account", drafts.account) - .putExtra("folder", drafts.id)); + .putExtra("folder", drafts.id) + .putExtra("type", drafts.type)); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index b82d8a76e0..ada4003380 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -212,8 +212,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private int colorAccent; private long primary; - private boolean trash = false; - private boolean outbox = false; private boolean connected; private boolean reset = false; private String searching = null; @@ -340,8 +338,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. viewType = AdapterMessage.ViewType.SEARCH; setTitle(R.string.title_search); } - - outbox = (viewType == AdapterMessage.ViewType.FOLDER); } @Override @@ -790,7 +786,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_MESSAGES) .putExtra("account", drafts.account) - .putExtra("folder", drafts.id)); + .putExtra("folder", drafts.id) + .putExtra("type", drafts.type)); } @Override @@ -2246,14 +2243,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. folders.add(folder); updateState(folders); - - boolean trash = (folder != null && EntityFolder.TRASH.equals(folder.type)); - boolean outbox = (folder != null && EntityFolder.OUTBOX.equals(folder.type)); - if (FragmentMessages.this.trash != trash || FragmentMessages.this.outbox != outbox) { - FragmentMessages.this.trash = trash; - FragmentMessages.this.outbox = outbox; - getActivity().invalidateOptionsMenu(); - } } }); db.message().liveHiddenFolder(folder, null).observe(getViewLifecycleOwner(), new Observer>() { @@ -2482,6 +2471,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. boolean compact = prefs.getBoolean("compact", false); boolean experiments = prefs.getBoolean("experiments", false); + boolean outbox = EntityFolder.OUTBOX.equals(type); + boolean folder = + (viewType == AdapterMessage.ViewType.UNIFIED || + (viewType == AdapterMessage.ViewType.FOLDER && !outbox)); + + boolean canSnooze = + (viewType == AdapterMessage.ViewType.UNIFIED && !EntityFolder.DRAFTS.equals(type)) || + (viewType == AdapterMessage.ViewType.FOLDER && !EntityFolder.DRAFTS.equals(type)); + menu.findItem(R.id.menu_search).setVisible( viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER); @@ -2521,7 +2519,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. menu.findItem(R.id.menu_filter).setVisible(viewType != AdapterMessage.ViewType.SEARCH && !outbox); menu.findItem(R.id.menu_filter_seen).setVisible(viewType != AdapterMessage.ViewType.THREAD); menu.findItem(R.id.menu_filter_unflagged).setVisible(viewType != AdapterMessage.ViewType.THREAD); - menu.findItem(R.id.menu_filter_snoozed).setVisible(viewType != AdapterMessage.ViewType.THREAD); + menu.findItem(R.id.menu_filter_snoozed).setVisible(viewType != AdapterMessage.ViewType.THREAD && canSnooze); menu.findItem(R.id.menu_filter_duplicates).setVisible(viewType == AdapterMessage.ViewType.THREAD); menu.findItem(R.id.menu_filter_seen).setChecked(filter_seen); menu.findItem(R.id.menu_filter_unflagged).setChecked(filter_unflagged); @@ -2532,7 +2530,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. menu.findItem(R.id.menu_select_all).setVisible(!outbox && (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER)); - menu.findItem(R.id.menu_empty_trash).setVisible(trash); + menu.findItem(R.id.menu_empty_trash).setVisible( + viewType == AdapterMessage.ViewType.FOLDER && EntityFolder.TRASH.equals(type)); menu.findItem(R.id.menu_force_sync).setVisible(viewType == AdapterMessage.ViewType.UNIFIED); @@ -2540,11 +2539,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. ibUnflagged.setImageResource(filter_unflagged ? R.drawable.baseline_star_border_24 : R.drawable.baseline_star_24); ibSnoozed.setImageResource(filter_snoozed ? R.drawable.baseline_timelapse_24 : R.drawable.baseline_timer_off_24); - boolean folder = (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER); - ibSeen.setVisibility(experiments && folder ? View.VISIBLE : View.GONE); ibUnflagged.setVisibility(experiments && folder ? View.VISIBLE : View.GONE); - ibSnoozed.setVisibility(experiments && folder ? View.VISIBLE : View.GONE); + ibSnoozed.setVisibility(experiments && folder && canSnooze ? View.VISIBLE : View.GONE); super.onPrepareOptionsMenu(menu); }