From 5a2f692d7323f3bc7f5b2347fb8490be9057f302 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sat, 6 Jan 2018 23:45:49 -0600 Subject: TunnelManager: Sort tunnels case-insensitively The second comparator is required to allow multiple tunnels that differ only in case. Signed-off-by: Samuel Holland --- app/src/main/java/com/wireguard/android/model/TunnelManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java index 68bb541a..22bf1190 100644 --- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -13,10 +13,12 @@ import com.wireguard.android.util.ObservableSortedKeyedArrayList; import com.wireguard.config.Config; import java.util.Collections; +import java.util.Comparator; import java.util.Set; import javax.inject.Inject; +import java9.util.Comparators; import java9.util.concurrent.CompletableFuture; import java9.util.concurrent.CompletionStage; import java9.util.stream.Collectors; @@ -30,6 +32,8 @@ import java9.util.stream.StreamSupport; public final class TunnelManager { public static final String KEY_PRIMARY_TUNNEL = "primary_config"; public static final String KEY_SELECTED_TUNNEL = "selected_tunnel"; + private static final Comparator COMPARATOR = Comparators.thenComparing( + String.CASE_INSENSITIVE_ORDER, Comparators.naturalOrder()); private static final String KEY_RESTORE_ON_BOOT = "restore_on_boot"; private static final String KEY_RUNNING_TUNNELS = "enabled_configs"; private static final String TAG = TunnelManager.class.getSimpleName(); @@ -38,7 +42,7 @@ public final class TunnelManager { private final ConfigStore configStore; private final SharedPreferences preferences; private final ObservableKeyedList tunnels = - new ObservableSortedKeyedArrayList<>(); + new ObservableSortedKeyedArrayList<>(COMPARATOR); @Inject public TunnelManager(final Backend backend, final ConfigStore configStore, -- cgit v1.2.3