1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 12:44:42 +00:00

Added filter seen

This commit is contained in:
M66B 2019-04-28 15:16:26 +02:00
parent 895648cf86
commit 4e26fa1577
5 changed files with 98 additions and 63 deletions

View file

@ -131,7 +131,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean monospaced;
private int zoom;
private String sort;
private boolean duplicates;
private boolean filter_duplicates;
private boolean suitable;
private IProperties properties;
@ -448,7 +448,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
pbLoading.setVisibility(View.GONE);
if (viewType == ViewType.THREAD)
view.setVisibility(duplicates || !message.duplicate ? View.VISIBLE : View.GONE);
view.setVisibility(!filter_duplicates || !message.duplicate ? View.VISIBLE : View.GONE);
// Text size
if (textSize != 0) {
@ -3020,7 +3020,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
AdapterMessage(Context context, LifecycleOwner owner,
ViewType viewType, boolean compact, int zoom, String sort, boolean duplicates, IProperties properties) {
ViewType viewType, boolean compact, int zoom, String sort, boolean filter_duplicates, IProperties properties) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.TF = Helper.getTimeInstance(context, SimpleDateFormat.SHORT);
@ -3035,7 +3035,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.monospaced = prefs.getBoolean("monospaced", false);
this.zoom = zoom;
this.sort = sort;
this.duplicates = duplicates;
this.filter_duplicates = filter_duplicates;
this.suitable = Helper.getNetworkState(context).isSuitable();
this.properties = properties;
@ -3108,9 +3108,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return this.sort;
}
void setDuplicates(boolean duplicates) {
if (this.duplicates != duplicates) {
this.duplicates = duplicates;
void setFilterDuplicates(boolean filter_duplicates) {
if (this.filter_duplicates != filter_duplicates) {
this.filter_duplicates = filter_duplicates;
notifyDataSetChanged();
}
}

View file

@ -64,10 +64,11 @@ public interface DaoMessage {
" JOIN folder ON folder.id = message.folder" +
" WHERE account.`synchronize`" +
" AND (NOT message.ui_hide OR :debug)" +
" AND (:snoozed OR :found OR ui_snoozed IS NULL)" +
" AND (NOT :filter_snoozed OR ui_snoozed IS NULL)" +
" AND (NOT :found OR ui_found = :found)" +
" GROUP BY account.id, CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
" HAVING :found OR SUM(unified) > 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<Integer, TupleMessageEx> pagedUnifiedInbox(boolean threading, String sort, boolean snoozed, boolean found, boolean debug);
DataSource.Factory<Integer, TupleMessageEx> 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<Integer, TupleMessageEx> pagedFolder(long folder, boolean threading, String sort, boolean snoozed, boolean found, boolean debug);
DataSource.Factory<Integer, TupleMessageEx> 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" +

View file

@ -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;
}

View file

@ -44,6 +44,31 @@
</menu>
</item>
<item
android:id="@+id/menu_filter"
android:icon="@drawable/baseline_filter_list_24"
android:title="@string/title_filter"
app:showAsAction="ifRoom">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/menu_filter_seen"
android:checkable="true"
android:title="@string/title_filter_seen" />
<item
android:id="@+id/menu_filter_snoozed"
android:checkable="true"
android:title="@string/title_filter_snoozed" />
<item
android:id="@+id/menu_filter_duplicates"
android:checkable="true"
android:title="@string/title_filter_duplicates" />
</group>
</menu>
</item>
<item
android:id="@+id/menu_zoom"
android:icon="@drawable/baseline_format_size_24"
@ -56,18 +81,6 @@
android:title="@string/title_compact"
app:showAsAction="never" />
<item
android:id="@+id/menu_snoozed"
android:checkable="true"
android:title="@string/title_snoozed"
app:showAsAction="never" />
<item
android:id="@+id/menu_duplicates"
android:checkable="true"
android:title="@string/title_duplicates"
app:showAsAction="never" />
<item
android:id="@+id/menu_select_all"
android:icon="@drawable/baseline_format_size_24"

View file

@ -465,10 +465,13 @@
<string name="title_sort_on_subject">Subject</string>
<string name="title_sort_on_size">Size</string>
<string name="title_filter">Filter</string>
<string name="title_filter_seen">Read</string>
<string name="title_filter_snoozed">Snoozed</string>
<string name="title_filter_duplicates">Duplicates</string>
<string name="title_compact">Compact view</string>
<string name="title_zoom">Text size</string>
<string name="title_snoozed">Snoozed</string>
<string name="title_duplicates">Show duplicates</string>
<string name="title_select_all">Select all</string>
<string name="title_address_sent">Sent:</string>