Skip to content

Commit c23a91c

Browse files
author
Jon Petersson
committed
Update view model when switching between entry and exit location
1 parent bd71954 commit c23a91c

11 files changed

+261
-88
lines changed

ios/MullvadVPN.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@
491491
7A3353912AAA014400F0A71C /* SimulatorVPNConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3353902AAA014400F0A71C /* SimulatorVPNConnection.swift */; };
492492
7A3353932AAA089000F0A71C /* SimulatorTunnelInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3353922AAA089000F0A71C /* SimulatorTunnelInfo.swift */; };
493493
7A3353972AAA0F8600F0A71C /* OperationBlockObserverSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3353962AAA0F8600F0A71C /* OperationBlockObserverSupport.swift */; };
494+
7A3EFAAB2BDFDAE800318736 /* RelaySelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3EFAAA2BDFDAE800318736 /* RelaySelection.swift */; };
494495
7A3FD1B52AD4465A0042BEA6 /* AppMessageHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3FD1B42AD4465A0042BEA6 /* AppMessageHandlerTests.swift */; };
495496
7A3FD1B72AD54ABD0042BEA6 /* AnyTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BDEB982A98F4ED00F578F2 /* AnyTransport.swift */; };
496497
7A3FD1B82AD54AE60042BEA6 /* TimeServerProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BDEB9A2A98F58600F578F2 /* TimeServerProxy.swift */; };
@@ -1841,6 +1842,7 @@
18411842
7A3353902AAA014400F0A71C /* SimulatorVPNConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorVPNConnection.swift; sourceTree = "<group>"; };
18421843
7A3353922AAA089000F0A71C /* SimulatorTunnelInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorTunnelInfo.swift; sourceTree = "<group>"; };
18431844
7A3353962AAA0F8600F0A71C /* OperationBlockObserverSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationBlockObserverSupport.swift; sourceTree = "<group>"; };
1845+
7A3EFAAA2BDFDAE800318736 /* RelaySelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaySelection.swift; sourceTree = "<group>"; };
18441846
7A3FD1B42AD4465A0042BEA6 /* AppMessageHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppMessageHandlerTests.swift; sourceTree = "<group>"; };
18451847
7A42DEC82A05164100B209BE /* SettingsInputCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInputCell.swift; sourceTree = "<group>"; };
18461848
7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotTests.swift; sourceTree = "<group>"; };
@@ -2768,6 +2770,7 @@
27682770
F0BE65362B9F136A005CC385 /* LocationSectionHeaderView.swift */,
27692771
5888AD86227B17950051EB06 /* LocationViewController.swift */,
27702772
7AB3BEB42BD7A6CB00E34384 /* LocationViewControllerWrapper.swift */,
2773+
7A3EFAAA2BDFDAE800318736 /* RelaySelection.swift */,
27712774
);
27722775
path = SelectLocation;
27732776
sourceTree = "<group>";
@@ -5774,6 +5777,7 @@
57745777
5878F50029CDA742003D4BE2 /* UIView+AutoLayoutBuilder.swift in Sources */,
57755778
7A28826D2BAAC9DE00FD9F20 /* IPOverrideHeaderView.swift in Sources */,
57765779
A98502032B627B120061901E /* LocalNetworkProbe.swift in Sources */,
5780+
7A3EFAAB2BDFDAE800318736 /* RelaySelection.swift in Sources */,
57775781
583FE01029C0F532006E85F9 /* CustomSplitViewController.swift in Sources */,
57785782
7A6F2FA92AFD0842006D0856 /* CustomDNSDataSource.swift in Sources */,
57795783
58EF580B25D69D7A00AEBA94 /* ProblemReportSubmissionOverlayView.swift in Sources */,

ios/MullvadVPN/Coordinators/CustomLists/ListCustomListCoordinator.swift

