summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBug Magnet <marco.nikic@mullvad.net>2024-04-12 16:35:30 +0200
committerBug Magnet <marco.nikic@mullvad.net>2024-04-12 16:35:30 +0200
commitbdcce0b74fc041d61f9d2e224efd8e6eadf32dea (patch)
tree3f44bfad221b9c624a6f9fe5b62ecc78757225fe
parent02e2f2e9fdeb92348e9a11c7ade43c4462ec588e (diff)
parentb1722ac1b2eea19d6cb3073c0662b20960858aab (diff)
downloadmullvadvpn-bdcce0b74fc041d61f9d2e224efd8e6eadf32dea.tar.xz
mullvadvpn-bdcce0b74fc041d61f9d2e224efd8e6eadf32dea.zip
Merge branch 'alphabetical-sorting-for-custom-list-locations-ios-604'
-rw-r--r--ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift29
1 files changed, 29 insertions, 0 deletions
diff --git a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
index 66e4ddbb5a..e92a8bda8d 100644
--- a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
+++ b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
@@ -8,6 +8,7 @@
import Foundation
import MullvadSettings
+import MullvadTypes
struct CustomListLocationNodeBuilder {
let customList: CustomList
@@ -18,6 +19,7 @@ struct CustomListLocationNodeBuilder {
name: customList.name,
code: customList.name.lowercased(),
locations: customList.locations,
+ isActive: !customList.locations.isEmpty,
customList: customList
)
@@ -44,6 +46,33 @@ struct CustomListLocationNodeBuilder {
.copy(withParent: listNode)
}
}
+
+ listNode.sort()
return listNode
}
}
+
+private extension CustomListLocationNode {
+ func sort() {
+ let sortedChildren = Dictionary(grouping: children, by: {
+ return switch RelayLocation(dashSeparatedString: $0.code)! {
+ case .country:
+ LocationGroup.country
+ case .city:
+ LocationGroup.city
+ case .hostname:
+ LocationGroup.host
+ }
+ })
+ .sorted(by: { $0.key < $1.key })
+ .reduce([]) {
+ return $0 + $1.value.sorted(by: { $0.name < $1.name })
+ }
+
+ children = sortedChildren
+ }
+}
+
+private enum LocationGroup: CaseIterable, Comparable {
+ case country, city, host
+}