Sort identities by creation time

This follows the principle of least surprise: the default identity
doesn't change when a new identity is created.
This commit is contained in:
akwizgran
2014-02-10 12:15:01 +00:00
parent 71a31c2a7a
commit c6ac826acd
2 changed files with 14 additions and 7 deletions

View File

@@ -12,10 +12,17 @@ public class LocalAuthorItemComparator implements Comparator<LocalAuthorItem> {
public int compare(LocalAuthorItem a, LocalAuthorItem b) {
if(a == b) return 0;
if(a == ANONYMOUS || b == NEW) return -1;
if(a == NEW || b == ANONYMOUS) return 1;
String aName = a.getLocalAuthor().getName();
String bName = b.getLocalAuthor().getName();
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
// NEW comes after everything else
if(a == NEW) return 1;
if(b == NEW) return -1;
// ANONYMOUS comes after everything else except NEW
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;
}
}

View File

@@ -62,9 +62,9 @@ implements SpinnerAdapter {
public LocalAuthorItem getItem(int position) {
if(includeAnonymous) {
if(position == 0) return ANONYMOUS;
if(position == list.size()) return ANONYMOUS;
if(position == list.size() + 1) return NEW;
return list.get(position - 1);
return list.get(position);
} else {
if(position == list.size()) return NEW;
return list.get(position);