From 5ea9a3118b6401812d2bbd8ef5a4c35e475bb264 Mon Sep 17 00:00:00 2001 From: Yishi Lin Date: Sat, 11 Mar 2017 02:07:04 +0800 Subject: [PATCH] Go back to the "password store" view if user discards all local changes. - Otherwise, editing an updated entry will crash the app. - Showing an deleted entry is not reasonable. --- .../PasswordDetailTableViewController.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pass/Controllers/PasswordDetailTableViewController.swift b/pass/Controllers/PasswordDetailTableViewController.swift index 05a6f4f..6dd2586 100644 --- a/pass/Controllers/PasswordDetailTableViewController.swift +++ b/pass/Controllers/PasswordDetailTableViewController.swift @@ -17,6 +17,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni var password: Password? var passwordImage: UIImage? var oneTimePasswordIndexPath : IndexPath? + var shouldPopCurrentView = false let indicatorLable: UILabel = { let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 21)) @@ -118,6 +119,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni } self.setupUpdateOneTimePassword() + self.addNotificationObservers() } @@ -386,4 +388,22 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni return true } + private func addNotificationObservers() { + NotificationCenter.default.addObserver(self, selector: #selector(setShouldPopCurrentView), name: NSNotification.Name(rawValue: "passwordStoreChangeDiscarded"), object: nil) + } + + func setShouldPopCurrentView() { + self.shouldPopCurrentView = true + } + + override func viewDidAppear(_ animated: Bool) { + super.viewWillAppear(animated) + if self.shouldPopCurrentView { + let alert = UIAlertController(title: "Notice", message: "All previous local changes have been discarded. Your current Password Store will be shown.", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in + _ = self.navigationController?.popViewController(animated: true) + })) + self.present(alert, animated: true, completion: nil) + } + } }