Skip to content

Commit

Permalink
Update logic for showing DAITA filter pill
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson authored and rablador committed Oct 14, 2024
1 parent d35866d commit 3feb1df
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 21 deletions.
1 change: 1 addition & 0 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,7 @@
7A42DEC82A05164100B209BE /* SettingsInputCell.swift */,
58677711290976FB006F721F /* SettingsInteractor.swift */,
5867770F290975E8006F721F /* SettingsInteractorFactory.swift */,
F041BE4E2C983C2B0083EC28 /* SettingsPromptAlertItem.swift */,
58ACF64A26553C3F00ACE4B7 /* SettingsSwitchCell.swift */,
58CCA01122424D11004F3011 /* SettingsViewController.swift */,
7A27E3CA2CAE86170088BCFF /* SettingsViewModel.swift */,
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Coordinators/LocationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
customListRepository: customListRepository,
constraints: tunnelManager.settings.relayConstraints,
multihopEnabled: tunnelManager.settings.tunnelMultihopState.isEnabled,
daitaEnabled: tunnelManager.settings.daita.daitaState.isEnabled,
daitaSettings: tunnelManager.settings.daita,
startContext: startContext
)
locationViewControllerWrapper.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class LocationViewController: UIViewController {
private var relaysWithLocation: LocationRelays?
private var filter = RelayFilter()
private var selectedRelays: RelaySelection
private var daitaEnabled: Bool
private var shouldFilterDaita: Bool
weak var delegate: LocationViewControllerDelegate?
var customListRepository: CustomListRepositoryProtocol

Expand All @@ -35,17 +35,17 @@ final class LocationViewController: UIViewController {
}

var filterViewShouldBeHidden: Bool {
!daitaEnabled && (filter.ownership == .any) && (filter.providers == .any)
!shouldFilterDaita && (filter.ownership == .any) && (filter.providers == .any)
}

init(
customListRepository: CustomListRepositoryProtocol,
selectedRelays: RelaySelection,
daitaEnabled: Bool = false
shouldFilterDaita: Bool
) {
self.customListRepository = customListRepository
self.selectedRelays = selectedRelays
self.daitaEnabled = daitaEnabled
self.shouldFilterDaita = shouldFilterDaita

super.init(nibName: nil, bundle: nil)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ final class LocationViewController: UIViewController {
topContentView.addArrangedSubview(searchBar)

filterView.isHidden = filterViewShouldBeHidden
filterView.setDaita(daitaEnabled)
filterView.setDaita(shouldFilterDaita)

filterView.didUpdateFilter = { [weak self] in
self?.delegate?.didUpdateFilter(filter: $0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ final class LocationViewControllerWrapper: UIViewController {
private var selectedExit: UserSelectedRelays?
private let multihopEnabled: Bool
private var multihopContext: MultihopContext = .exit
private let daitaEnabled: Bool
private let daitaSettings: DAITASettings

weak var delegate: LocationViewControllerWrapperDelegate?

init(
customListRepository: CustomListRepositoryProtocol,
constraints: RelayConstraints,
multihopEnabled: Bool,
daitaEnabled: Bool,
daitaSettings: DAITASettings,
startContext: MultihopContext
) {
self.multihopEnabled = multihopEnabled
self.daitaEnabled = daitaEnabled
self.daitaSettings = daitaSettings
multihopContext = startContext

selectedEntry = constraints.entryLocations.value
Expand All @@ -73,13 +73,16 @@ final class LocationViewControllerWrapper: UIViewController {
entryLocationViewController = LocationViewController(
customListRepository: customListRepository,
selectedRelays: RelaySelection(),
daitaEnabled: multihopEnabled && daitaEnabled
shouldFilterDaita: daitaSettings.daitaState.isEnabled
&& daitaSettings.directOnlyState.isEnabled
)

exitLocationViewController = LocationViewController(
customListRepository: customListRepository,
selectedRelays: RelaySelection(),
daitaEnabled: !multihopEnabled && daitaEnabled
shouldFilterDaita: !multihopEnabled
&& daitaSettings.daitaState.isEnabled
&& daitaSettings.directOnlyState.isEnabled
)

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

func setRelaysWithLocation(_ relaysWithLocation: LocationRelays, filter: RelayFilter) {
var daitaFilteredRelays = relaysWithLocation
if daitaEnabled {
if daitaSettings.daitaState.isEnabled && daitaSettings.directOnlyState.isEnabled {
daitaFilteredRelays.relays = relaysWithLocation.relays.filter { relay in
relay.daita == true
}
Expand Down
65 changes: 56 additions & 9 deletions ios/MullvadVPN/View controllers/Settings/SettingsDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
}
}

private enum HeaderFooterReuseIdentifier: String, CaseIterable {
private enum HeaderFooterReuseIdentifier: String, CaseIterable, HeaderFooterIdentifierProtocol {
case primary
case spacer

var reusableViewClass: AnyClass {
EmptyTableViewHeaderFooterView.self
var headerFooterClass: AnyClass {
switch self {
case .primary:
UITableViewHeaderFooterView.self
case .spacer:
EmptyTableViewHeaderFooterView.self
}
}
}

Expand All @@ -38,6 +44,20 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
case main
case version
case problemReport

var sectionFooter: String? {
switch self {
case .daita:
NSLocalizedString(
"SETTINGS_DAITA_SECTION_FOOTER",
tableName: "Settings",
value: "Makes it possible to use DAITA with any server and is automatically enabled.",
comment: ""
)
default:
nil
}
}
}

enum Item: String {
Expand Down Expand Up @@ -130,16 +150,43 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
)
}

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
nil
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
let sectionIdentifier = snapshot().sectionIdentifiers[section]

return switch sectionIdentifier {
case .main:
0
case .daita, .version, .problemReport:
UITableView.automaticDimension
}
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return UIMetrics.TableView.sectionSpacing
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let sectionIdentifier = snapshot().sectionIdentifiers[section]
guard let sectionFooterText = sectionIdentifier.sectionFooter else { return nil }

guard let headerView = tableView
.dequeueReusableView(withIdentifier: HeaderFooterReuseIdentifier.primary)
else { return nil }

var contentConfiguration = UIListContentConfiguration.mullvadGroupedFooter(tableStyle: .plain)
contentConfiguration.text = sectionFooterText

headerView.contentConfiguration = contentConfiguration
// headerView.directionalLayoutMargins = UIMetrics.SettingsCell.apiAccessInsetLayoutMargins

return headerView
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
0
let sectionIdentifier = snapshot().sectionIdentifiers[section]

return switch sectionIdentifier {
case .daita:
UITableView.automaticDimension
case .main, .version, .problemReport:
0
}
}

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

HeaderFooterReuseIdentifier.allCases.forEach { reuseIdentifier in
tableView?.register(
reuseIdentifier.reusableViewClass,
reuseIdentifier.headerFooterClass,
forHeaderFooterViewReuseIdentifier: reuseIdentifier.rawValue
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// SettingsPromptAlertItem.swift
// MullvadVPN
//
// Created by Mojgan on 2024-09-16.
// Copyright © 2024 Mullvad VPN AB. All rights reserved.
//

import Foundation
enum DAITASettingsPromptItem: CustomStringConvertible {
case daitaSettingIncompatibleWithSinglehop
case daitaSettingIncompatibleWithMultihop

var description: String {
switch self {
case .daitaSettingIncompatibleWithSinglehop:
"""
DAITA isn’t available on the current server. After enabling, please go to the Switch \
location view and select a location that supports DAITA.
Attention: Since this increases your total network traffic, be cautious if you have a \
limited data plan. It can also negatively impact your network speed and battery usage.
"""
case .daitaSettingIncompatibleWithMultihop:
"""
DAITA isn’t available on the current entry server. After enabling, please go to the Switch \
location view and select an entry location that supports DAITA.
Attention: Since this increases your total network traffic, be cautious if you have a \
limited data plan. It can also negatively impact your network speed and battery usage.
"""
}
}
}

0 comments on commit 3feb1df

Please sign in to comment.