aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-01 16:04:42 +0530
committerRoopesh Chander <roop@roopc.net>2019-02-02 18:10:57 +0530
commit4134baced16a1b136b5df6133095b385e6f96198 (patch)
tree06bf928d4ed364a978e12e183597a25db3b3eebe
parentStrings: fix backwards clock wording (diff)
downloadwireguard-apple-4134baced16a1b136b5df6133095b385e6f96198.tar.xz
wireguard-apple-4134baced16a1b136b5df6133095b385e6f96198.zip
iOS: Tunnel detail: Keep track of visible fields with a [Bool] array
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift38
1 files changed, 28 insertions, 10 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
index 9aeab35f..6a2b1b7e 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
@@ -8,7 +8,7 @@ class TunnelDetailTableViewController: UITableViewController {
private enum Section {
case status
case interface
- case peer(_ peer: TunnelViewModel.PeerData)
+ case peer(index: Int, peer: TunnelViewModel.PeerData)
case onDemand
case delete
}
@@ -27,7 +27,11 @@ class TunnelDetailTableViewController: UITableViewController {
let tunnelsManager: TunnelsManager
let tunnel: TunnelContainer
var tunnelViewModel: TunnelViewModel
+
private var sections = [Section]()
+ private var interfaceFieldIsVisible = [Bool]()
+ private var peerFieldIsVisible = [[Bool]]()
+
private weak var statusCell: SwitchCell?
private var onDemandStatusObservationToken: AnyObject?
private var statusObservationToken: AnyObject?
@@ -39,6 +43,7 @@ class TunnelDetailTableViewController: UITableViewController {
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
super.init(style: .grouped)
loadSections()
+ loadVisibleFields()
statusObservationToken = tunnel.observe(\.status) { [weak self] _, _ in
guard let self = self else { return }
if let cell = self.statusCell {
@@ -76,11 +81,22 @@ class TunnelDetailTableViewController: UITableViewController {
sections.removeAll()
sections.append(.status)
sections.append(.interface)
- tunnelViewModel.peersData.forEach { sections.append(.peer($0)) }
+ for (index, peer) in tunnelViewModel.peersData.enumerated() {
+ sections.append(.peer(index: index, peer: peer))
+ }
sections.append(.onDemand)
sections.append(.delete)
}
+ private func loadVisibleFields() {
+ let visibleInterfaceFields = tunnelViewModel.interfaceData.filterFieldsWithValueOrControl(interfaceFields: interfaceFields)
+ interfaceFieldIsVisible = interfaceFields.map { visibleInterfaceFields.contains($0) }
+ peerFieldIsVisible = tunnelViewModel.peersData.map { peer in
+ let visiblePeerFields = peer.filterFieldsWithValueOrControl(peerFields: peerFields)
+ return peerFields.map { visiblePeerFields.contains($0) }
+ }
+ }
+
override func viewWillAppear(_ animated: Bool) {
if tunnel.status == .active {
self.startUpdatingRuntimeConfiguration()
@@ -189,9 +205,9 @@ extension TunnelDetailTableViewController {
case .status:
return 1
case .interface:
- return tunnelViewModel.interfaceData.filterFieldsWithValueOrControl(interfaceFields: interfaceFields).count
- case .peer(let peerData):
- return peerData.filterFieldsWithValueOrControl(peerFields: peerFields).count
+ return interfaceFieldIsVisible.filter { $0 }.count
+ case .peer(let peerIndex, _):
+ return peerFieldIsVisible[peerIndex].filter { $0 }.count
case .onDemand:
return 1
case .delete:
@@ -220,8 +236,8 @@ extension TunnelDetailTableViewController {
return statusCell(for: tableView, at: indexPath)
case .interface:
return interfaceCell(for: tableView, at: indexPath)
- case .peer(let peer):
- return peerCell(for: tableView, at: indexPath, with: peer)
+ case .peer(let index, let peer):
+ return peerCell(for: tableView, at: indexPath, with: peer, peerIndex: index)
case .onDemand:
return onDemandCell(for: tableView, at: indexPath)
case .delete:
@@ -245,15 +261,17 @@ extension TunnelDetailTableViewController {
}
private func interfaceCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
- let field = tunnelViewModel.interfaceData.filterFieldsWithValueOrControl(interfaceFields: interfaceFields)[indexPath.row]
+ let visibleInterfaceFields = interfaceFields.enumerated().filter { interfaceFieldIsVisible[$0.offset] }.map { $0.element }
+ let field = visibleInterfaceFields[indexPath.row]
let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath)
cell.key = field.localizedUIString
cell.value = tunnelViewModel.interfaceData[field]
return cell
}
- private func peerCell(for tableView: UITableView, at indexPath: IndexPath, with peerData: TunnelViewModel.PeerData) -> UITableViewCell {
- let field = peerData.filterFieldsWithValueOrControl(peerFields: peerFields)[indexPath.row]
+ private func peerCell(for tableView: UITableView, at indexPath: IndexPath, with peerData: TunnelViewModel.PeerData, peerIndex: Int) -> UITableViewCell {
+ let visiblePeerFields = peerFields.enumerated().filter { peerFieldIsVisible[peerIndex][$0.offset] }.map { $0.element }
+ let field = visiblePeerFields[indexPath.row]
let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath)
cell.key = field.localizedUIString
if field == .persistentKeepAlive {