Skip to content
Snippets Groups Projects
Commit c6ac826a authored by akwizgran's avatar akwizgran
Browse files

Sort identities by creation time

This follows the principle of least surprise: the default identity
doesn't change when a new identity is created.
parent 71a31c2a
No related branches found
No related tags found
No related merge requests found
...@@ -12,10 +12,17 @@ public class LocalAuthorItemComparator implements Comparator<LocalAuthorItem> { ...@@ -12,10 +12,17 @@ public class LocalAuthorItemComparator implements Comparator<LocalAuthorItem> {
public int compare(LocalAuthorItem a, LocalAuthorItem b) { public int compare(LocalAuthorItem a, LocalAuthorItem b) {
if(a == b) return 0; if(a == b) return 0;
if(a == ANONYMOUS || b == NEW) return -1; // NEW comes after everything else
if(a == NEW || b == ANONYMOUS) return 1; if(a == NEW) return 1;
String aName = a.getLocalAuthor().getName(); if(b == NEW) return -1;
String bName = b.getLocalAuthor().getName(); // ANONYMOUS comes after everything else except NEW
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName); if(a == ANONYMOUS) return 1;
if(b == ANONYMOUS) return -1;
// Sort items in order of creation, so the oldest item is the default
long aCreated = a.getLocalAuthor().getTimeCreated();
long bCreated = b.getLocalAuthor().getTimeCreated();
if(aCreated < bCreated) return -1;
if(aCreated > bCreated) return 1;
return 0;
} }
} }
...@@ -62,9 +62,9 @@ implements SpinnerAdapter { ...@@ -62,9 +62,9 @@ implements SpinnerAdapter {
public LocalAuthorItem getItem(int position) { public LocalAuthorItem getItem(int position) {
if(includeAnonymous) { if(includeAnonymous) {
if(position == 0) return ANONYMOUS; if(position == list.size()) return ANONYMOUS;
if(position == list.size() + 1) return NEW; if(position == list.size() + 1) return NEW;
return list.get(position - 1); return list.get(position);
} else { } else {
if(position == list.size()) return NEW; if(position == list.size()) return NEW;
return list.get(position); return list.get(position);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment