diff options
| author | mojganii <mojgan.jelodar@codic.se> | 2024-04-11 11:04:51 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2024-04-12 16:34:32 +0200 |
| commit | b1722ac1b2eea19d6cb3073c0662b20960858aab (patch) | |
| tree | 3f44bfad221b9c624a6f9fe5b62ecc78757225fe | |
| parent | 02e2f2e9fdeb92348e9a11c7ade43c4462ec588e (diff) | |
| download | mullvadvpn-b1722ac1b2eea19d6cb3073c0662b20960858aab.tar.xz mullvadvpn-b1722ac1b2eea19d6cb3073c0662b20960858aab.zip | |
Add alphabetical sorting for custom list locations
| -rw-r--r-- | ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift | 29 |
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 +} |
