aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/EditTunnel
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditReadOnlyKeyValueCell.swift35
-rw-r--r--WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditTableViewController.swift48
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/ButtonCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditButtonCell.swift)6
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/CheckmarkCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSectionListCell.swift)3
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/EditableKeyValueCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditKeyValueCell.swift)12
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/SwitchCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSwitchCell.swift)19
6 files changed, 64 insertions, 59 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditReadOnlyKeyValueCell.swift b/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditReadOnlyKeyValueCell.swift
index 48c8798..15d58d6 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditReadOnlyKeyValueCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditReadOnlyKeyValueCell.swift
@@ -6,29 +6,36 @@ import UIKit
class TunnelEditReadOnlyKeyValueCell: CopyableLabelTableViewCell {
var key: String {
get { return keyLabel.text ?? "" }
- set(value) {keyLabel.text = value }
+ set(value) { keyLabel.text = value }
}
var value: String {
get { return valueLabel.text }
set(value) { valueLabel.text = value }
}
- let keyLabel: UILabel
- let valueLabel: ScrollableLabel
+ override var textToCopy: String? {
+ return valueLabel.text
+ }
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- keyLabel = UILabel()
+ let keyLabel: UILabel = {
+ let keyLabel = UILabel()
keyLabel.font = UIFont.preferredFont(forTextStyle: .body)
keyLabel.adjustsFontForContentSizeCategory = true
- valueLabel = ScrollableLabel()
+ keyLabel.textColor = .gray
+ return keyLabel
+ }()
+
+ let valueLabel: ScrollableLabel = {
+ let valueLabel = ScrollableLabel()
valueLabel.label.font = UIFont.preferredFont(forTextStyle: .body)
valueLabel.label.adjustsFontForContentSizeCategory = true
-
+ valueLabel.textColor = .gray
+ return valueLabel
+ }()
+
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
- keyLabel.textColor = UIColor.gray
- valueLabel.textColor = UIColor.gray
-
contentView.addSubview(keyLabel)
keyLabel.translatesAutoresizingMaskIntoConstraints = false
keyLabel.textAlignment = .right
@@ -44,7 +51,7 @@ class TunnelEditReadOnlyKeyValueCell: CopyableLabelTableViewCell {
keyLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
keyLabel.leftAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leftAnchor),
widthRatioConstraint
- ])
+ ])
contentView.addSubview(valueLabel)
valueLabel.translatesAutoresizingMaskIntoConstraints = false
@@ -52,11 +59,7 @@ class TunnelEditReadOnlyKeyValueCell: CopyableLabelTableViewCell {
valueLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
valueLabel.leftAnchor.constraint(equalToSystemSpacingAfter: keyLabel.rightAnchor, multiplier: 1),
valueLabel.rightAnchor.constraint(equalTo: contentView.layoutMarginsGuide.rightAnchor)
- ])
- }
-
- override var textToCopy: String? {
- return self.valueLabel.text
+ ])
}
required init?(coder aDecoder: NSCoder) {
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditTableViewController.swift
index 8d055d2..393294e 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditTableViewController.swift
@@ -72,18 +72,18 @@ class TunnelEditTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
- self.title = tunnel == nil ? "New configuration" : "Edit configuration"
- self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(saveTapped))
- self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelTapped))
-
- self.tableView.estimatedRowHeight = 44
- self.tableView.rowHeight = UITableView.automaticDimension
-
- self.tableView.register(TunnelEditKeyValueCell.self)
- self.tableView.register(TunnelEditReadOnlyKeyValueCell.self)
- self.tableView.register(TunnelEditButtonCell.self)
- self.tableView.register(TunnelEditSwitchCell.self)
- self.tableView.register(TunnelEditSelectionListCell.self)
+ title = tunnel == nil ? "New configuration" : "Edit configuration"
+ navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(saveTapped))
+ navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelTapped))
+
+ tableView.estimatedRowHeight = 44
+ tableView.rowHeight = UITableView.automaticDimension
+
+ tableView.register(EditableKeyValueCell.self)
+ tableView.register(TunnelEditReadOnlyKeyValueCell.self)
+ tableView.register(ButtonCell.self)
+ tableView.register(SwitchCell.self)
+ tableView.register(CheckmarkCell.self)
}
private func loadSections() {
@@ -95,13 +95,13 @@ class TunnelEditTableViewController: UITableViewController {
}
@objc func saveTapped() {
- self.tableView.endEditing(false)
+ tableView.endEditing(false)
let tunnelSaveResult = tunnelViewModel.save()
switch tunnelSaveResult {
case .error(let errorMessage):
let erroringConfiguration = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ? "Interface" : "Peer"
ErrorPresenter.showErrorAlert(title: "Invalid \(erroringConfiguration)", message: errorMessage, from: self)
- self.tableView.reloadData() // Highlight erroring fields
+ tableView.reloadData() // Highlight erroring fields
case .saved(let tunnelConfiguration):
if let tunnel = tunnel {
// We're modifying an existing tunnel
@@ -133,7 +133,7 @@ class TunnelEditTableViewController: UITableViewController {
@objc func cancelTapped() {
dismiss(animated: true, completion: nil)
- self.delegate?.tunnelEditingCancelled()
+ delegate?.tunnelEditingCancelled()
}
}
@@ -201,7 +201,7 @@ extension TunnelEditTableViewController {
}
private func generateKeyPairCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell {
- let cell: TunnelEditButtonCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
cell.buttonText = field.rawValue
cell.onTapped = { [weak self] in
guard let self = self else { return }
@@ -225,7 +225,7 @@ extension TunnelEditTableViewController {
}
private func interfaceFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell {
- let cell: TunnelEditKeyValueCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: EditableKeyValueCell = tableView.dequeueReusableCell(for: indexPath)
cell.key = field.rawValue
switch field {
@@ -287,7 +287,7 @@ extension TunnelEditTableViewController {
}
private func deletePeerCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell {
- let cell: TunnelEditButtonCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
cell.buttonText = field.rawValue
cell.hasDestructiveAction = true
cell.onTapped = { [weak self, weak peerData] in
@@ -313,7 +313,7 @@ extension TunnelEditTableViewController {
}
private func excludePrivateIPsCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell {
- let cell: TunnelEditSwitchCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: SwitchCell = tableView.dequeueReusableCell(for: indexPath)
cell.message = field.rawValue
cell.isEnabled = peerData.shouldAllowExcludePrivateIPsControl
cell.isOn = peerData.excludePrivateIPsValue
@@ -328,7 +328,7 @@ extension TunnelEditTableViewController {
}
private func peerFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell {
- let cell: TunnelEditKeyValueCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: EditableKeyValueCell = tableView.dequeueReusableCell(for: indexPath)
cell.key = field.rawValue
switch field {
@@ -377,7 +377,7 @@ extension TunnelEditTableViewController {
}
private func addPeerCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
- let cell: TunnelEditButtonCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
cell.buttonText = "Add peer"
cell.onTapped = { [weak self] in
guard let self = self else { return }
@@ -398,7 +398,7 @@ extension TunnelEditTableViewController {
private func onDemandCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
- let cell: TunnelEditSwitchCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: SwitchCell = tableView.dequeueReusableCell(for: indexPath)
cell.message = "Activate on demand"
cell.isOn = activateOnDemandSetting.isActivateOnDemandEnabled
cell.onSwitchToggled = { [weak self] isOn in
@@ -419,7 +419,7 @@ extension TunnelEditTableViewController {
}
return cell
} else {
- let cell: TunnelEditSelectionListCell = tableView.dequeueReusableCell(for: indexPath)
+ let cell: CheckmarkCell = tableView.dequeueReusableCell(for: indexPath)
let rowOption = activateOnDemandOptions[indexPath.row - 1]
let selectedOption = activateOnDemandSetting.activateOnDemandOption
assert(selectedOption != .none)
@@ -455,7 +455,7 @@ extension TunnelEditTableViewController {
alert.popoverPresentationController?.sourceView = sourceView
alert.popoverPresentationController?.sourceRect = sourceView.bounds
- self.present(alert, animated: true, completion: nil)
+ present(alert, animated: true, completion: nil)
}
}
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditButtonCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/ButtonCell.swift
index af70183..4702993 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditButtonCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/ButtonCell.swift
@@ -3,14 +3,14 @@
import UIKit
-class TunnelEditButtonCell: UITableViewCell {
+class ButtonCell: UITableViewCell {
var buttonText: String {
get { return button.title(for: .normal) ?? "" }
set(value) { button.setTitle(value, for: .normal) }
}
var hasDestructiveAction: Bool {
- get { return button.tintColor == UIColor.red }
- set(value) { button.tintColor = value ? UIColor.red : buttonStandardTintColor }
+ get { return button.tintColor == .red }
+ set(value) { button.tintColor = value ? .red : buttonStandardTintColor }
}
var onTapped: (() -> Void)?
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSectionListCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/CheckmarkCell.swift
index ca0352e..db4b6c9 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSectionListCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/CheckmarkCell.swift
@@ -3,7 +3,7 @@
import UIKit
-class TunnelEditSelectionListCell: UITableViewCell {
+class CheckmarkCell: UITableViewCell {
var message: String {
get { return textLabel?.text ?? "" }
set(value) { textLabel!.text = value }
@@ -13,6 +13,7 @@ class TunnelEditSelectionListCell: UITableViewCell {
accessoryType = isChecked ? .checkmark : .none
}
}
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
isChecked = false
super.init(style: .default, reuseIdentifier: reuseIdentifier)
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditKeyValueCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/EditableKeyValueCell.swift
index 432d75b..48956eb 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditKeyValueCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/EditableKeyValueCell.swift
@@ -3,10 +3,10 @@
import UIKit
-class TunnelEditKeyValueCell: UITableViewCell {
+class EditableKeyValueCell: UITableViewCell {
var key: String {
get { return keyLabel.text ?? "" }
- set(value) {keyLabel.text = value }
+ set(value) { keyLabel.text = value }
}
var value: String {
get { return valueTextField.text ?? "" }
@@ -89,7 +89,7 @@ class TunnelEditKeyValueCell: UITableViewCell {
func configureForContentSize() {
var constraints = [NSLayoutConstraint]()
- if self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
+ if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
// Stack vertically
if !isStackedVertically {
constraints = [
@@ -113,9 +113,9 @@ class TunnelEditKeyValueCell: UITableViewCell {
}
}
if !constraints.isEmpty {
- NSLayoutConstraint.deactivate(self.contentSizeBasedConstraints)
+ NSLayoutConstraint.deactivate(contentSizeBasedConstraints)
NSLayoutConstraint.activate(constraints)
- self.contentSizeBasedConstraints = constraints
+ contentSizeBasedConstraints = constraints
}
}
@@ -136,7 +136,7 @@ class TunnelEditKeyValueCell: UITableViewCell {
}
}
-extension TunnelEditKeyValueCell: UITextFieldDelegate {
+extension EditableKeyValueCell: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
textFieldValueOnBeginEditing = textField.text ?? ""
isValueValid = true
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSwitchCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/SwitchCell.swift
index 658fb95..d0c29aa 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSwitchCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/SwitchCell.swift
@@ -3,10 +3,10 @@
import UIKit
-class TunnelEditSwitchCell: UITableViewCell {
+class SwitchCell: UITableViewCell {
var message: String {
get { return textLabel?.text ?? "" }
- set(value) { textLabel!.text = value }
+ set(value) { textLabel?.text = value }
}
var isOn: Bool {
get { return switchView.isOn }
@@ -16,31 +16,32 @@ class TunnelEditSwitchCell: UITableViewCell {
get { return switchView.isEnabled }
set(value) {
switchView.isEnabled = value
- textLabel?.textColor = value ? UIColor.black : UIColor.gray
+ textLabel?.textColor = value ? .black : .gray
}
}
var onSwitchToggled: ((Bool) -> Void)?
- let switchView: UISwitch
+ let switchView = UISwitch()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- switchView = UISwitch()
super.init(style: .default, reuseIdentifier: reuseIdentifier)
+
accessoryView = switchView
switchView.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
}
+
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
@objc func switchToggled() {
onSwitchToggled?(switchView.isOn)
}
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
override func prepareForReuse() {
super.prepareForReuse()
+ isEnabled = true
message = ""
isOn = false
}