Tunnel editing: Delegate should also report when editing is cancelled

This commit is contained in:
Roopesh Chander 2018-10-25 11:14:38 +05:30
parent 4e2a1aa07a
commit b2ad15da55
3 changed files with 13 additions and 5 deletions

View File

@ -54,10 +54,13 @@ class TunnelDetailTableViewController: UITableViewController {
// MARK: TunnelEditTableViewControllerDelegate // MARK: TunnelEditTableViewControllerDelegate
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate { extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
func saved(tunnel: TunnelContainer) { func tunnelSaved(tunnel: TunnelContainer) {
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration) tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
self.tableView.reloadData() self.tableView.reloadData()
} }
func tunnelEditingCancelled() {
// Nothing to do
}
} }
// MARK: UITableViewDataSource // MARK: UITableViewDataSource

View File

@ -4,7 +4,8 @@
import UIKit import UIKit
protocol TunnelEditTableViewControllerDelegate: class { protocol TunnelEditTableViewControllerDelegate: class {
func saved(tunnel: TunnelContainer) func tunnelSaved(tunnel: TunnelContainer)
func tunnelEditingCancelled()
} }
// MARK: TunnelEditTableViewController // MARK: TunnelEditTableViewController
@ -81,8 +82,8 @@ class TunnelEditTableViewController: UITableViewController {
print("Could not modify tunnel: \(error)") print("Could not modify tunnel: \(error)")
self?.showErrorAlert(title: "Could not save", message: "Internal error") self?.showErrorAlert(title: "Could not save", message: "Internal error")
} else { } else {
self?.delegate?.saved(tunnel: tunnel)
self?.dismiss(animated: true, completion: nil) self?.dismiss(animated: true, completion: nil)
self?.delegate?.tunnelSaved(tunnel: tunnel)
} }
} }
} else { } else {
@ -92,8 +93,8 @@ class TunnelEditTableViewController: UITableViewController {
print("Could not add tunnel: \(error)") print("Could not add tunnel: \(error)")
self?.showErrorAlert(title: "Could not save", message: "Internal error") self?.showErrorAlert(title: "Could not save", message: "Internal error")
} else { } else {
self?.delegate?.saved(tunnel: tunnel)
self?.dismiss(animated: true, completion: nil) self?.dismiss(animated: true, completion: nil)
self?.delegate?.tunnelSaved(tunnel: tunnel)
} }
} }
} }
@ -102,6 +103,7 @@ class TunnelEditTableViewController: UITableViewController {
@objc func cancelTapped() { @objc func cancelTapped() {
dismiss(animated: true, completion: nil) dismiss(animated: true, completion: nil)
self.delegate?.tunnelEditingCancelled()
} }
func showErrorAlert(title: String, message: String) { func showErrorAlert(title: String, message: String) {

View File

@ -94,12 +94,15 @@ class TunnelsListTableViewController: UITableViewController {
// MARK: TunnelEditTableViewControllerDelegate // MARK: TunnelEditTableViewControllerDelegate
extension TunnelsListTableViewController: TunnelEditTableViewControllerDelegate { extension TunnelsListTableViewController: TunnelEditTableViewControllerDelegate {
func saved(tunnel: TunnelContainer) { func tunnelSaved(tunnel: TunnelContainer) {
guard let tunnelsManager = tunnelsManager else { return } guard let tunnelsManager = tunnelsManager else { return }
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager, let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager,
tunnel: tunnel) tunnel: tunnel)
showDetailViewController(tunnelDetailVC, sender: self) // Shall get propagated up to the split-vc showDetailViewController(tunnelDetailVC, sender: self) // Shall get propagated up to the split-vc
} }
func tunnelEditingCancelled() {
// Nothing to do here
}
} }
// MARK: UITableViewDataSource // MARK: UITableViewDataSource