diff options
author | Arne Schwabe <arne@rfc2549.org> | 2016-12-17 14:07:37 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2016-12-17 14:07:37 +0100 |
commit | bc379919437bde35eaa0a0f10315973207b96f03 (patch) | |
tree | 34f033fb937f8a2dd4701644038b6c8e4c2fdc1f /main/src | |
parent | 9f44ae471ba9e413f4d936710ce95daf497c5c07 (diff) |
Fix sorting
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java index c50d62ab..054279fa 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java @@ -344,6 +344,8 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn static class VpnProfileLRUComparator implements Comparator<VpnProfile> { + VpnProfileNameComparator nameComparator = new VpnProfileNameComparator(); + @Override public int compare(VpnProfile lhs, VpnProfile rhs) { if (lhs == rhs) @@ -356,9 +358,13 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn return 1; // Copied from Long.compare - return (lhs.mLastUsed > rhs.mLastUsed) ? -1 : ((lhs.mLastUsed == rhs.mLastUsed) ? 0 : 1); + if (lhs.mLastUsed > rhs.mLastUsed) + return -1; + if (lhs.mLastUsed < rhs.mLastUsed) + return 1; + else + return nameComparator.compare(lhs, rhs); } - } @@ -375,10 +381,10 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn Collection<VpnProfile> allvpn = getPM().getProfiles(); TreeSet<VpnProfile> sortedset; if (sortByLRU) - sortedset= new TreeSet<>(new VpnProfileLRUComparator()); + sortedset = new TreeSet<>(new VpnProfileLRUComparator()); else sortedset = new TreeSet<>(new VpnProfileNameComparator()); - + sortedset.addAll(allvpn); mArrayadapter.clear(); mArrayadapter.addAll(sortedset); @@ -419,7 +425,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn return true; } else if (itemId == MENU_IMPORT_PROFILE) { return startImportConfigFilePicker(); - } else if (itemId == MENU_CHANGE_SORTING){ + } else if (itemId == MENU_CHANGE_SORTING) { return changeSorting(); } else { return super.onOptionsItemSelected(item); |