From 4e26fa1577b3242e0f32ee3fa50ed1940697b914 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 28 Apr 2019 15:16:26 +0200 Subject: [PATCH] Added filter seen --- .../eu/faircode/email/AdapterMessage.java | 14 +-- .../java/eu/faircode/email/DaoMessage.java | 12 ++- .../eu/faircode/email/FragmentMessages.java | 91 +++++++++++-------- app/src/main/res/menu/menu_messages.xml | 37 +++++--- app/src/main/res/values/strings.xml | 7 +- 5 files changed, 98 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 340ec35013..85e9a14810 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -131,7 +131,7 @@ public class AdapterMessage extends RecyclerView.Adapter 0" + + " AND (NOT :filter_seen OR " + unseen_unified + " > 0)" + " ORDER BY" + " CASE" + " WHEN 'unread' = :sort THEN " + unseen_unified + " = 0" + @@ -78,7 +79,8 @@ public interface DaoMessage { " ELSE 0" + " END, message.received DESC") @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) - DataSource.Factory pagedUnifiedInbox(boolean threading, String sort, boolean snoozed, boolean found, boolean debug); + DataSource.Factory pagedUnifiedInbox( + boolean threading, String sort, boolean filter_seen, boolean filter_snoozed, boolean found, boolean debug); String unseen_folder = "SUM(CASE WHEN message.ui_seen" + " OR (folder.id <> :folder AND folder.type = '" + EntityFolder.ARCHIVE + "')" + @@ -108,10 +110,11 @@ public interface DaoMessage { " JOIN folder f ON f.id = :folder" + " WHERE (message.account = f.account OR folder.type = '" + EntityFolder.OUTBOX + "')" + " AND (NOT message.ui_hide OR :debug)" + - " AND (:snoozed OR :found OR ui_snoozed IS NULL OR folder.type = '" + EntityFolder.OUTBOX + "')" + + " AND (NOT :filter_snoozed OR ui_snoozed IS NULL)" + " AND (NOT :found OR ui_found = :found)" + " GROUP BY CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " HAVING SUM(CASE WHEN folder.id = :folder THEN 1 ELSE 0 END) > 0" + + " AND (NOT :filter_seen OR " + unseen_folder + " > 0)" + " ORDER BY" + " CASE" + " WHEN 'unread' = :sort THEN " + unseen_folder + " = 0" + @@ -122,7 +125,8 @@ public interface DaoMessage { " ELSE 0" + " END, message.received DESC") @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) - DataSource.Factory pagedFolder(long folder, boolean threading, String sort, boolean snoozed, boolean found, boolean debug); + DataSource.Factory pagedFolder( + long folder, boolean threading, String sort, boolean filter_seen, boolean filter_snoozed, boolean found, boolean debug); @Query("SELECT message.*" + ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index d2d9960989..9ba80fe0ff 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -425,11 +425,11 @@ public class FragmentMessages extends FragmentBase { boolean compact = prefs.getBoolean("compact", false); int zoom = prefs.getInt("zoom", compact ? 0 : 1); String sort = prefs.getString("sort", "time"); - boolean duplicates = prefs.getBoolean("duplicates", true); + boolean filter_duplicates = prefs.getBoolean("filter_duplicates", false); adapter = new AdapterMessage( getContext(), getViewLifecycleOwner(), - viewType, compact, zoom, sort, duplicates, iProperties); + viewType, compact, zoom, sort, filter_duplicates, iProperties); rvMessage.setAdapter(adapter); @@ -2050,15 +2050,16 @@ public class FragmentMessages extends FragmentBase { else if ("size".equals(sort)) menu.findItem(R.id.menu_sort_on_size).setChecked(true); + menu.findItem(R.id.menu_filter).setVisible(viewType != AdapterMessage.ViewType.SEARCH); + menu.findItem(R.id.menu_filter_seen).setVisible(viewType != AdapterMessage.ViewType.THREAD); + menu.findItem(R.id.menu_filter_snoozed).setVisible(viewType != AdapterMessage.ViewType.THREAD); + menu.findItem(R.id.menu_filter_duplicates).setVisible(viewType == AdapterMessage.ViewType.THREAD); + menu.findItem(R.id.menu_filter_seen).setChecked(prefs.getBoolean("filter_seen", false)); + menu.findItem(R.id.menu_filter_snoozed).setChecked(prefs.getBoolean("filter_snoozed", true)); + menu.findItem(R.id.menu_filter_duplicates).setChecked(prefs.getBoolean("filter_duplicates", false)); + menu.findItem(R.id.menu_compact).setChecked(prefs.getBoolean("compact", false)); - menu.findItem(R.id.menu_snoozed).setVisible(!outbox && - (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER)); - menu.findItem(R.id.menu_snoozed).setChecked(prefs.getBoolean("snoozed", false)); - - menu.findItem(R.id.menu_duplicates).setVisible(viewType == AdapterMessage.ViewType.THREAD); - menu.findItem(R.id.menu_duplicates).setChecked(prefs.getBoolean("duplicates", true)); - menu.findItem(R.id.menu_select_all).setVisible(!outbox && (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER)); @@ -2103,6 +2104,18 @@ public class FragmentMessages extends FragmentBase { onMenuSort("size"); return true; + case R.id.menu_filter_seen: + onMenuFilterRead(!item.isChecked()); + return true; + + case R.id.menu_filter_snoozed: + onMenuFilterSnoozed(!item.isChecked()); + return true; + + case R.id.menu_filter_duplicates: + onMenuFilterDuplicates(!item.isChecked()); + return true; + case R.id.menu_zoom: onMenuZoom(); return true; @@ -2111,14 +2124,6 @@ public class FragmentMessages extends FragmentBase { onMenuCompact(); return true; - case R.id.menu_snoozed: - onMenuSnoozed(); - return true; - - case R.id.menu_duplicates: - onMenuDuplicates(); - return true; - case R.id.menu_select_all: onMenuSelectAll(); return true; @@ -2150,6 +2155,31 @@ public class FragmentMessages extends FragmentBase { loadMessages(); } + private void onMenuFilterRead(boolean filter) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + prefs.edit().putBoolean("filter_seen", filter).apply(); + getActivity().invalidateOptionsMenu(); + if (selectionTracker != null) + selectionTracker.clearSelection(); + loadMessages(); + } + + private void onMenuFilterSnoozed(boolean filter) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + prefs.edit().putBoolean("filter_snoozed", filter).apply(); + getActivity().invalidateOptionsMenu(); + if (selectionTracker != null) + selectionTracker.clearSelection(); + loadMessages(); + } + + private void onMenuFilterDuplicates(boolean filter) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + prefs.edit().putBoolean("filter_duplicates", filter).apply(); + getActivity().invalidateOptionsMenu(); + adapter.setFilterDuplicates(filter); + } + private void onMenuZoom() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean compact = prefs.getBoolean("compact", false); @@ -2172,22 +2202,6 @@ public class FragmentMessages extends FragmentBase { getActivity().invalidateOptionsMenu(); } - private void onMenuSnoozed() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean snoozed = prefs.getBoolean("snoozed", false); - prefs.edit().putBoolean("snoozed", !snoozed).apply(); - if (selectionTracker != null) - selectionTracker.clearSelection(); - loadMessages(); - } - - private void onMenuDuplicates() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean duplicates = prefs.getBoolean("duplicates", true); - prefs.edit().putBoolean("duplicates", !duplicates).apply(); - adapter.setDuplicates(!duplicates); - } - private void onMenuSelectAll() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean snoozed = prefs.getBoolean("snoozed", false); @@ -2291,7 +2305,8 @@ public class FragmentMessages extends FragmentBase { // Observe folder/messages/search SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); String sort = prefs.getString("sort", "time"); - boolean snoozed = prefs.getBoolean("snoozed", false); + boolean filter_seen = prefs.getBoolean("filter_seen", false); + boolean filter_snoozed = prefs.getBoolean("filter_snoozed", true); boolean debug = prefs.getBoolean("debug", false); Log.i("Load messages type=" + viewType + " sort=" + sort + " debug=" + debug); @@ -2304,7 +2319,7 @@ public class FragmentMessages extends FragmentBase { switch (viewType) { case UNIFIED: builder = new LivePagedListBuilder<>( - db.message().pagedUnifiedInbox(threading, sort, snoozed, false, debug), LOCAL_PAGE_SIZE); + db.message().pagedUnifiedInbox(threading, sort, filter_seen, filter_snoozed, false, debug), LOCAL_PAGE_SIZE); break; case FOLDER: @@ -2313,7 +2328,7 @@ public class FragmentMessages extends FragmentBase { .setPrefetchDistance(REMOTE_PAGE_SIZE) .build(); builder = new LivePagedListBuilder<>( - db.message().pagedFolder(folder, threading, sort, snoozed, false, debug), configFolder); + db.message().pagedFolder(folder, threading, sort, filter_seen, filter_snoozed, false, debug), configFolder); builder.setBoundaryCallback(boundaryCallback); break; @@ -2329,10 +2344,10 @@ public class FragmentMessages extends FragmentBase { .build(); if (folder < 0) builder = new LivePagedListBuilder<>( - db.message().pagedUnifiedInbox(threading, "time", snoozed, true, debug), configSearch); + db.message().pagedUnifiedInbox(threading, "time", false, false, true, debug), configSearch); else builder = new LivePagedListBuilder<>( - db.message().pagedFolder(folder, threading, "time", snoozed, true, debug), configSearch); + db.message().pagedFolder(folder, threading, "time", false, false, true, debug), configSearch); builder.setBoundaryCallback(boundaryCallback); break; } diff --git a/app/src/main/res/menu/menu_messages.xml b/app/src/main/res/menu/menu_messages.xml index a7e592b3fd..b94c549e14 100644 --- a/app/src/main/res/menu/menu_messages.xml +++ b/app/src/main/res/menu/menu_messages.xml @@ -44,6 +44,31 @@ + + + + + + + + + + + + - - - - Subject Size + Filter + Read + Snoozed + Duplicates + Compact view Text size - Snoozed - Show duplicates Select all Sent: