Add a way to save current sorting method

This commit is contained in:
Michael Schättgen 2019-03-31 22:34:25 +02:00
parent b9d011b48e
commit bbf967e2b7
4 changed files with 56 additions and 6 deletions

View file

@ -39,6 +39,15 @@ public class Preferences {
_prefs.edit().putInt("pref_tap_to_reveal_time", number).apply();
}
public void setCurrentSortCategory(SortCategory category) {
_prefs.edit().putInt("pref_current_sort_category", category.ordinal()).apply();
}
public int getCurrentSortCategory() {
return _prefs.getInt("pref_current_sort_category", 0);
}
public int getTapToRevealTime() {
return _prefs.getInt("pref_tap_to_reveal_time", 30);
}

View file

@ -6,11 +6,27 @@ import com.beemdevelopment.aegis.helpers.comparators.IssuerNameComparator;
import java.util.Comparator;
public enum SortCategory {
CUSTOM,
ACCOUNT,
ACCOUNTREVERSED,
ISSUER,
ISSUERREVERSED,
CUSTOM;
ISSUERREVERSED;
public static SortCategory fromInteger(int x) {
switch(x) {
case 0:
return CUSTOM;
case 1:
return ACCOUNT;
case 2:
return ACCOUNTREVERSED;
case 3:
return ISSUER;
case 4:
return ISSUERREVERSED;
}
return null;
}
public static Comparator getComparator(SortCategory sortCategory) {
switch(sortCategory) {
@ -27,8 +43,7 @@ public enum SortCategory {
}
public static boolean isReversed(SortCategory sortCategory) {
switch(sortCategory)
{
switch(sortCategory) {
case ACCOUNTREVERSED:
case ISSUERREVERSED:
return true;
@ -37,4 +52,22 @@ public enum SortCategory {
return false;
}
}
public static int getMenuItem(SortCategory sortCategory) {
switch (sortCategory) {
case CUSTOM:
return R.id.menu_sort_custom;
case ACCOUNT:
return R.id.menu_sort_alphabetically_name;
case ACCOUNTREVERSED:
return R.id.menu_sort_alphabetically_name_reverse;
case ISSUER:
return R.id.menu_sort_alphabetically;
case ISSUERREVERSED:
return R.id.menu_sort_alphabetically_reverse;
default:
return R.id.menu_sort_custom;
}
}
}

View file

@ -275,6 +275,10 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setSortCategory(sortCategory);
}
private void updateSortCategoryMenu(SortCategory sortCategory) {
_menu.findItem(SortCategory.getMenuItem(sortCategory)).setChecked(true);
}
private void addEntry(DatabaseEntry entry) {
_db.addEntry(entry);
_entryListView.addEntry(entry);
@ -416,6 +420,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
updateLockIcon();
if (_loaded) {
updateGroupFilterMenu();
updateSortCategoryMenu(SortCategory.fromInteger(getPreferences().getCurrentSortCategory()));
}
return true;
}
@ -462,13 +467,14 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
sortCategory = SortCategory.ACCOUNTREVERSED;
break;
case R.id.sort_custom:
case R.id.menu_sort_custom:
default:
sortCategory = SortCategory.CUSTOM;
break;
}
setSortCategory(sortCategory);
getPreferences().setCurrentSortCategory(sortCategory);
}
return super.onOptionsItemSelected(item);
}
@ -507,6 +513,8 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
}
loadEntries();
SortCategory currentSortCategory = SortCategory.fromInteger(getPreferences().getCurrentSortCategory());
setSortCategory(currentSortCategory);
}
private void loadEntries() {

View file

@ -34,7 +34,7 @@
android:id="@+id/action_sort_category"
android:checkableBehavior="single">
<item
android:id="@+id/sort_custom"
android:id="@+id/menu_sort_custom"
android:title="@string/sort_custom"
android:checked="true" />
<item