From c6ac826acd201c35393e7da5f9f9580215f35d2d Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Mon, 10 Feb 2014 12:15:01 +0000 Subject: [PATCH] Sort identities by creation time This follows the principle of least surprise: the default identity doesn't change when a new identity is created. --- .../identity/LocalAuthorItemComparator.java | 17 ++++++++++++----- .../identity/LocalAuthorSpinnerAdapter.java | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java b/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java index 349e539897..1b37470d6f 100644 --- a/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java +++ b/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java @@ -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; } } diff --git a/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java b/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java index bed42c379b..57a8e019aa 100644 --- a/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java +++ b/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java @@ -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); -- GitLab