iOS: Refactor showing of the tunnel detail
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
393718dfaf
commit
88c80d6694
|
@ -90,19 +90,10 @@ extension MainViewController {
|
||||||
|
|
||||||
func showTunnelDetailForTunnel(named tunnelName: String, animated: Bool, shouldToggleStatus: Bool) {
|
func showTunnelDetailForTunnel(named tunnelName: String, animated: Bool, shouldToggleStatus: Bool) {
|
||||||
let showTunnelDetailBlock: (TunnelsManager) -> Void = { [weak self] tunnelsManager in
|
let showTunnelDetailBlock: (TunnelsManager) -> Void = { [weak self] tunnelsManager in
|
||||||
|
guard let self = self else { return }
|
||||||
|
guard let tunnelsListVC = self.tunnelsListVC else { return }
|
||||||
if let tunnel = tunnelsManager.tunnel(named: tunnelName) {
|
if let tunnel = tunnelsManager.tunnel(named: tunnelName) {
|
||||||
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager, tunnel: tunnel)
|
tunnelsListVC.showTunnelDetail(for: tunnel, animated: false)
|
||||||
let tunnelDetailNC = UINavigationController(rootViewController: tunnelDetailVC)
|
|
||||||
tunnelDetailNC.restorationIdentifier = "DetailNC"
|
|
||||||
if let self = self {
|
|
||||||
if animated {
|
|
||||||
self.showDetailViewController(tunnelDetailNC, sender: self)
|
|
||||||
} else {
|
|
||||||
UIView.performWithoutAnimation {
|
|
||||||
self.showDetailViewController(tunnelDetailNC, sender: self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if shouldToggleStatus {
|
if shouldToggleStatus {
|
||||||
if tunnel.status == .inactive {
|
if tunnel.status == .inactive {
|
||||||
tunnelsManager.startActivation(of: tunnel)
|
tunnelsManager.startActivation(of: tunnel)
|
||||||
|
|
|
@ -251,6 +251,26 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showTunnelDetail(for tunnel: TunnelContainer, animated: Bool) {
|
||||||
|
guard let tunnelsManager = tunnelsManager else { return }
|
||||||
|
guard let splitViewController = splitViewController else { return }
|
||||||
|
|
||||||
|
if detailDisplayedTunnel != tunnel {
|
||||||
|
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager,
|
||||||
|
tunnel: tunnel)
|
||||||
|
let tunnelDetailNC = UINavigationController(rootViewController: tunnelDetailVC)
|
||||||
|
tunnelDetailNC.restorationIdentifier = "DetailNC"
|
||||||
|
if animated {
|
||||||
|
splitViewController.showDetailViewController(tunnelDetailNC, sender: self)
|
||||||
|
} else {
|
||||||
|
UIView.performWithoutAnimation {
|
||||||
|
splitViewController.showDetailViewController(tunnelDetailNC, sender: self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
detailDisplayedTunnel = tunnel
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TunnelsListTableViewController: UIDocumentPickerDelegate {
|
extension TunnelsListTableViewController: UIDocumentPickerDelegate {
|
||||||
|
@ -309,12 +329,7 @@ extension TunnelsListTableViewController: UITableViewDelegate {
|
||||||
}
|
}
|
||||||
guard let tunnelsManager = tunnelsManager else { return }
|
guard let tunnelsManager = tunnelsManager else { return }
|
||||||
let tunnel = tunnelsManager.tunnel(at: indexPath.row)
|
let tunnel = tunnelsManager.tunnel(at: indexPath.row)
|
||||||
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager,
|
showTunnelDetail(for: tunnel, animated: true)
|
||||||
tunnel: tunnel)
|
|
||||||
let tunnelDetailNC = UINavigationController(rootViewController: tunnelDetailVC)
|
|
||||||
tunnelDetailNC.restorationIdentifier = "DetailNC"
|
|
||||||
showDetailViewController(tunnelDetailNC, sender: self) // Shall get propagated up to the split-vc
|
|
||||||
detailDisplayedTunnel = tunnel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
|
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
|
||||||
|
|
Loading…
Reference in New Issue