Bladeren bron

don't allow to dismiss the login screen (#385), navigate back on successful login in advanced settings (#387)

cyberta 5 jaren geleden
bovenliggende
commit
70e66224d0

+ 0 - 4
deltachat-ios/AppDelegate.swift

@@ -68,15 +68,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // setup deltachat core context
         //       - second param remains nil (user data for more than one mailbox)
         open()
-        let isConfigured = dc_is_configured(mailboxPointer) != 0
         appCoordinator = AppCoordinator(window: window, dcContext: dcContext)
         appCoordinator.start()
         UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
         start()
         setStockTranslations()
-        if !isConfigured {
-            appCoordinator.presentLoginController()
-        }
         return true
     }
 

+ 22 - 14
deltachat-ios/Controller/AccountSetupController.swift

@@ -117,11 +117,13 @@ class AccountSetupController: UITableViewController {
         })
     }
 
-    private func updateProgressHudSuccess() {
+    private func updateProgressHudSuccess(isLogin: Bool) {
         updateProgressHudValue(value: 1000)
         DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
             self.configProgressAlert.dismiss(animated: true) {
-                self.handleLoginSuccess()
+                if isLogin {
+                    self.handleLoginSuccess()
+                }
             }
         })
     }
@@ -390,7 +392,6 @@ class AccountSetupController: UITableViewController {
 
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
-        addProgressHudEventListener()
     }
 
     override func viewWillDisappear(_ animated: Bool) {
@@ -559,6 +560,7 @@ class AccountSetupController: UITableViewController {
     }
 
     private func login(emailAddress: String, password: String, skipAdvanceSetup: Bool = false) {
+        addProgressHudLoginListener()
         resignFirstResponderOnAllCells()	// this will resign focus from all textFieldCells so the keyboard wont pop up anymore
         DcConfig.addr = emailAddress
         DcConfig.mailPw = password
@@ -637,10 +639,10 @@ class AccountSetupController: UITableViewController {
         UIApplication.shared.open(url) // this opens safari as seperate app
     }
 
-    private func addProgressHudEventListener() {
+    private func addProgressHudLoginListener() {
         let nc = NotificationCenter.default
-        backupProgressObserver = nc.addObserver(
-            forName: dcNotificationImexProgress,
+        configureProgressObserver = nc.addObserver(
+            forName: dcNotificationConfigureProgress,
             object: nil,
             queue: nil
         ) {
@@ -649,14 +651,18 @@ class AccountSetupController: UITableViewController {
                 if ui["error"] as! Bool {
                     self.updateProgressHud(error: ui["errorMessage"] as? String)
                 } else if ui["done"] as! Bool {
-                    self.updateProgressHudSuccess()
+                    self.updateProgressHudSuccess(isLogin: true)
                 } else {
                     self.updateProgressHudValue(value: ui["progress"] as? Int)
                 }
             }
         }
-        configureProgressObserver = nc.addObserver(
-            forName: dcNotificationConfigureProgress,
+    }
+
+    private func addProgressHudBackupListener() {
+        let nc = NotificationCenter.default
+        backupProgressObserver = nc.addObserver(
+            forName: dcNotificationImexProgress,
             object: nil,
             queue: nil
         ) {
@@ -665,7 +671,7 @@ class AccountSetupController: UITableViewController {
                 if ui["error"] as! Bool {
                     self.updateProgressHud(error: ui["errorMessage"] as? String)
                 } else if ui["done"] as! Bool {
-                    self.updateProgressHudSuccess()
+                    self.updateProgressHudSuccess(isLogin: false)
                 } else {
                     self.updateProgressHudValue(value: ui["progress"] as? Int)
                 }
@@ -703,6 +709,7 @@ class AccountSetupController: UITableViewController {
         if DcConfig.configured {
             return
         }
+        addProgressHudBackupListener()
         let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
         if !documents.isEmpty {
             logger.info("looking for backup in: \(documents[0])")
@@ -773,14 +780,10 @@ class AccountSetupController: UITableViewController {
             appDelegate.open()
             appDelegate.start()
 
-            self.coordinator?.navigationController.popToRootViewController(animated: true)
             appDelegate.appCoordinator.presentLoginController()
         }))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
         present(alert, animated: true, completion: nil)
-
-
-        coordinator?.navigationController.popToRootViewController(animated: true)
     }
 
     private func handleLoginSuccess() {
@@ -789,6 +792,11 @@ class AccountSetupController: UITableViewController {
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
         appDelegate.registerForPushNotifications()
         initSelectionCells();
+        if let onLoginSuccess = self.coordinator?.onLoginSuccess {
+            onLoginSuccess()
+        } else {
+            self.coordinator?.navigateBack()
+        }
     }
 
     private func initSelectionCells() {

+ 29 - 12
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -10,10 +10,6 @@ class AppCoordinator: NSObject, Coordinator {
     private let chatsTab = 1
     private let settingsTab = 2
 
-    var rootViewController: UIViewController {
-        return tabBarController
-    }
-
     private var childCoordinators: [Coordinator] = []
 
     private lazy var tabBarController: UITabBarController = {
@@ -23,6 +19,16 @@ class AppCoordinator: NSObject, Coordinator {
         return tabBarController
     }()
 
+    private lazy var loginController: UIViewController = {
+        let accountSetupController = AccountSetupController(dcContext: dcContext, editView: false)
+        let accountSetupNav = DcNavigationController(rootViewController: accountSetupController)
+        let coordinator = AccountSetupCoordinator(dcContext: dcContext, navigationController: accountSetupNav)
+        coordinator.onLoginSuccess = presentTabBarController
+        childCoordinators.append(coordinator)
+        accountSetupController.coordinator = coordinator
+        return accountSetupNav
+    }()
+
     // MARK: viewControllers
 
     private lazy var qrController: UIViewController = {
@@ -62,8 +68,12 @@ class AppCoordinator: NSObject, Coordinator {
         self.window = window
         self.dcContext = dcContext
         super.init()
-        window.rootViewController = rootViewController
-        window.makeKeyAndVisible()
+
+        if dcContext.isConfigured() {
+            presentTabBarController()
+        } else {
+            presentLoginController()
+        }
     }
 
     public func start() {
@@ -88,12 +98,14 @@ class AppCoordinator: NSObject, Coordinator {
     }
 
     func presentLoginController() {
-        let accountSetupController = AccountSetupController(dcContext: dcContext, editView: false)
-        let accountSetupNav = DcNavigationController(rootViewController: accountSetupController)
-        let coordinator = AccountSetupCoordinator(dcContext: dcContext, navigationController: accountSetupNav)
-        childCoordinators.append(coordinator)
-        accountSetupController.coordinator = coordinator
-        rootViewController.present(accountSetupNav, animated: false, completion: nil)
+        window.rootViewController = loginController
+        window.makeKeyAndVisible()
+    }
+
+    func presentTabBarController() {
+        window.rootViewController = tabBarController
+        window.makeKeyAndVisible()
+        showTab(index: chatsTab)
     }
 }
 
@@ -216,6 +228,7 @@ class EditSettingsCoordinator: Coordinator {
 class AccountSetupCoordinator: Coordinator {
     var dcContext: DcContext
     let navigationController: UINavigationController
+    var onLoginSuccess: (() -> Void)?
 
     init(dcContext: DcContext, navigationController: UINavigationController) {
         self.dcContext = dcContext
@@ -237,6 +250,10 @@ class AccountSetupCoordinator: Coordinator {
         let securitySettingsController = SecuritySettingsController(title: String.localized("login_imap_security"), type: SecurityType.SMTPSecurity)
         navigationController.pushViewController(securitySettingsController, animated: true)
     }
+
+    func navigateBack() {
+        navigationController.popViewController(animated: true)
+    }
 }
 
 class NewChatCoordinator: Coordinator {