Filter improvement/fix

This commit is contained in:
M66B 2019-10-19 11:45:34 +02:00
parent 8db7b8fdda
commit bb1f911d8f
2 changed files with 24 additions and 44 deletions

View File

@ -611,7 +611,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
public void onClick(View view) { public void onClick(View view) {
boolean filter = prefs.getBoolean("filter_seen", true); boolean filter = prefs.getBoolean("filter_seen", true);
onMenuFilterSeen(!filter); onMenuFilter("filter_seen", !filter);
} }
}); });
@ -619,7 +619,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
public void onClick(View view) { public void onClick(View view) {
boolean filter = prefs.getBoolean("filter_unflagged", true); boolean filter = prefs.getBoolean("filter_unflagged", true);
onMenuFilterUnflagged(!filter); onMenuFilter("filter_unflagged", !filter);
} }
}); });
@ -627,7 +627,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
public void onClick(View view) { public void onClick(View view) {
boolean filter = prefs.getBoolean("filter_snoozed", true); boolean filter = prefs.getBoolean("filter_snoozed", true);
onMenuFilterSnoozed(!filter); onMenuFilter("filter_snoozed", !filter);
} }
}); });
@ -2685,15 +2685,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return true; return true;
case R.id.menu_filter_seen: case R.id.menu_filter_seen:
onMenuFilterSeen(!item.isChecked()); onMenuFilter("filter_seen", !item.isChecked());
return true; return true;
case R.id.menu_filter_unflagged: case R.id.menu_filter_unflagged:
onMenuFilterUnflagged(!item.isChecked()); onMenuFilter("filter_unflagged", !item.isChecked());
return true; return true;
case R.id.menu_filter_snoozed: case R.id.menu_filter_snoozed:
onMenuFilterSnoozed(!item.isChecked()); onMenuFilter("filter_snoozed", !item.isChecked());
return true; return true;
case R.id.menu_filter_duplicates: case R.id.menu_filter_duplicates:
@ -2760,27 +2760,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
loadMessages(true); loadMessages(true);
} }
private void onMenuFilterSeen(boolean filter) { private void onMenuFilter(String name, boolean filter) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("filter_seen", filter).apply(); prefs.edit().putBoolean(name, filter).apply();
getActivity().invalidateOptionsMenu();
if (selectionTracker != null)
selectionTracker.clearSelection();
loadMessages(true);
}
private void onMenuFilterUnflagged(boolean filter) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("filter_unflagged", filter).apply();
getActivity().invalidateOptionsMenu();
if (selectionTracker != null)
selectionTracker.clearSelection();
loadMessages(true);
}
private void onMenuFilterSnoozed(boolean filter) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("filter_snoozed", filter).apply();
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
if (selectionTracker != null) if (selectionTracker != null)
selectionTracker.clearSelection(); selectionTracker.clearSelection();

View File

@ -57,27 +57,25 @@
android:title="@string/title_filter" android:title="@string/title_filter"
app:showAsAction="ifRoom"> app:showAsAction="ifRoom">
<menu> <menu>
<group android:checkableBehavior="single"> <item
<item android:id="@+id/menu_filter_seen"
android:id="@+id/menu_filter_seen" android:checkable="true"
android:checkable="true" android:title="@string/title_filter_seen" />
android:title="@string/title_filter_seen" />
<item <item
android:id="@+id/menu_filter_unflagged" android:id="@+id/menu_filter_unflagged"
android:checkable="true" android:checkable="true"
android:title="@string/title_filter_unflagged" /> android:title="@string/title_filter_unflagged" />
<item <item
android:id="@+id/menu_filter_snoozed" android:id="@+id/menu_filter_snoozed"
android:checkable="true" android:checkable="true"
android:title="@string/title_filter_hidden" /> android:title="@string/title_filter_hidden" />
<item <item
android:id="@+id/menu_filter_duplicates" android:id="@+id/menu_filter_duplicates"
android:checkable="true" android:checkable="true"
android:title="@string/title_filter_duplicates" /> android:title="@string/title_filter_duplicates" />
</group>
</menu> </menu>
</item> </item>