State restoration: Restore tunnel detail view
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
e3801308cb
commit
105eca7adc
|
@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
var mainVC: MainViewController?
|
var mainVC: MainViewController?
|
||||||
|
|
||||||
func application(_ application: UIApplication,
|
func application(_ application: UIApplication,
|
||||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
|
|
||||||
let window = UIWindow(frame: UIScreen.main.bounds)
|
let window = UIWindow(frame: UIScreen.main.bounds)
|
||||||
window.backgroundColor = UIColor.white
|
window.backgroundColor = UIColor.white
|
||||||
|
@ -36,3 +36,38 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
mainVC?.refreshTunnelConnectionStatuses()
|
mainVC?.refreshTunnelConnectionStatuses()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: State restoration
|
||||||
|
|
||||||
|
extension AppDelegate {
|
||||||
|
func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func application(_ application: UIApplication,
|
||||||
|
viewControllerWithRestorationIdentifierPath identifierComponents: [String],
|
||||||
|
coder: NSCoder) -> UIViewController? {
|
||||||
|
guard let vcIdentifier = identifierComponents.last else { return nil }
|
||||||
|
if (vcIdentifier == "MainVC") {
|
||||||
|
return MainViewController()
|
||||||
|
} else if (vcIdentifier == "TunnelsListVC") {
|
||||||
|
return TunnelsListTableViewController()
|
||||||
|
} else if (vcIdentifier.hasPrefix("TunnelDetailVC:")) {
|
||||||
|
let tunnelName = String(vcIdentifier.suffix(vcIdentifier.count - "TunnelDetailVC:".count))
|
||||||
|
if let tunnelsManager = mainVC?.tunnelsManager {
|
||||||
|
if let tunnel = tunnelsManager.tunnel(named: tunnelName) {
|
||||||
|
return TunnelDetailTableViewController(tunnelsManager: tunnelsManager, tunnel: tunnel)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Show it when tunnelsManager is available
|
||||||
|
mainVC?.showTunnelDetailForTunnel(named: tunnelName, animated: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,11 @@ class MainViewController: UISplitViewController {
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
|
||||||
self.viewControllers = [ masterNC, detailNC ]
|
self.viewControllers = [ masterNC, detailNC ]
|
||||||
|
|
||||||
|
// State restoration
|
||||||
|
self.restorationIdentifier = "MainVC"
|
||||||
|
masterNC.restorationIdentifier = "MasterNC"
|
||||||
|
detailNC.restorationIdentifier = "DetailNC"
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
@ -67,6 +72,30 @@ extension MainViewController {
|
||||||
tunnelsManager.refreshStatuses()
|
tunnelsManager.refreshStatuses()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showTunnelDetailForTunnel(named tunnelName: String, animated: Bool) {
|
||||||
|
let showTunnelDetailBlock: (TunnelsManager) -> Void = { [weak self] (tunnelsManager) in
|
||||||
|
if let tunnel = tunnelsManager.tunnel(named: tunnelName) {
|
||||||
|
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager, tunnel: tunnel)
|
||||||
|
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 let tunnelsManager = tunnelsManager {
|
||||||
|
showTunnelDetailBlock(tunnelsManager)
|
||||||
|
} else {
|
||||||
|
onTunnelsManagerReady = showTunnelDetailBlock
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension MainViewController: UISplitViewControllerDelegate {
|
extension MainViewController: UISplitViewControllerDelegate {
|
||||||
|
|
|
@ -43,6 +43,9 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||||
self.tableView.register(TunnelDetailTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelDetailTableViewKeyValueCell.id)
|
self.tableView.register(TunnelDetailTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelDetailTableViewKeyValueCell.id)
|
||||||
self.tableView.register(TunnelDetailTableViewButtonCell.self, forCellReuseIdentifier: TunnelDetailTableViewButtonCell.id)
|
self.tableView.register(TunnelDetailTableViewButtonCell.self, forCellReuseIdentifier: TunnelDetailTableViewButtonCell.id)
|
||||||
self.tableView.register(TunnelDetailTableViewActivateOnDemandCell.self, forCellReuseIdentifier: TunnelDetailTableViewActivateOnDemandCell.id)
|
self.tableView.register(TunnelDetailTableViewActivateOnDemandCell.self, forCellReuseIdentifier: TunnelDetailTableViewActivateOnDemandCell.id)
|
||||||
|
|
||||||
|
// State restoration
|
||||||
|
self.restorationIdentifier = "TunnelDetailVC:\(tunnel.name)"
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func editTapped() {
|
@objc func editTapped() {
|
||||||
|
|
|
@ -37,6 +37,9 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
])
|
])
|
||||||
busyIndicator.startAnimating()
|
busyIndicator.startAnimating()
|
||||||
self.busyIndicator = busyIndicator
|
self.busyIndicator = busyIndicator
|
||||||
|
|
||||||
|
// State restoration
|
||||||
|
self.restorationIdentifier = "TunnelsListVC"
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTunnelsManager(tunnelsManager: TunnelsManager) {
|
func setTunnelsManager(tunnelsManager: TunnelsManager) {
|
||||||
|
@ -266,6 +269,7 @@ extension TunnelsListTableViewController: UITableViewDelegate {
|
||||||
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager,
|
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager,
|
||||||
tunnel: tunnel)
|
tunnel: tunnel)
|
||||||
let tunnelDetailNC = UINavigationController(rootViewController: tunnelDetailVC)
|
let tunnelDetailNC = UINavigationController(rootViewController: tunnelDetailVC)
|
||||||
|
tunnelDetailNC.restorationIdentifier = "DetailNC"
|
||||||
showDetailViewController(tunnelDetailNC, sender: self) // Shall get propagated up to the split-vc
|
showDetailViewController(tunnelDetailNC, sender: self) // Shall get propagated up to the split-vc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,6 +238,10 @@ class TunnelsManager {
|
||||||
return tunnels[index]
|
return tunnels[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tunnel(named tunnelName: String) -> TunnelContainer? {
|
||||||
|
return self.tunnels.first(where: { $0.name == tunnelName })
|
||||||
|
}
|
||||||
|
|
||||||
func startActivation(of tunnel: TunnelContainer, completionHandler: @escaping (TunnelsManagerError?) -> Void) {
|
func startActivation(of tunnel: TunnelContainer, completionHandler: @escaping (TunnelsManagerError?) -> Void) {
|
||||||
guard (tunnel.status == .inactive) else {
|
guard (tunnel.status == .inactive) else {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue