diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index e9aed5c1..f0e90ed1 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -506,6 +506,9 @@ public class MainActivity extends BaseActivity if (mode == SortMode.UNSORTED) { sortMenu.setIcon(R.drawable.ic_sort_inverted_white); menu.findItem(R.id.menu_sort_none).setChecked(true); + } else if (mode == SortMode.ISSUER) { + sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white); + menu.findItem(R.id.menu_sort_issuer).setChecked(true); } else if (mode == SortMode.LABEL) { sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white); menu.findItem(R.id.menu_sort_label).setChecked(true); @@ -594,6 +597,14 @@ public class MainActivity extends BaseActivity adapter.setSortMode(SortMode.UNSORTED); touchHelperCallback.setDragEnabled(true); } + } else if (id == R.id.menu_sort_issuer) { + item.setChecked(true); + sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white); + saveSortMode(SortMode.ISSUER); + if(adapter != null) { + adapter.setSortMode(SortMode.ISSUER); + touchHelperCallback.setDragEnabled(false); + } } else if (id == R.id.menu_sort_label) { item.setChecked(true); sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java index d6598bef..2869beab 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java @@ -37,7 +37,7 @@ public class Constants { } public enum SortMode { - UNSORTED, LABEL, LAST_USED, MOST_USED + UNSORTED, ISSUER, LABEL, LAST_USED, MOST_USED } public enum BackupType { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java index 90c37422..67739f9a 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java @@ -455,7 +455,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter String newIssuer = input.getEditableText().toString(); displayedEntries.get(pos).setIssuer(newIssuer); - if (sortMode == SortMode.LABEL) { + if (sortMode == SortMode.ISSUER) { displayedEntries = sortEntries(displayedEntries); notifyDataSetChanged(); } else { @@ -733,7 +733,9 @@ public class EntriesCardAdapter extends RecyclerView.Adapter private ArrayList sortEntries(List unsorted) { ArrayList sorted = new ArrayList<>(unsorted); - if (sortMode == SortMode.LABEL) { + if (sortMode == SortMode.ISSUER) { + Collections.sort(sorted, new IssuerComparator()); + } else if (sortMode == SortMode.LABEL) { Collections.sort(sorted, new LabelComparator()); } else if (sortMode == SortMode.LAST_USED) { Collections.sort(sorted, new LastUsedComparator()); @@ -812,6 +814,20 @@ public class EntriesCardAdapter extends RecyclerView.Adapter } } + public class IssuerComparator implements Comparator { + Collator collator; + + IssuerComparator(){ + collator = Collator.getInstance(); + collator.setStrength(Collator.PRIMARY); + } + + @Override + public int compare(Entry o1, Entry o2) { + return collator.compare(o1.getIssuer(), o2.getIssuer()); + } + } + public class LabelComparator implements Comparator { Collator collator; diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 4e77a348..9db3ddd0 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -14,6 +14,10 @@ android:title="@string/menu_sort_none" android:checked="true" /> + + @@ -21,6 +25,7 @@ + diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index 79df64a8..12ae672c 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -47,6 +47,7 @@ Sort Unsorted + Issuer Label Last used Most used