Browse Source

remove WelcomeCoordinator

B. Petersen 5 years ago
parent
commit
34806b808a

+ 7 - 5
deltachat-ios/Controller/WelcomeViewController.swift

@@ -2,8 +2,6 @@ import UIKit
 import DcCore
 
 class WelcomeViewController: UIViewController, ProgressAlertHandler {
-
-    weak var coordinator: WelcomeCoordinator?
     private let dcContext: DcContext
     private var scannedQrCode: String?
     var progressObserver: Any?
@@ -18,7 +16,9 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     private lazy var welcomeView: WelcomeContentView = {
         let view = WelcomeContentView()
         view.onLogin = { [unowned self] in
-            self.coordinator?.presentLogin()
+            if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+                appDelegate.appCoordinator.presentLogin()
+            }
         }
         view.onScanQRCode  = { [unowned self] in
             self.showQRReader()
@@ -34,8 +34,10 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     init(dcContext: DcContext) {
         self.dcContext = dcContext
         super.init(nibName: nil, bundle: nil)
-        onProgressSuccess = {[unowned self] in
-            self.coordinator?.handleQRAccountCreationSuccess()
+        onProgressSuccess = {
+            if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+                appDelegate.appCoordinator.handleQRAccountCreationSuccess()
+            }
         }
     }
 

+ 10 - 31
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -127,7 +127,7 @@ class AppCoordinator: NSObject, Coordinator {
         // but even when this changes in ios, we need the reset as we allow account-deletion also in-app.
         UIApplication.shared.applicationIconBadgeNumber = 0
 
-        let wc = makeWelcomeController()
+        let wc = WelcomeViewController(dcContext: dcContext)
         self.welcomeController = wc
         window.rootViewController = wc
         window.makeKeyAndVisible()
@@ -140,23 +140,13 @@ class AppCoordinator: NSObject, Coordinator {
         showTab(index: chatsTab)
     }
 
-    private func makeWelcomeController() -> WelcomeViewController {
-        let welcomeController = WelcomeViewController(dcContext: dcContext)
-        welcomeController.coordinator = self
-        return welcomeController
-    }
-}
-
-// MARK: - WelcomeCoordinator
-extension AppCoordinator: WelcomeCoordinator {
-
     func presentLogin() {
         // add cancel button item to accountSetupController
         if let nav = loginController as? UINavigationController, let loginController = nav.topViewController as? AccountSetupController {
             loginController.navigationItem.leftBarButtonItem = UIBarButtonItem(
                 title: String.localized("cancel"),
                 style: .done,
-                target: self, action: #selector(cancelButtonPressed(_:))
+                target: self, action: #selector(loginCancelButtonPressed)
             )
             loginController.onLoginSuccess = handleLoginSuccess
         }
@@ -164,6 +154,14 @@ extension AppCoordinator: WelcomeCoordinator {
         welcomeController?.present(loginController, animated: true, completion: nil)
     }
 
+    @objc private func loginCancelButtonPressed(_ sender: UIBarButtonItem) {
+        loginController.dismiss(animated: true, completion: nil)
+    }
+
+    private func handleLoginSuccess() {
+        presentTabBarController()
+    }
+
     func handleQRAccountCreationSuccess() {
         let profileInfoController = ProfileInfoViewController(context: dcContext)
         let profileInfoNav = UINavigationController(rootViewController: profileInfoController)
@@ -171,23 +169,4 @@ extension AppCoordinator: WelcomeCoordinator {
         profileInfoController.onClose = handleLoginSuccess
         welcomeController?.present(profileInfoNav, animated: true, completion: nil)
     }
-
-    func handleLoginSuccess() {
-        presentTabBarController()
-    }
-
-    @objc private func cancelButtonPressed(_ sender: UIBarButtonItem) {
-        loginController.dismiss(animated: true, completion: nil)
-    }
-}
-
-/*
- boilerplate - I tend to remove that interface (cyberta)
- */
-
-
-protocol WelcomeCoordinator: class {
-    func presentLogin()
-    func handleLoginSuccess()
-    func handleQRAccountCreationSuccess()
 }