Skip to content

Commit 9c033f9

Browse files
Jon Peterssonrablador
Jon Petersson
authored andcommitted
Update logic for showing DAITA filter pill
1 parent d35866d commit 9c033f9

File tree

8 files changed

+114
-25
lines changed

8 files changed

+114
-25
lines changed

ios/MullvadVPN.xcodeproj/project.pbxproj

+1
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,7 @@
28112811
7A42DEC82A05164100B209BE /* SettingsInputCell.swift */,
28122812
58677711290976FB006F721F /* SettingsInteractor.swift */,
28132813
5867770F290975E8006F721F /* SettingsInteractorFactory.swift */,
2814+
F041BE4E2C983C2B0083EC28 /* SettingsPromptAlertItem.swift */,
28142815
58ACF64A26553C3F00ACE4B7 /* SettingsSwitchCell.swift */,
28152816
58CCA01122424D11004F3011 /* SettingsViewController.swift */,
28162817
7A27E3CA2CAE86170088BCFF /* SettingsViewModel.swift */,

ios/MullvadVPN/Coordinators/LocationCoordinator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
6464
customListRepository: customListRepository,
6565
constraints: tunnelManager.settings.relayConstraints,
6666
multihopEnabled: tunnelManager.settings.tunnelMultihopState.isEnabled,
67-
daitaEnabled: tunnelManager.settings.daita.daitaState.isEnabled,
67+
daitaSettings: tunnelManager.settings.daita,
6868
startContext: startContext
6969
)
7070
locationViewControllerWrapper.delegate = self

ios/MullvadVPN/View controllers/Alert/AlertPresenter.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import Routing
1010

