Browse Source

allow re-configuring (e.g. after changing the IMAP/SMTP password) at an arbitrary point in time

Alla Reinsch 6 years ago
parent
commit
c224f5611f

+ 5 - 4
deltachat-ios/AppCoordinator.swift

@@ -34,8 +34,9 @@ class AppCoordinator: Coordinator {
         }
         }
     }
     }
     
     
-    func displayCredentialsController(message: String? = nil) {
-        let credentialsController = CredentialsController()
+    func displayCredentialsController(message: String? = nil, isCancellable:Bool = false) {
+        let credentialsController = CredentialsController(isCancellable: isCancellable)
+        
         let credentialsNav = UINavigationController(rootViewController: credentialsController)
         let credentialsNav = UINavigationController(rootViewController: credentialsController)
         
         
         if baseController.presentedViewController != nil {
         if baseController.presentedViewController != nil {
@@ -61,8 +62,8 @@ class AppCoordinator: Coordinator {
     
     
     func setupInnerViewControllers() {
     func setupInnerViewControllers() {
 
 
-        let chatViewController = ChatListController()
-        let chatNavigationController = UINavigationController(rootViewController: chatViewController)
+        let chatListController = ChatListController()
+        let chatNavigationController = UINavigationController(rootViewController: chatListController)
         
         
         baseController.present(chatNavigationController, animated: false, completion: nil)
         baseController.present(chatNavigationController, animated: false, completion: nil)
     }
     }

+ 5 - 3
deltachat-ios/AppDelegate.swift

@@ -55,9 +55,9 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
             }
             }
             if data1 == 0 {
             if data1 == 0 {
                 if let lastErrorMessage = AppDelegate.lastErrorDuringConfig {
                 if let lastErrorMessage = AppDelegate.lastErrorDuringConfig {
-                    AppDelegate.appCoordinator.displayCredentialsController(message: lastErrorMessage)
+                    AppDelegate.appCoordinator.displayCredentialsController(message: lastErrorMessage, isCancellable: AppDelegate.cancellableCredentialsController)
                 } else {
                 } else {
-                    AppDelegate.appCoordinator.displayCredentialsController(message: "Configuration failed. Make sure to enter correct credentials. If using GMail, enable access for 'less secure apps' first.")
+                    AppDelegate.appCoordinator.displayCredentialsController(message: "Configuration failed. Make sure to enter correct credentials. If using GMail, enable access for 'less secure apps' first.", isCancellable: AppDelegate.cancellableCredentialsController)
                 }
                 }
             }
             }
             let nc = NotificationCenter.default
             let nc = NotificationCenter.default
@@ -104,6 +104,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
     static let appCoordinator = AppCoordinator()
     static let appCoordinator = AppCoordinator()
     static var progress:Float = 0
     static var progress:Float = 0
     static var lastErrorDuringConfig:String? = nil
     static var lastErrorDuringConfig:String? = nil
+    static var cancellableCredentialsController = false
     var window: UIWindow?
     var window: UIWindow?
 
 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
@@ -120,7 +121,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 }
 }
 
 
 
 
-func initCore(withCredentials: Bool, advancedMode:Bool = false, model:CredentialsModel? = nil) {
+func initCore(withCredentials: Bool, advancedMode:Bool = false, model:CredentialsModel? = nil, cancellableCredentialsUponFailure: Bool = false) {
+    AppDelegate.cancellableCredentialsController = cancellableCredentialsUponFailure
 
 
     let paths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
     let paths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
     let documentsPath = paths[0]
     let documentsPath = paths[0]

+ 1 - 5
deltachat-ios/ChatListController.swift

@@ -107,11 +107,7 @@ actionSheet.addAction(UIAlertAction(title: "Scan QR code",
         actionSheet.addAction(UIAlertAction(title: "Settings",
         actionSheet.addAction(UIAlertAction(title: "Settings",
                                             style: .default,
                                             style: .default,
                                             handler: {a in
                                             handler: {a in
-                                                print("Settings")
-                                                let credentials = CredentialsController(isCancellable: true)
-                                                let nav = UINavigationController(rootViewController: credentials)
-                                                self.present(nav, animated: true, completion: nil)
-                                                
+                                                AppDelegate.appCoordinator.displayCredentialsController(isCancellable: true)
                                                 
                                                 
         }))
         }))
         actionSheet.addAction(UIAlertAction(title: "Cancel",
         actionSheet.addAction(UIAlertAction(title: "Cancel",

+ 6 - 2
deltachat-ios/CredentialsController.swift

@@ -164,9 +164,11 @@ class CredentialsController: UITableViewController {
     }
     }
     
     
     let cells:[UITableViewCell]
     let cells:[UITableViewCell]
+    let isCancellable:Bool
     
     
     init(isCancellable:Bool = false) {
     init(isCancellable:Bool = false) {
         cells = [emailCell, passwordCell]
         cells = [emailCell, passwordCell]
+        self.isCancellable = isCancellable
 
 
         super.init(style: .grouped)
         super.init(style: .grouped)
         doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(didPressSaveAccountButton))
         doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(didPressSaveAccountButton))
@@ -208,14 +210,16 @@ class CredentialsController: UITableViewController {
     }
     }
     
     
     @objc func didPressCancelButton() {
     @objc func didPressCancelButton() {
-        dismiss(animated: true, completion: nil)
+        dismiss(animated: false) {
+            AppDelegate.appCoordinator.setupInnerViewControllers()
+        }
     }
     }
     
     
     @objc func didPressSaveAccountButton() {
     @objc func didPressSaveAccountButton() {
         let m = model
         let m = model
         let a = advancedMode
         let a = advancedMode
         dismiss(animated: true) {
         dismiss(animated: true) {
-            initCore(withCredentials: true, advancedMode: a, model: m)
+            initCore(withCredentials: true, advancedMode: a, model: m, cancellableCredentialsUponFailure: self.isCancellable)
         }
         }
     }
     }