Skip to content

Commit

Permalink
Merge branch 'add-a-new-container-view-to-wrap-the-whole-location-ios…
Browse files Browse the repository at this point in the history
…-630'
  • Loading branch information
buggmagnet committed May 13, 2024
2 parents c828a96 + 2ad27f5 commit f91ba00
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 111 deletions.
4 changes: 4 additions & 0 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@
7AA513862BC91C6B00D081A4 /* LogRotationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AA513852BC91C6B00D081A4 /* LogRotationTests.swift */; };
7AB2B6702BA1EB8C00B03E3B /* ListCustomListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB2B66E2BA1EB8C00B03E3B /* ListCustomListViewController.swift */; };
7AB2B6712BA1EB8C00B03E3B /* ListCustomListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB2B66F2BA1EB8C00B03E3B /* ListCustomListCoordinator.swift */; };
7AB3BEB52BD7A6CB00E34384 /* LocationViewControllerWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB3BEB42BD7A6CB00E34384 /* LocationViewControllerWrapper.swift */; };
7AB4CCB92B69097E006037F5 /* IPOverrideTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4CCB82B69097E006037F5 /* IPOverrideTests.swift */; };
7AB4CCBB2B691BBB006037F5 /* IPOverrideInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4CCBA2B691BBB006037F5 /* IPOverrideInteractor.swift */; };
7ABCA5B32A9349F20044A708 /* Routing.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A88DCCE2A8FABBE00D2FF0E /* Routing.framework */; };
Expand Down Expand Up @@ -1855,6 +1856,7 @@
7AA513852BC91C6B00D081A4 /* LogRotationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogRotationTests.swift; sourceTree = "<group>"; };
7AB2B66E2BA1EB8C00B03E3B /* ListCustomListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListCustomListViewController.swift; sourceTree = "<group>"; };
7AB2B66F2BA1EB8C00B03E3B /* ListCustomListCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListCustomListCoordinator.swift; sourceTree = "<group>"; };
7AB3BEB42BD7A6CB00E34384 /* LocationViewControllerWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationViewControllerWrapper.swift; sourceTree = "<group>"; };
7AB4CCB82B69097E006037F5 /* IPOverrideTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPOverrideTests.swift; sourceTree = "<group>"; };
7AB4CCBA2B691BBB006037F5 /* IPOverrideInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPOverrideInteractor.swift; sourceTree = "<group>"; };
7ABE318C2A1CDD4500DF4963 /* UIFont+Weight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Weight.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2646,6 +2648,7 @@
F050AE512B70DFC0003F4EDB /* LocationSection.swift */,
F0BE65362B9F136A005CC385 /* LocationSectionHeaderView.swift */,
5888AD86227B17950051EB06 /* LocationViewController.swift */,
7AB3BEB42BD7A6CB00E34384 /* LocationViewControllerWrapper.swift */,
);
path = SelectLocation;
sourceTree = "<group>";
Expand Down Expand Up @@ -5582,6 +5585,7 @@
063687BA28EB234F00BE7161 /* PacketTunnelTransport.swift in Sources */,
A9C342C12ACC37E30045F00E /* TunnelStatusBlockObserver.swift in Sources */,
587425C12299833500CA2045 /* RootContainerViewController.swift in Sources */,
7AB3BEB52BD7A6CB00E34384 /* LocationViewControllerWrapper.swift in Sources */,
F09D04BD2AEBB7C5003D4F89 /* OutgoingConnectionService.swift in Sources */,
58FF9FF42B07C61B00E4C97D /* AccessMethodValidationError.swift in Sources */,
5896AE84246D5889005B36CB /* CustomDateComponentsFormatting.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions ios/MullvadVPN/Classes/AccessbilityIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public enum AccessibilityIdentifier: String {
case outOfTimeView
case termsOfServiceView
case selectLocationView
case selectLocationViewWrapper
case selectLocationTableView
case settingsTableView
case vpnSettingsTableView
Expand Down
113 changes: 48 additions & 65 deletions ios/MullvadVPN/Coordinators/LocationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
navigationController
}

var locationViewController: LocationViewController? {
var locationViewControllerWrapper: LocationViewControllerWrapper? {
return navigationController.viewControllers.first {
$0 is LocationViewController
} as? LocationViewController
$0 is LocationViewControllerWrapper
} as? LocationViewControllerWrapper
}

var relayFilter: RelayFilter {
Expand All @@ -54,56 +54,25 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
}

func start() {
let locationViewController = LocationViewController(customListRepository: customListRepository)
locationViewController.delegate = self

locationViewController.didSelectRelays = { [weak self] locations in
guard let self else { return }

var relayConstraints = tunnelManager.settings.relayConstraints
relayConstraints.locations = .only(locations)

tunnelManager.updateSettings([.relayConstraints(relayConstraints)]) {
self.tunnelManager.startTunnel()
}

didFinish?(self)
}

locationViewController.navigateToFilter = { [weak self] in
guard let self else { return }

let coordinator = makeRelayFilterCoordinator(forModalPresentation: true)
coordinator.start()

presentChild(coordinator, animated: true)
}

locationViewController.didUpdateFilter = { [weak self] filter in
guard let self else { return }

var relayConstraints = tunnelManager.settings.relayConstraints
relayConstraints.filter = .only(filter)

tunnelManager.updateSettings([.relayConstraints(relayConstraints)])
}
let locationViewControllerWrapper = LocationViewControllerWrapper(
customListRepository: customListRepository,
selectedRelays: tunnelManager.settings.relayConstraints.locations.value
)
locationViewControllerWrapper.delegate = self

locationViewController.didFinish = { [weak self] in
locationViewControllerWrapper.didFinish = { [weak self] in
guard let self else { return }

didFinish?(self)
}

relayCacheTracker.addObserver(self)

if let cachedRelays = try? relayCacheTracker.getCachedRelays() {
self.cachedRelays = cachedRelays
locationViewController.setCachedRelays(cachedRelays, filter: relayFilter)
locationViewControllerWrapper.setCachedRelays(cachedRelays, filter: relayFilter)
}

locationViewController.relayLocations = tunnelManager.settings.relayConstraints.locations.value

navigationController.pushViewController(locationViewController, animated: false)
navigationController.pushViewController(locationViewControllerWrapper, animated: false)
}

private func makeRelayFilterCoordinator(forModalPresentation isModalPresentation: Bool)
Expand All @@ -118,7 +87,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {

relayFilterCoordinator.didFinish = { [weak self] coordinator, filter in
if let cachedRelays = self?.cachedRelays, let filter {
self?.locationViewController?.setCachedRelays(cachedRelays, filter: filter)
self?.locationViewControllerWrapper?.setCachedRelays(cachedRelays, filter: filter)
}

coordinator.dismiss(animated: true)
Expand All @@ -138,7 +107,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {

coordinator.didFinish = { [weak self] addCustomListCoordinator in
addCustomListCoordinator.dismiss(animated: true)
self?.locationViewController?.refreshCustomLists()
self?.locationViewControllerWrapper?.refreshCustomLists()
}

coordinator.start()
Expand All @@ -155,7 +124,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {

coordinator.didFinish = { [weak self] listCustomListCoordinator in
listCustomListCoordinator.dismiss(animated: true)
self?.locationViewController?.refreshCustomLists()
self?.locationViewControllerWrapper?.refreshCustomLists()
}

coordinator.start()
Expand All @@ -169,7 +138,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
// See showEditCustomLists() above.
extension LocationCoordinator: UIAdaptivePresentationControllerDelegate {
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
locationViewController?.refreshCustomLists()
locationViewControllerWrapper?.refreshCustomLists()
}
}

Expand All @@ -180,32 +149,50 @@ extension LocationCoordinator: RelayCacheTrackerObserver {
) {
self.cachedRelays = cachedRelays

locationViewController?.setCachedRelays(cachedRelays, filter: relayFilter)
locationViewControllerWrapper?.setCachedRelays(cachedRelays, filter: relayFilter)
}
}

extension LocationCoordinator: LocationViewControllerDelegate {
func didRequestRouteToCustomLists(_ controller: LocationViewController, nodes: [LocationNode]) {
extension LocationCoordinator: LocationViewControllerWrapperDelegate {
func didSelectRelays(relays: UserSelectedRelays) {
var relayConstraints = tunnelManager.settings.relayConstraints
relayConstraints.locations = .only(relays)

tunnelManager.updateSettings([.relayConstraints(relayConstraints)]) {
self.tunnelManager.startTunnel()
}

didFinish?(self)
}

func didUpdateFilter(filter: RelayFilter) {
var relayConstraints = tunnelManager.settings.relayConstraints
relayConstraints.filter = .only(filter)

tunnelManager.updateSettings([.relayConstraints(relayConstraints)])
}

func navigateToFilter() {
let coordinator = makeRelayFilterCoordinator(forModalPresentation: true)
coordinator.start()

presentChild(coordinator, animated: true)
}

func navigateToCustomLists(nodes: [LocationNode]) {
let actionSheet = UIAlertController(
title: NSLocalizedString(
"CUSTOM_LIST_ACTION_SHEET_TITLE",
tableName: "CustomLists",
value: "Custom lists",
comment: ""
"ACTION_SHEET_TITLE", tableName: "CustomLists", value: "Custom lists", comment: ""
),
message: nil,
preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? .alert : .actionSheet
)

actionSheet.overrideUserInterfaceStyle = .dark
actionSheet.view.tintColor = UIColor(red: 0.0, green: 0.59, blue: 1.0, alpha: 1)

let addCustomListAction = UIAlertAction(
title: NSLocalizedString(
"CUSTOM_LIST_ACTION_SHEET_ADD_LIST_BUTTON",
tableName: "CustomLists",
value: "Add new list",
comment: ""
"ACTION_SHEET_ADD_LIST_BUTTON", tableName: "CustomLists", value: "Add new list", comment: ""
),
style: .default,
handler: { [weak self] _ in
Expand All @@ -214,12 +201,10 @@ extension LocationCoordinator: LocationViewControllerDelegate {
)
addCustomListAction.accessibilityIdentifier = AccessibilityIdentifier.addNewCustomListButton
actionSheet.addAction(addCustomListAction)

let editAction = UIAlertAction(
title: NSLocalizedString(
"CUSTOM_LIST_ACTION_SHEET_EDIT_LISTS_BUTTON",
tableName: "CustomLists",
value: "Edit lists",
comment: ""
"ACTION_SHEET_EDIT_LISTS_BUTTON", tableName: "CustomLists", value: "Edit lists", comment: ""
),
style: .default,
handler: { [weak self] _ in
Expand All @@ -228,7 +213,6 @@ extension LocationCoordinator: LocationViewControllerDelegate {
)
editAction.isEnabled = !customListRepository.fetchAll().isEmpty
editAction.accessibilityIdentifier = AccessibilityIdentifier.editCustomListButton

actionSheet.addAction(editAction)

actionSheet.addAction(UIAlertAction(
Expand All @@ -238,8 +222,7 @@ extension LocationCoordinator: LocationViewControllerDelegate {
value: "Cancel",
comment: ""
),
style: .cancel,
handler: nil
style: .cancel
))

presentationContext.present(actionSheet, animated: true)
Expand Down
5 changes: 5 additions & 0 deletions ios/MullvadVPN/UI appearance/UIColor+Palette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ extension UIColor {
static let actionButtonColor = UIColor(white: 1.0, alpha: 0.8)
}

enum SegmentedControl {
static let backgroundColor = UIColor(red: 0.18, green: 0.33, blue: 0.49, alpha: 1.0)
static let selectedColor = successColor
}

// Common colors
static let primaryColor = UIColor(red: 0.16, green: 0.30, blue: 0.45, alpha: 1.0)
static let secondaryColor = UIColor(red: 0.10, green: 0.18, blue: 0.27, alpha: 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class RelayFilterView: UIView {
contentContainer.spacing = UIMetrics.FilterView.labelSpacing

addConstrainedSubviews([contentContainer]) {
contentContainer.pinEdges(.init([.top(0), .bottom(0)]), to: self)
contentContainer.pinEdges(.init([.leading(0), .trailing(0)]), to: layoutMarginsGuide)
contentContainer.pinEdges(.init([.top(4), .bottom(0)]), to: self)
contentContainer.pinEdges(.init([.leading(4), .trailing(4)]), to: layoutMarginsGuide)
}
}

Expand Down
Loading

0 comments on commit f91ba00

Please sign in to comment.