aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-08 14:55:08 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:55 +0100
commit574d8433b3402b93352a85f11726adf9e93fbcdd (patch)
treef65f41bcfcb47531e68c0cd6accf3407348bf504
parenton-demand: ActivateOnDemandViewModel: Uniquify SSIDs list (diff)
downloadwireguard-apple-574d8433b3402b93352a85f11726adf9e93fbcdd.tar.xz
wireguard-apple-574d8433b3402b93352a85f11726adf9e93fbcdd.zip
on-demand: iOS: Update on-demand info shown in tunnel edit view
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift7
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift7
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift13
3 files changed, 23 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift b/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift
index 55da6e07..f38ca6ac 100644
--- a/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift
+++ b/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift
@@ -137,6 +137,13 @@ extension ActivateOnDemandViewModel {
#endif
}
}
+
+ func fixSSIDOption() {
+ selectedSSIDs = uniquifiedNonEmptySelectedSSIDs()
+ if selectedSSIDs.isEmpty {
+ ssidOption = .anySSID
+ }
+ }
}
private extension ActivateOnDemandViewModel {
diff --git a/WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift b/WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift
index 94e4e053..a059b9c6 100644
--- a/WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift
@@ -9,8 +9,13 @@ class ChevronCell: UITableViewCell {
set(value) { textLabel?.text = value }
}
+ var detailMessage: String {
+ get { return detailTextLabel?.text ?? "" }
+ set(value) { detailTextLabel?.text = value }
+ }
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: .default, reuseIdentifier: reuseIdentifier)
+ super.init(style: .value1, reuseIdentifier: reuseIdentifier)
accessoryType = .disclosureIndicator
}
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
index 6f0444e6..f640414f 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
@@ -442,6 +442,7 @@ extension TunnelEditTableViewController {
} else {
let cell: ChevronCell = tableView.dequeueReusableCell(for: indexPath)
cell.message = field.localizedUIString
+ cell.detailMessage = onDemandViewModel.ssidOption.localizedUIString
return cell
}
}
@@ -500,8 +501,14 @@ extension TunnelEditTableViewController {
extension TunnelEditTableViewController: SSIDOptionEditTableViewControllerDelegate {
func ssidOptionSaved(option: ActivateOnDemandViewModel.OnDemandSSIDOption, ssids: [String]) {
- let validSSIDs = ssids.filter { !$0.isEmpty }
- onDemandViewModel.selectedSSIDs = validSSIDs
- onDemandViewModel.ssidOption = validSSIDs.isEmpty ? .anySSID : option
+ onDemandViewModel.selectedSSIDs = ssids
+ onDemandViewModel.ssidOption = option
+ onDemandViewModel.fixSSIDOption()
+ if let onDemandSection = sections.firstIndex(where: { $0 == .onDemand }) {
+ if let ssidRowIndex = onDemandFields.firstIndex(of: .ssid) {
+ let indexPath = IndexPath(row: ssidRowIndex, section: onDemandSection)
+ tableView.reloadRows(at: [indexPath], with: .none)
+ }
+ }
}
}