+30-13
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,25 @@ class ListCustomListCoordinator: Coordinator, Presentable, Presenting {
6060

6161
coordinator.didFinish = { [weak self] editCustomListCoordinator, action, list in
6262
guard let self else { return }
63+
6364
popToList()
6465
editCustomListCoordinator.removeFromParent()
65-
self.updateRelayConstraints(for: action, in: list)
66+
67+
var relayConstraints = tunnelManager.settings.relayConstraints
68+
relayConstraints.entryLocations = self.updateRelayConstraint(
69+
relayConstraints.entryLocations,
70+
for: action,
71+
in: list
72+
)
73+
relayConstraints.exitLocations = self.updateRelayConstraint(
74+
relayConstraints.exitLocations,
75+
for: action,
76+
in: list
77+
)
78+
79+
tunnelManager.updateSettings([.relayConstraints(relayConstraints)]) { [weak self] in
80+
self?.tunnelManager.reconnectTunnel(selectNewRelay: true)
81+
}
6682
}
6783

6884
coordinator.didCancel = { [weak self] editCustomListCoordinator in
@@ -75,38 +91,39 @@ class ListCustomListCoordinator: Coordinator, Presentable, Presenting {
7591
addChild(coordinator)
7692
}
7793

78-
private func updateRelayConstraints(for action: EditCustomListCoordinator.FinishAction, in list: CustomList) {
79-
var relayConstraints = tunnelManager.settings.relayConstraints
94+
private func updateRelayConstraint(
95+
_ relayConstraint: RelayConstraint<UserSelectedRelays>,
96+
for action: EditCustomListCoordinator.FinishAction,
97+
in list: CustomList
98+
) -> RelayConstraint<UserSelectedRelays> {
99+
var relayConstraint = relayConstraint
80100

81-
guard let customListSelection = relayConstraints.exitLocations.value?.customListSelection,
101+
guard let customListSelection = relayConstraint.value?.customListSelection,
82102
customListSelection.listId == list.id
83-
else { return }
103+
else { return relayConstraint }
84104

85105
switch action {
86106
case .save:
87-
// TODO: - Add entry locations
88107
if customListSelection.isList {
89108
let selectedRelays = UserSelectedRelays(
90109
locations: list.locations,
91110
customListSelection: UserSelectedRelays.CustomListSelection(listId: list.id, isList: true)
92111
)
93-
relayConstraints.exitLocations = .only(selectedRelays)
112+
relayConstraint = .only(selectedRelays)
94113
} else {
95114
let selectedConstraintIsRemovedFromList = list.locations.filter {
96-
relayConstraints.exitLocations.value?.locations.contains($0) ?? false
115+
relayConstraint.value?.locations.contains($0) ?? false
97116
}.isEmpty
98117

99118
if selectedConstraintIsRemovedFromList {
100-
relayConstraints.exitLocations = .only(UserSelectedRelays(locations: []))
119+
relayConstraint = .only(UserSelectedRelays(locations: []))
101120
}
102121
}
103122
case .delete:
104-
relayConstraints.exitLocations = .only(UserSelectedRelays(locations: []))
123+
relayConstraint = .only(UserSelectedRelays(locations: []))
105124
}
106125

107-
tunnelManager.updateSettings([.relayConstraints(relayConstraints)]) { [weak self] in
108-
self?.tunnelManager.reconnectTunnel(selectNewRelay: true)
109-
}
126+
return relayConstraint
110127
}
111128

112129
private func popToList() {

ios/MullvadVPN/Coordinators/LocationCoordinator.swift

+11-5
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
5454
}
5555

5656
func start() {
57-
// TODO: - the location should be defined whether it's Entry or Exit location
5857
let locationViewControllerWrapper = LocationViewControllerWrapper(
5958
customListRepository: customListRepository,
60-
selectedRelays: tunnelManager.settings.relayConstraints.exitLocations.value
59+
constraints: tunnelManager.settings.relayConstraints
6160
)
6261
locationViewControllerWrapper.delegate = self
6362

@@ -155,15 +154,22 @@ extension LocationCoordinator: RelayCacheTrackerObserver {
155154
}
156155

157156
extension LocationCoordinator: LocationViewControllerWrapperDelegate {
158-
func didSelectRelays(relays: UserSelectedRelays) {
157+
func didSelectEntryRelays(relays: UserSelectedRelays) {
159158
var relayConstraints = tunnelManager.settings.relayConstraints
160-
relayConstraints.exitLocations = .only(relays)
159+
relayConstraints.entryLocations = .only(relays)
161160

162161
tunnelManager.updateSettings([.relayConstraints(relayConstraints)]) {
163162
self.tunnelManager.startTunnel()
164163
}
164+
}
165+
166+
func didSelectExitRelays(relays: UserSelectedRelays) {
167+
var relayConstraints = tunnelManager.settings.relayConstraints
168+
relayConstraints.exitLocations = .only(relays)
165169

166-
didFinish?(self)
170+
tunnelManager.updateSettings([.relayConstraints(relayConstraints)]) {
171+
self.tunnelManager.startTunnel()
172+
}
167173
}
168174

169175
func didUpdateFilter(filter: RelayFilter) {

ios/MullvadVPN/UI appearance/UIColor+Palette.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extension UIColor {
137137
}
138138

139139
enum SegmentedControl {
140-
static let backgroundColor = UIColor(red: 0.18, green: 0.33, blue: 0.49, alpha: 1.0)
140+
static let backgroundColor = UIColor(red: 0.14, green: 0.25, blue: 0.38, alpha: 1.0)
141141
static let selectedColor = successColor
142142
}
143143

ios/MullvadVPN/View controllers/RelayFilter/RelayFilterView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class RelayFilterView: UIView {
9494
contentContainer.spacing = UIMetrics.FilterView.labelSpacing
9595

9696
addConstrainedSubviews([contentContainer]) {
97-
contentContainer.pinEdges(.init([.top(4), .bottom(0)]), to: self)
97+
contentContainer.pinEdges(.init([.top(7), .bottom(0)]), to: self)
9898
contentContainer.pinEdges(.init([.leading(4), .trailing(4)]), to: layoutMarginsGuide)
9999
}
100100
}

ios/MullvadVPN/View controllers/SelectLocation/LocationCell.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class LocationCell: UITableViewCell {
7272

7373
var isDisabled = false {
7474
didSet {
75-
updateDisabled()
75+
updateDisabled(isDisabled)
7676
updateBackgroundColor()
7777
updateStatusIndicatorColor()
7878
}
@@ -150,7 +150,7 @@ class LocationCell: UITableViewCell {
150150

151151
updateCollapseImage()
152152
updateAccessibilityCustomActions()
153-
updateDisabled()
153+
updateDisabled(isDisabled)
154154
updateBackgroundColor()
155155
setLayoutMargins()
156156

@@ -207,7 +207,7 @@ class LocationCell: UITableViewCell {
207207
statusIndicator.backgroundColor = statusIndicatorColor()
208208
}
209209

210-
private func updateDisabled() {
210+
private func updateDisabled(_ isDisabled: Bool) {
211211
locationLabel.alpha = isDisabled ? 0.2 : 1
212212
collapseButton.alpha = isDisabled ? 0.2 : 1
213213

@@ -339,9 +339,17 @@ extension LocationCell {
339339
}
340340
}
341341

342+
setExcludedRelayTitle(item.excludedRelayTitle)
342343
setBehavior(behavior)
343344
}
344345

346+
func setExcludedRelayTitle(_ title: String?) {
347+
if let title {
348+
locationLabel.text! += " (\(title))"
349+
updateDisabled(true)
350+
}
351+
}
352+
345353
private func setBehavior(_ newBehavior: LocationCellBehavior) {
346354
self.behavior = newBehavior
347355
updateLeadingImage()

ios/MullvadVPN/View controllers/SelectLocation/LocationCellViewModel.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ struct LocationCellViewModel: Hashable {
1313
let node: LocationNode
1414
var indentationLevel = 0
1515
var isSelected = false
16+
var excludedRelayTitle: String?
1617

1718
func hash(into hasher: inout Hasher) {
1819
hasher.combine(node)
1920
hasher.combine(node.children.count)
2021
hasher.combine(section)
2122
hasher.combine(isSelected)
22-
hasher.combine(indentationLevel)
2323
}
2424

2525
static func == (lhs: Self, rhs: Self) -> Bool {
2626
lhs.node == rhs.node &&
2727
lhs.node.children.count == rhs.node.children.count &&
2828
lhs.section == rhs.section &&
29-
lhs.isSelected == rhs.isSelected &&
30-
lhs.indentationLevel == rhs.indentationLevel
29+
lhs.isSelected == rhs.isSelected
3130
}
3231
}
3332

0 commit comments

Comments
 (0)