Add sorting by issuer
This commit is contained in:
parent
3084596931
commit
7a6922d06c
5 changed files with 36 additions and 3 deletions
|
@ -506,6 +506,9 @@ public class MainActivity extends BaseActivity
|
||||||
if (mode == SortMode.UNSORTED) {
|
if (mode == SortMode.UNSORTED) {
|
||||||
sortMenu.setIcon(R.drawable.ic_sort_inverted_white);
|
sortMenu.setIcon(R.drawable.ic_sort_inverted_white);
|
||||||
menu.findItem(R.id.menu_sort_none).setChecked(true);
|
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) {
|
} else if (mode == SortMode.LABEL) {
|
||||||
sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white);
|
sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white);
|
||||||
menu.findItem(R.id.menu_sort_label).setChecked(true);
|
menu.findItem(R.id.menu_sort_label).setChecked(true);
|
||||||
|
@ -594,6 +597,14 @@ public class MainActivity extends BaseActivity
|
||||||
adapter.setSortMode(SortMode.UNSORTED);
|
adapter.setSortMode(SortMode.UNSORTED);
|
||||||
touchHelperCallback.setDragEnabled(true);
|
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) {
|
} else if (id == R.id.menu_sort_label) {
|
||||||
item.setChecked(true);
|
item.setChecked(true);
|
||||||
sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white);
|
sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class Constants {
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SortMode {
|
public enum SortMode {
|
||||||
UNSORTED, LABEL, LAST_USED, MOST_USED
|
UNSORTED, ISSUER, LABEL, LAST_USED, MOST_USED
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum BackupType {
|
public enum BackupType {
|
||||||
|
|
|
@ -455,7 +455,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
|
||||||
String newIssuer = input.getEditableText().toString();
|
String newIssuer = input.getEditableText().toString();
|
||||||
|
|
||||||
displayedEntries.get(pos).setIssuer(newIssuer);
|
displayedEntries.get(pos).setIssuer(newIssuer);
|
||||||
if (sortMode == SortMode.LABEL) {
|
if (sortMode == SortMode.ISSUER) {
|
||||||
displayedEntries = sortEntries(displayedEntries);
|
displayedEntries = sortEntries(displayedEntries);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
} else {
|
} else {
|
||||||
|
@ -733,7 +733,9 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
|
||||||
private ArrayList<Entry> sortEntries(List<Entry> unsorted) {
|
private ArrayList<Entry> sortEntries(List<Entry> unsorted) {
|
||||||
ArrayList<Entry> sorted = new ArrayList<>(unsorted);
|
ArrayList<Entry> 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());
|
Collections.sort(sorted, new LabelComparator());
|
||||||
} else if (sortMode == SortMode.LAST_USED) {
|
} else if (sortMode == SortMode.LAST_USED) {
|
||||||
Collections.sort(sorted, new LastUsedComparator());
|
Collections.sort(sorted, new LastUsedComparator());
|
||||||
|
@ -812,6 +814,20 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class IssuerComparator implements Comparator<Entry> {
|
||||||
|
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<Entry> {
|
public class LabelComparator implements Comparator<Entry> {
|
||||||
Collator collator;
|
Collator collator;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
android:title="@string/menu_sort_none"
|
android:title="@string/menu_sort_none"
|
||||||
android:checked="true" />
|
android:checked="true" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_sort_issuer"
|
||||||
|
android:title="@string/menu_sort_issuer" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_sort_label"
|
android:id="@+id/menu_sort_label"
|
||||||
android:title="@string/menu_sort_label" />
|
android:title="@string/menu_sort_label" />
|
||||||
|
@ -21,6 +25,7 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_sort_last_used"
|
android:id="@+id/menu_sort_last_used"
|
||||||
android:title="@string/menu_sort_last_used" />
|
android:title="@string/menu_sort_last_used" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_sort_most_used"
|
android:id="@+id/menu_sort_most_used"
|
||||||
android:title="@string/menu_sort_most_used" />
|
android:title="@string/menu_sort_most_used" />
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
<string name="menu_main_sort">Sort</string>
|
<string name="menu_main_sort">Sort</string>
|
||||||
|
|
||||||
<string name="menu_sort_none">Unsorted</string>
|
<string name="menu_sort_none">Unsorted</string>
|
||||||
|
<string name="menu_sort_issuer">Issuer</string>
|
||||||
<string name="menu_sort_label">Label</string>
|
<string name="menu_sort_label">Label</string>
|
||||||
<string name="menu_sort_last_used">Last used</string>
|
<string name="menu_sort_last_used">Last used</string>
|
||||||
<string name="menu_sort_most_used">Most used</string>
|
<string name="menu_sort_most_used">Most used</string>
|
||||||
|
|
Loading…
Reference in a new issue