mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user