Skip to content

Commit 3c410d0

Browse files
committed
Add trailing status indicators for daita and multihop cells
1 parent b3d61b2 commit 3c410d0

File tree

6 files changed

+40
-45
lines changed

6 files changed

+40
-45
lines changed

ios/MullvadVPN/View controllers/Settings/SettingsCellFactory.swift

+16-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@ final class SettingsCellFactory: CellFactoryProtocol {
111111
value: "DAITA",
112112
comment: ""
113113
)
114-
cell.detailTitleLabel.text = nil
114+
115+
cell.detailTitleLabel.text = NSLocalizedString(
116+
"DAITA_CELL_DETAIL_LABEL",
117+
tableName: "Settings",
118+
value: viewModel.daitaSettings.daitaState.isEnabled ? "On" : "Off",
119+
comment: ""
120+
)
121+
115122
cell.accessibilityIdentifier = item.accessibilityIdentifier
116123
cell.disclosureType = .chevron
117124

@@ -124,7 +131,14 @@ final class SettingsCellFactory: CellFactoryProtocol {
124131
value: "Multihop",
125132
comment: ""
126133
)
127-
cell.detailTitleLabel.text = nil
134+
135+
cell.detailTitleLabel.text = NSLocalizedString(
136+
"MULTIHOP_CELL_DETAIL_LABEL",
137+
tableName: "Settings",
138+
value: viewModel.multihopState.isEnabled ? "On" : "Off",
139+
comment: ""
140+
)
141+
128142
cell.accessibilityIdentifier = item.accessibilityIdentifier
129143
cell.disclosureType = .chevron
130144
}

ios/MullvadVPN/View controllers/Settings/SettingsDataSource.swift

+8-6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
104104
storedAccountData = interactor.deviceState.accountData
105105
}
106106

107+
func reload(from tunnelSettings: LatestTunnelSettings) {
108+
settingsCellFactory.viewModel = SettingsViewModel(from: tunnelSettings)
109+
110+
var snapshot = snapshot()
111+
snapshot.reconfigureItems(snapshot.itemIdentifiers)
112+
apply(snapshot, animatingDifferences: false)
113+
}
114+
107115
// MARK: - UITableViewDelegate
108116

109117
func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
@@ -171,10 +179,4 @@ extension SettingsDataSource: SettingsCellEventHandler {
171179
func showInfo(for button: SettingsInfoButtonItem) {
172180
delegate?.showInfo(for: button)
173181
}
174-
175-
private func reloadItem(_ item: Item) {
176-
var snapshot = snapshot()
177-
snapshot.reloadItems([item])
178-
apply(snapshot, animatingDifferences: false)
179-
}
180182
}

ios/MullvadVPN/View controllers/Settings/SettingsInteractor.swift

+9-32
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class SettingsInteractor {
1515
private var tunnelObserver: TunnelObserver?
1616

1717
var didUpdateDeviceState: ((DeviceState) -> Void)?
18+
var didUpdateTunnelSettings: ((LatestTunnelSettings) -> Void)?
1819

1920
var tunnelSettings: LatestTunnelSettings {
2021
tunnelManager.settings
@@ -28,41 +29,17 @@ final class SettingsInteractor {
2829
self.tunnelManager = tunnelManager
2930

3031
let tunnelObserver =
31-
TunnelBlockObserver(didUpdateDeviceState: { [weak self] _, deviceState, _ in
32-
self?.didUpdateDeviceState?(deviceState)
33-
})
32+
TunnelBlockObserver(
33+
didUpdateDeviceState: { [weak self] _, deviceState, _ in
34+
self?.didUpdateDeviceState?(deviceState)
35+
},
36+
didUpdateTunnelSettings: { [weak self] _, settings in
37+
self?.didUpdateTunnelSettings?(settings)
38+
}
39+
)
3440

3541
tunnelManager.addObserver(tunnelObserver)
3642

3743
self.tunnelObserver = tunnelObserver
3844
}
39-
40-
func updateDAITASettings(_ settings: DAITASettings) {
41-
tunnelManager.updateSettings([.daita(settings)])
42-
}
43-
44-
func evaluateDaitaSettingsCompatibility(_ settings: DAITASettings) -> DAITASettingsCompatibilityError? {
45-
guard settings.daitaState.isEnabled else { return nil }
46-
47-
var tunnelSettings = tunnelSettings
48-
tunnelSettings.daita = settings
49-
50-
var compatibilityError: DAITASettingsCompatibilityError?
51-
52-
do {
53-
_ = try tunnelManager.selectRelays(tunnelSettings: tunnelSettings)
54-
} catch let error as NoRelaysSatisfyingConstraintsError where error.reason == .noDaitaRelaysFound {
55-
// Return error if no relays could be selected due to DAITA constraints.
56-
compatibilityError = tunnelSettings.tunnelMultihopState.isEnabled ? .multihop : .singlehop
57-
} catch _ as NoRelaysSatisfyingConstraintsError {
58-
// Even if the constraints error is not DAITA specific, if both DAITA and Direct only are enabled,
59-
// we should return a DAITA related error since the current settings would have resulted in the
60-
// relay selector not being able to select a DAITA relay anyway.
61-
if settings.isDirectOnly {
62-
compatibilityError = tunnelSettings.tunnelMultihopState.isEnabled ? .multihop : .singlehop
63-
}
64-
} catch {}
65-
66-
return compatibilityError
67-
}
6845
}

ios/MullvadVPN/View controllers/Settings/SettingsViewController.swift

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class SettingsViewController: UITableViewController {
6969

7070
dataSource = SettingsDataSource(tableView: tableView, interactor: interactor)
7171
dataSource?.delegate = self
72+
73+
interactor.didUpdateTunnelSettings = { [weak self] newSettings in
74+
self?.dataSource?.reload(from: newSettings)
75+
}
7276
}
7377
}
7478

ios/MullvadVPN/View controllers/Settings/SettingsViewModel.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import MullvadSettings
1010

1111
struct SettingsViewModel {
1212
private(set) var daitaSettings: DAITASettings
13-
14-
mutating func setDAITASettings(_ newSettings: DAITASettings) {
15-
daitaSettings = newSettings
16-
}
13+
private(set) var multihopState: MultihopState
1714

1815
init(from tunnelSettings: LatestTunnelSettings = LatestTunnelSettings()) {
1916
daitaSettings = tunnelSettings.daita
17+
multihopState = tunnelSettings.tunnelMultihopState
2018
}
2119
}

ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,4 @@ struct SingleChoiceList<Value>: View where Value: Equatable {
411411
)
412412
}
413413
}
414-
}
414+
} // swiftlint:disable:this file_length

0 commit comments

Comments
 (0)