From 8e5a9215de945cd6a6bc274c37bb1f2d31581bd5 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Sat, 9 Mar 2019 12:53:14 +0530 Subject: on-demand: iOS: Show list of SSIDs in a separate screen Signed-off-by: Roopesh Chander --- WireGuard/WireGuard.xcodeproj/project.pbxproj | 4 ++ .../SSIDOptionDetailTableViewController.swift | 48 ++++++++++++++++++++++ .../TunnelDetailTableViewController.swift | 42 ++++++++++++++++--- 3 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 WireGuard/WireGuard/UI/iOS/ViewController/SSIDOptionDetailTableViewController.swift diff --git a/WireGuard/WireGuard.xcodeproj/project.pbxproj b/WireGuard/WireGuard.xcodeproj/project.pbxproj index 985ac06..e149a33 100644 --- a/WireGuard/WireGuard.xcodeproj/project.pbxproj +++ b/WireGuard/WireGuard.xcodeproj/project.pbxproj @@ -90,6 +90,7 @@ 6F919EDB218C65C50023B400 /* wireguard_doc_logo_64x64.png in Resources */ = {isa = PBXBuildFile; fileRef = 6F919ED7218C65C50023B400 /* wireguard_doc_logo_64x64.png */; }; 6F919EDC218C65C50023B400 /* wireguard_doc_logo_320x320.png in Resources */ = {isa = PBXBuildFile; fileRef = 6F919ED8218C65C50023B400 /* wireguard_doc_logo_320x320.png */; }; 6F9B582921E8D6D100544D02 /* PopupRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9B582721E8CD4300544D02 /* PopupRow.swift */; }; + 6F9B8A8E223398610041B9C4 /* SSIDOptionDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9B8A8D223398610041B9C4 /* SSIDOptionDetailTableViewController.swift */; }; 6FB1017921C57DE600766195 /* MockTunnels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FB1017821C57DE600766195 /* MockTunnels.swift */; }; 6FB17946222FD5960018AE71 /* OnDemandWiFiControls.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FB17945222FD5960018AE71 /* OnDemandWiFiControls.swift */; }; 6FB1BD6021D2607A00A991BF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FB1BD5F21D2607A00A991BF /* AppDelegate.swift */; }; @@ -314,6 +315,7 @@ 6F919ED7218C65C50023B400 /* wireguard_doc_logo_64x64.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wireguard_doc_logo_64x64.png; sourceTree = ""; }; 6F919ED8218C65C50023B400 /* wireguard_doc_logo_320x320.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wireguard_doc_logo_320x320.png; sourceTree = ""; }; 6F9B582721E8CD4300544D02 /* PopupRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopupRow.swift; sourceTree = ""; }; + 6F9B8A8D223398610041B9C4 /* SSIDOptionDetailTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSIDOptionDetailTableViewController.swift; sourceTree = ""; }; 6FB1017821C57DE600766195 /* MockTunnels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTunnels.swift; sourceTree = ""; }; 6FB17945222FD5960018AE71 /* OnDemandWiFiControls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnDemandWiFiControls.swift; sourceTree = ""; }; 6FB1BD5D21D2607A00A991BF /* WireGuard.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WireGuard.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -431,6 +433,7 @@ 6FDEF805218725D200D8FBF6 /* SettingsTableViewController.swift */, 6F7774DF217181B1006A79B3 /* MainViewController.swift */, 6F8F0D7622267C57000E8335 /* SSIDOptionEditTableViewController.swift */, + 6F9B8A8D223398610041B9C4 /* SSIDOptionDetailTableViewController.swift */, ); path = ViewController; sourceTree = ""; @@ -1282,6 +1285,7 @@ 5F4541A621C4449E00994C13 /* ButtonCell.swift in Sources */, 5F45419821C2D60500994C13 /* KeyValueCell.swift in Sources */, 6FBA103E21D6B6D70051C35F /* TunnelImporter.swift in Sources */, + 6F9B8A8E223398610041B9C4 /* SSIDOptionDetailTableViewController.swift in Sources */, 6F919EC3218A2AE90023B400 /* ErrorPresenter.swift in Sources */, 6B62E45F220A6FA900EF34A6 /* PrivateDataConfirmation.swift in Sources */, 6F5A2B4821AFF49A0081EDD8 /* FileManager+Extension.swift in Sources */, diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/SSIDOptionDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/SSIDOptionDetailTableViewController.swift new file mode 100644 index 0000000..c1e0913 --- /dev/null +++ b/WireGuard/WireGuard/UI/iOS/ViewController/SSIDOptionDetailTableViewController.swift @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved. + +import UIKit + +class SSIDOptionDetailTableViewController: UITableViewController { + + let selectedSSIDs: [String] + + init(title: String, ssids: [String]) { + selectedSSIDs = ssids + super.init(style: .grouped) + self.title = title + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + + tableView.estimatedRowHeight = 44 + tableView.rowHeight = UITableView.automaticDimension + + tableView.register(TextCell.self) + } +} + +extension SSIDOptionDetailTableViewController { + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return selectedSSIDs.count + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return tr("tunnelOnDemandSectionTitleSelectedSSIDs") + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: TextCell = tableView.dequeueReusableCell(for: indexPath) + cell.message = selectedSSIDs[indexPath.row] + return cell + } +} diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift index 4ed75a6..abee818 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift @@ -76,10 +76,10 @@ class TunnelDetailTableViewController: UITableViewController { tableView.estimatedRowHeight = 44 tableView.rowHeight = UITableView.automaticDimension - tableView.allowsSelection = false tableView.register(SwitchCell.self) tableView.register(KeyValueCell.self) tableView.register(ButtonCell.self) + tableView.register(ChevronCell.self) restorationIdentifier = "TunnelDetailVC:\(tunnel.name)" } @@ -407,15 +407,26 @@ extension TunnelDetailTableViewController { } private func onDemandCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { - let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) let field = TunnelDetailTableViewController.onDemandFields[indexPath.row] - cell.key = field.localizedUIString if field == .onDemand { + let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) + cell.key = field.localizedUIString cell.value = onDemandViewModel.localizedInterfaceDescription - } else if field == .ssid { - cell.value = onDemandViewModel.ssidOption.localizedUIString + return cell + } else { + assert(field == .ssid) + if onDemandViewModel.ssidOption == .anySSID { + let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) + cell.key = field.localizedUIString + cell.value = onDemandViewModel.ssidOption.localizedUIString + return cell + } else { + let cell: ChevronCell = tableView.dequeueReusableCell(for: indexPath) + cell.message = field.localizedUIString + cell.detailMessage = onDemandViewModel.ssidOption.localizedUIString + return cell + } } - return cell } private func deleteConfigurationCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { @@ -438,3 +449,22 @@ extension TunnelDetailTableViewController { } } + +extension TunnelDetailTableViewController { + override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { + if case .onDemand = sections[indexPath.section], + case .ssid = TunnelDetailTableViewController.onDemandFields[indexPath.row] { + return indexPath + } + return nil + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + if case .onDemand = sections[indexPath.section], + case .ssid = TunnelDetailTableViewController.onDemandFields[indexPath.row] { + let ssidDetailVC = SSIDOptionDetailTableViewController(title: onDemandViewModel.ssidOption.localizedUIString, ssids: onDemandViewModel.selectedSSIDs) + navigationController?.pushViewController(ssidDetailVC, animated: true) + } + tableView.deselectRow(at: indexPath, animated: true) + } +} -- cgit v1.2.3-59-g8ed1b