summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormojganii <mojgan.jelodar@codic.se>2024-03-15 11:43:06 +0100
committerBug Magnet <marco.nikic@mullvad.net>2024-04-05 09:34:32 +0200
commitad89a992ba49996eee751b7baa257bab0daa0517 (patch)
tree6690767f40d525ca5cb8c5965081091ace600fcf
parent5da5419f74a18493bc4f5384c9bfa3c44abd46e2 (diff)
downloadmullvadvpn-ad89a992ba49996eee751b7baa257bab0daa0517.tar.xz
mullvadvpn-ad89a992ba49996eee751b7baa257bab0daa0517.zip
Create LocationNode from CustomList
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj6
-rw-r--r--ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift49
2 files changed, 55 insertions, 0 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index af62482d12..41411f85d4 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -826,6 +826,8 @@
F028A56A2A34D4E700C0CAA3 /* RedeemVoucherViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F028A5692A34D4E700C0CAA3 /* RedeemVoucherViewController.swift */; };
F028A56C2A34D8E600C0CAA3 /* AddCreditSucceededViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F028A56B2A34D8E600C0CAA3 /* AddCreditSucceededViewController.swift */; };
F03580252A13842C00E5DAFD /* IncreasedHitButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = F03580242A13842C00E5DAFD /* IncreasedHitButton.swift */; };
+ F04413612BA45CD70018A6EE /* CustomListLocationNodeBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F04413602BA45CD70018A6EE /* CustomListLocationNodeBuilder.swift */; };
+ F04413622BA45CE30018A6EE /* CustomListLocationNodeBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F04413602BA45CD70018A6EE /* CustomListLocationNodeBuilder.swift */; };
F04F95A12B21D24400431E08 /* shadowsocks.h in Headers */ = {isa = PBXBuildFile; fileRef = F04F95A02B21D24400431E08 /* shadowsocks.h */; settings = {ATTRIBUTES = (Private, ); }; };
F04FBE612A8379EE009278D7 /* AppPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = F04FBE602A8379EE009278D7 /* AppPreferences.swift */; };
F050AE4E2B70D7F8003F4EDB /* LocationCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE4D2B70D7F8003F4EDB /* LocationCellViewModel.swift */; };
@@ -1980,6 +1982,7 @@
F028A5692A34D4E700C0CAA3 /* RedeemVoucherViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedeemVoucherViewController.swift; sourceTree = "<group>"; };
F028A56B2A34D8E600C0CAA3 /* AddCreditSucceededViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddCreditSucceededViewController.swift; sourceTree = "<group>"; };
F03580242A13842C00E5DAFD /* IncreasedHitButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IncreasedHitButton.swift; sourceTree = "<group>"; };
+ F04413602BA45CD70018A6EE /* CustomListLocationNodeBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomListLocationNodeBuilder.swift; sourceTree = "<group>"; };
F04F95A02B21D24400431E08 /* shadowsocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shadowsocks.h; sourceTree = "<group>"; };
F04FBE602A8379EE009278D7 /* AppPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppPreferences.swift; sourceTree = "<group>"; };
F050AE4D2B70D7F8003F4EDB /* LocationCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationCellViewModel.swift; sourceTree = "<group>"; };
@@ -2430,6 +2433,7 @@
isa = PBXGroup;
children = (
F050AE5F2B73A41E003F4EDB /* AllLocationDataSource.swift */,
+ F04413602BA45CD70018A6EE /* CustomListLocationNodeBuilder.swift */,
F050AE612B74DBAC003F4EDB /* CustomListsDataSource.swift */,
F0A92B3B2B8E44F900DC7B37 /* InMemoryCustomListRepository.swift */,
5888AD82227B11080051EB06 /* LocationCell.swift */,
@@ -4951,6 +4955,7 @@
A9A5FA2D2ACB05160083449F /* DurationTests.swift in Sources */,
A9A5FA2E2ACB05160083449F /* FileCacheTests.swift in Sources */,
A9A5FA2F2ACB05160083449F /* FixedWidthIntegerArithmeticsTests.swift in Sources */,
+ F04413622BA45CE30018A6EE /* CustomListLocationNodeBuilder.swift in Sources */,
A9A5FA302ACB05160083449F /* InputTextFormatterTests.swift in Sources */,
F0B0E6972AFE6E7E001DC66B /* XCTest+Async.swift in Sources */,
449EB9FF2B95FF2500DFA4EB /* AccountMock.swift in Sources */,
@@ -5267,6 +5272,7 @@
7A28826A2BA8336600FD9F20 /* VPNSettingsCoordinator.swift in Sources */,
7A6389DE2B7E3BD6008E77E1 /* CustomListItemIdentifier.swift in Sources */,
58C76A082A33850E00100D75 /* ApplicationTarget.swift in Sources */,
+ F04413612BA45CD70018A6EE /* CustomListLocationNodeBuilder.swift in Sources */,
58CEB3042AFD36CE00E6E088 /* SwitchCellContentView.swift in Sources */,
F07BF2622A26279100042943 /* RedeemVoucherOperation.swift in Sources */,
585E820327F3285E00939F0E /* SendStoreReceiptOperation.swift in Sources */,
diff --git a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
new file mode 100644
index 0000000000..66e4ddbb5a
--- /dev/null
+++ b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
@@ -0,0 +1,49 @@
+//
+// CustomListLocationNodeBuilder.swift
+// MullvadVPN
+//
+// Created by Mojgan on 2024-03-14.
+// Copyright © 2024 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import MullvadSettings
+
+struct CustomListLocationNodeBuilder {
+ let customList: CustomList
+ let allLocations: [LocationNode]
+
+ var customListLocationNode: CustomListLocationNode {
+ let listNode = CustomListLocationNode(
+ name: customList.name,
+ code: customList.name.lowercased(),
+ locations: customList.locations,
+ customList: customList
+ )
+
+ listNode.children = listNode.locations.compactMap { location in
+ let rootNode = RootLocationNode(children: allLocations)
+
+ return switch location {
+ case let .country(countryCode):
+ rootNode
+ .countryFor(code: countryCode)?
+ .copy(withParent: listNode)
+
+ case let .city(countryCode, cityCode):
+ rootNode
+ .countryFor(code: countryCode)?
+ .cityFor(codes: [countryCode, cityCode])?
+ .copy(withParent: listNode)
+
+ case let .hostname(countryCode, cityCode, hostCode):
+ rootNode
+ .countryFor(code: countryCode)?
+ .cityFor(codes: [countryCode, cityCode])?
+ .hostFor(code: hostCode)?
+ .copy(withParent: listNode)
+ }
+ }
+ return listNode
+ }
+}