1111
struct AlertPresenter {
12-
let context: any Presenting
12+
weak var context: (any Presenting)?
1313

1414
func showAlert(presentation: AlertPresentation, animated: Bool) {
15+
guard let context else { return }
16+
1517
context.applicationRouter?.presentAlert(
1618
route: .alert(presentation.id),
1719
animated: animated,
@@ -20,7 +22,7 @@ struct AlertPresenter {
2022
}
2123

2224
func dismissAlert(presentation: AlertPresentation, animated: Bool) {
23-
context.applicationRouter?.dismiss(.alert(presentation.id), animated: animated)
25+
context?.applicationRouter?.dismiss(.alert(presentation.id), animated: animated)
2426
}
2527
}
2628

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class LocationViewController: UIViewController {
2626
private var relaysWithLocation: LocationRelays?
2727
private var filter = RelayFilter()
2828
private var selectedRelays: RelaySelection
29-
private var daitaEnabled: Bool
29+
private var shouldFilterDaita: Bool
3030
weak var delegate: LocationViewControllerDelegate?
3131
var customListRepository: CustomListRepositoryProtocol
3232

@@ -35,17 +35,17 @@ final class LocationViewController: UIViewController {
3535
}
3636

3737
var filterViewShouldBeHidden: Bool {
38-
!daitaEnabled && (filter.ownership == .any) && (filter.providers == .any)
38+
!shouldFilterDaita && (filter.ownership == .any) && (filter.providers == .any)
3939
}
4040

4141
init(
4242
customListRepository: CustomListRepositoryProtocol,
4343
selectedRelays: RelaySelection,
44-
daitaEnabled: Bool = false
44+
shouldFilterDaita: Bool
4545
) {
4646
self.customListRepository = customListRepository
4747
self.selectedRelays = selectedRelays
48-
self.daitaEnabled = daitaEnabled
48+
self.shouldFilterDaita = shouldFilterDaita
4949

5050
super.init(nibName: nil, bundle: nil)
5151
}
@@ -154,7 +154,7 @@ final class LocationViewController: UIViewController {
154154
topContentView.addArrangedSubview(searchBar)
155155

156156
filterView.isHidden = filterViewShouldBeHidden
157-
filterView.setDaita(daitaEnabled)
157+
filterView.setDaita(shouldFilterDaita)
158158

159159
filterView.didUpdateFilter = { [weak self] in
160160
self?.delegate?.didUpdateFilter(filter: $0)

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ final class LocationViewControllerWrapper: UIViewController {
5252
private var selectedExit: UserSelectedRelays?
5353
private let multihopEnabled: Bool
5454
private var multihopContext: MultihopContext = .exit
55-
private let daitaEnabled: Bool
55+
private let daitaSettings: DAITASettings
5656

5757
weak var delegate: LocationViewControllerWrapperDelegate?
5858

5959
init(
6060
customListRepository: CustomListRepositoryProtocol,
6161
constraints: RelayConstraints,
6262
multihopEnabled: Bool,
63-
daitaEnabled: Bool,
63+
daitaSettings: DAITASettings,
6464
startContext: MultihopContext
6565
) {
6666
self.multihopEnabled = multihopEnabled
67-
self.daitaEnabled = daitaEnabled
67+
self.daitaSettings = daitaSettings
6868
multihopContext = startContext
6969

7070
selectedEntry = constraints.entryLocations.value
@@ -73,13 +73,16 @@ final class LocationViewControllerWrapper: UIViewController {
7373
entryLocationViewController = LocationViewController(
7474
customListRepository: customListRepository,
7575
selectedRelays: RelaySelection(),
76-
daitaEnabled: multihopEnabled && daitaEnabled
76+
shouldFilterDaita: daitaSettings.daitaState.isEnabled
77+
&& daitaSettings.directOnlyState.isEnabled
7778
)
7879

7980
exitLocationViewController = LocationViewController(
8081
customListRepository: customListRepository,
8182
selectedRelays: RelaySelection(),
82-
daitaEnabled: !multihopEnabled && daitaEnabled
83+
shouldFilterDaita: !multihopEnabled
84+
&& daitaSettings.daitaState.isEnabled
85+
&& daitaSettings.directOnlyState.isEnabled
8386
)
8487

8588
super.init(nibName: nil, bundle: nil)
@@ -109,7 +112,7 @@ final class LocationViewControllerWrapper: UIViewController {
109112

110113
func setRelaysWithLocation(_ relaysWithLocation: LocationRelays, filter: RelayFilter) {
111114
var daitaFilteredRelays = relaysWithLocation
112-
if daitaEnabled {
115+
if daitaSettings.daitaState.isEnabled && daitaSettings.directOnlyState.isEnabled {
113116
daitaFilteredRelays.relays = relaysWithLocation.relays.filter { relay in
114117
relay.daita == true
115118
}

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

+56-9
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
2525
}
2626
}
2727

28-
private enum HeaderFooterReuseIdentifier: String, CaseIterable {
28+
private enum HeaderFooterReuseIdentifier: String, CaseIterable, HeaderFooterIdentifierProtocol {
29+
case primary
2930
case spacer
3031

31-
var reusableViewClass: AnyClass {
32-
EmptyTableViewHeaderFooterView.self
32+
var headerFooterClass: AnyClass {
33+
switch self {
34+
case .primary:
35+
UITableViewHeaderFooterView.self
36+
case .spacer:
37+
EmptyTableViewHeaderFooterView.self
38+
}
3339
}
3440
}
3541

@@ -38,6 +44,20 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
3844
case main
3945
case version
4046
case problemReport
47+
48+
var sectionFooter: String? {
49+
switch self {
50+
case .daita:
51+
NSLocalizedString(
52+
"SETTINGS_DAITA_SECTION_FOOTER",
53+
tableName: "Settings",
54+
value: "Makes it possible to use DAITA with any server and is automatically enabled.",
55+
comment: ""
56+
)
57+
default:
58+
nil
59+
}
60+
}
4161
}
4262

4363
enum Item: String {
@@ -130,16 +150,43 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
130150
)
131151
}
132152

133-
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
134-
nil
153+
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
154+
let sectionIdentifier = snapshot().sectionIdentifiers[section]
155+
156+
return switch sectionIdentifier {
157+
case .main:
158+
0
159+
case .daita, .version, .problemReport:
160+
UITableView.automaticDimension
161+
}
135162
}
136163

137-
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
138-
return UIMetrics.TableView.sectionSpacing
164+
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
165+
let sectionIdentifier = snapshot().sectionIdentifiers[section]
166+
guard let sectionFooterText = sectionIdentifier.sectionFooter else { return nil }
167+
168+
guard let headerView = tableView
169+
.dequeueReusableView(withIdentifier: HeaderFooterReuseIdentifier.primary)
170+
else { return nil }
171+
172+
var contentConfiguration = UIListContentConfiguration.mullvadGroupedFooter(tableStyle: .plain)
173+
contentConfiguration.text = sectionFooterText
174+
175+
headerView.contentConfiguration = contentConfiguration
176+
// headerView.directionalLayoutMargins = UIMetrics.SettingsCell.apiAccessInsetLayoutMargins
177+
178+
return headerView
139179
}
140180

141181
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
142-
0
182+
let sectionIdentifier = snapshot().sectionIdentifiers[section]
183+
184+
return switch sectionIdentifier {
185+
case .daita:
186+
UITableView.automaticDimension
187+
case .main, .version, .problemReport:
188+
0
189+
}
143190
}
144191

145192
// MARK: - Private
@@ -154,7 +201,7 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
154201

155202
HeaderFooterReuseIdentifier.allCases.forEach { reuseIdentifier in
156203
tableView?.register(
157-
reuseIdentifier.reusableViewClass,
204+
reuseIdentifier.headerFooterClass,
158205
forHeaderFooterViewReuseIdentifier: reuseIdentifier.rawValue
159206
)
160207
}

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ final class SettingsInteractor {
4646
var tunnelSettings = tunnelSettings
4747
tunnelSettings.daita = settings
4848

49-
guard let selectedRelays = try? tunnelManager.selectRelays(tunnelSettings: tunnelSettings) else { return nil }
50-
return tunnelSettings.tunnelMultihopState.isEnabled ? .multihop : .singlehop
49+
// Return error if no relays could be selected.
50+
guard (try? tunnelManager.selectRelays(tunnelSettings: tunnelSettings)) != nil else {
51+
return tunnelSettings.tunnelMultihopState.isEnabled ? .multihop : .singlehop
52+
}
53+
54+
return nil
5155
}
5256
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// SettingsPromptAlertItem.swift
3+
// MullvadVPN
4+
//
5+
// Created by Mojgan on 2024-09-16.
6+
// Copyright © 2024 Mullvad VPN AB. All rights reserved.
7+
//
8+
9+
import Foundation
10+
enum DAITASettingsPromptItem: CustomStringConvertible {
11+
case daitaSettingIncompatibleWithSinglehop
12+
case daitaSettingIncompatibleWithMultihop
13+
14+
var description: String {
15+
switch self {
16+
case .daitaSettingIncompatibleWithSinglehop:
17+
"""
18+
DAITA isn’t available on the current server. After enabling, please go to the Switch \
19+
location view and select a location that supports DAITA.
20+
Attention: Since this increases your total network traffic, be cautious if you have a \
21+
limited data plan. It can also negatively impact your network speed and battery usage.
22+
"""
23+
case .daitaSettingIncompatibleWithMultihop:
24+
"""
25+
DAITA isn’t available on the current entry server. After enabling, please go to the Switch \
26+
location view and select an entry location that supports DAITA.
27+
Attention: Since this increases your total network traffic, be cautious if you have a \
28+
limited data plan. It can also negatively impact your network speed and battery usage.
29+
"""
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)