1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
//
// CustomDNSViewController.swift
// MullvadVPN
//
// Created by Jon Petersson on 2023-11-09.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import MullvadSettings
import UIKit
class CustomDNSViewController: UITableViewController, PreferencesDataSourceDelegate {
private let interactor: PreferencesInteractor
private var dataSource: CustomDNSDataSource?
private let alertPresenter: AlertPresenter
override var preferredStatusBarStyle: UIStatusBarStyle {
.lightContent
}
init(interactor: PreferencesInteractor, alertPresenter: AlertPresenter) {
self.interactor = interactor
self.alertPresenter = alertPresenter
super.init(style: .grouped)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundColor = .secondaryColor
tableView.separatorColor = .secondaryColor
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 60
tableView.estimatedSectionHeaderHeight = tableView.estimatedRowHeight
dataSource = CustomDNSDataSource(tableView: tableView)
dataSource?.delegate = self
navigationItem.title = NSLocalizedString(
"NAVIGATION_TITLE",
tableName: "Preferences",
value: "DNS settings",
comment: ""
)
navigationItem.rightBarButtonItem = editButtonItem
interactor.tunnelSettingsDidChange = { [weak self] newSettings in
self?.dataSource?.update(from: newSettings)
}
dataSource?.update(from: interactor.tunnelSettings)
tableView.tableHeaderView = UIView(frame: CGRect(
origin: .zero,
size: CGSize(width: 0, height: UIMetrics.TableView.sectionSpacing)
))
}
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
dataSource?.setEditing(editing, animated: animated)
navigationItem.setHidesBackButton(editing, animated: animated)
// Disable swipe to dismiss when editing
isModalInPresentation = editing
}
private func showInfo(with message: String) {
let presentation = AlertPresentation(
id: "preferences-content-blockers-alert",
icon: .info,
message: message,
buttons: [
AlertAction(
title: NSLocalizedString(
"PREFERENCES_DNS_SETTINGS_OK_ACTION",
tableName: "ContentBlockers",
value: "Got it!",
comment: ""
),
style: .default
),
]
)
alertPresenter.showAlert(presentation: presentation, animated: true)
}
// MARK: - PreferencesDataSourceDelegate
func didChangeViewModel(_ viewModel: PreferencesViewModel) {
interactor.setDNSSettings(viewModel.asDNSSettings())
}
func showInfo(for item: PreferencesInfoButtonItem) {
var message = ""
switch item {
case .contentBlockers:
message = NSLocalizedString(
"PREFERENCES_CONTENT_BLOCKERS_GENERAL",
tableName: "ContentBlockers",
value: """
When this feature is enabled it stops the device from contacting certain \
domains or websites known for distributing ads, malware, trackers and more. \
This might cause issues on certain websites, services, and programs.
""",
comment: ""
)
case .blockMalware:
message = NSLocalizedString(
"PREFERENCES_CONTENT_BLOCKERS_MALWARE",
tableName: "ContentBlockers",
value: """
Warning: The malware blocker is not an anti-virus and should not \
be treated as such, this is just an extra layer of protection.
""",
comment: ""
)
default:
assertionFailure("No matching InfoButtonItem")
}
showInfo(with: message)
}
func showDNSSettings() {
// No op.
}
func didSelectWireGuardPort(_ port: UInt16?) {
// No op.
}
}
|