Bläddra i källkod

remove AccountSetupCoordinator

B. Petersen 5 år sedan
förälder
incheckning
4eef999ec4

+ 42 - 9
deltachat-ios/Controller/AccountSetupController.swift

@@ -3,14 +3,12 @@ import UIKit
 import DcCore
 
 class AccountSetupController: UITableViewController, ProgressAlertHandler {
-
-    weak var coordinator: AccountSetupCoordinator?
-
     private let dcContext: DcContext
     private var skipOauth = false
     private var backupProgressObserver: Any?
     var progressObserver: Any?
     var onProgressSuccess: VoidFunction? // not needed here
+    var onLoginSuccess: (() -> Void)?
 
     private var oauth2Observer: Any?
 
@@ -484,11 +482,11 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         case tagAdvancedCell:
             toggleAdvancedSection()
         case tagImapSecurityCell:
-            coordinator?.showImapSecurityOptions()
+            showImapSecurityOptions()
         case tagSmtpSecurityCell:
-            coordinator?.showSmptpSecurityOptions()
+            showSmptpSecurityOptions()
         case tagCertCheckCell:
-            coordinator?.showCertCheckOptions()
+            showCertCheckOptions()
         default:
             break
         }
@@ -796,10 +794,10 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
         appDelegate.registerForPushNotifications()
         initSelectionCells();
-        if let onLoginSuccess = self.coordinator?.onLoginSuccess {
+        if let onLoginSuccess = self.onLoginSuccess {
             onLoginSuccess()
         } else {
-            self.coordinator?.navigateBack()
+            self.navigateBack()
         }
     }
 
@@ -827,7 +825,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         guard let provider = provider else {
             return
         }
-        coordinator?.openProviderInfo(provider: provider)
+        openProviderInfo(provider: provider)
     }
 
     func resignCell(cell: UITableViewCell) {
@@ -846,6 +844,41 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         }
     }
 
+    // MARK: - coordinator
+    func showCertCheckOptions() {
+        if let navigationController = self.parent as? UINavigationController {
+            let certificateCheckController = CertificateCheckController(dcContext: dcContext, sectionTitle: String.localized("login_certificate_checks"))
+            navigationController.pushViewController(certificateCheckController, animated: true)
+        }
+    }
+
+    func showImapSecurityOptions() {
+        if let navigationController = self.parent as? UINavigationController {
+            let securitySettingsController = SecuritySettingsController(dcContext: dcContext, title: String.localized("login_imap_security"),
+                                                                          type: SecurityType.IMAPSecurity)
+            navigationController.pushViewController(securitySettingsController, animated: true)
+        }
+    }
+
+    func showSmptpSecurityOptions() {
+        if let navigationController = self.parent as? UINavigationController {
+            let securitySettingsController = SecuritySettingsController(dcContext: dcContext,
+                                                                        title: String.localized("login_imap_security"),
+                                                                        type: SecurityType.SMTPSecurity)
+            navigationController.pushViewController(securitySettingsController, animated: true)
+        }
+    }
+
+    func openProviderInfo(provider: DcProvider) {
+        guard let url = URL(string: provider.getOverviewPage) else { return }
+        UIApplication.shared.open(url)
+    }
+
+    func navigateBack() {
+        if let navigationController = self.parent as? UINavigationController {
+            navigationController.popViewController(animated: true)
+        }
+    }
 }
 
 // MARK: - UITextFieldDelegate

+ 0 - 3
deltachat-ios/Controller/EditSettingsController.swift

@@ -131,9 +131,6 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
             tableView.deselectRow(at: indexPath, animated: true)
             guard let nc = navigationController else { return }
             let accountSetupVC = AccountSetupController(dcContext: dcContext, editView: true)
-            let coordinator = AccountSetupCoordinator(dcContext: dcContext, navigationController: nc)
-            self.childCoordinators = coordinator
-            accountSetupVC.coordinator = coordinator
             nc.pushViewController(accountSetupVC, animated: true)
         }
     }

+ 2 - 44
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -28,15 +28,12 @@ class AppCoordinator: NSObject, Coordinator {
     private lazy var loginController: UIViewController = {
         let accountSetupController = AccountSetupController(dcContext: dcContext, editView: false)
         let nav = UINavigationController(rootViewController: accountSetupController)
-        let coordinator = AccountSetupCoordinator(dcContext: dcContext, navigationController: nav)
-        coordinator.onLoginSuccess = {
+        accountSetupController.onLoginSuccess = {
             [unowned self] in
             self.loginController.dismiss(animated: true) {
                 self.presentTabBarController()
             }
         }
-        childCoordinators.append(coordinator)
-        accountSetupController.coordinator = coordinator
         return nav
     }()
 
@@ -161,7 +158,7 @@ extension AppCoordinator: WelcomeCoordinator {
                 style: .done,
                 target: self, action: #selector(cancelButtonPressed(_:))
             )
-            loginController.coordinator?.onLoginSuccess = handleLoginSuccess
+            loginController.onLoginSuccess = handleLoginSuccess
         }
         loginController.modalPresentationStyle = .fullScreen
         welcomeController?.present(loginController, animated: true, completion: nil)
@@ -231,45 +228,6 @@ class EditSettingsCoordinator: Coordinator {
     }
 }
 
-// MARK: - AccountSetupCoordinator
-class AccountSetupCoordinator: Coordinator {
-    var dcContext: DcContext
-    let navigationController: UINavigationController
-    var onLoginSuccess: (() -> Void)?
-
-    init(dcContext: DcContext, navigationController: UINavigationController) {
-        self.dcContext = dcContext
-        self.navigationController = navigationController
-    }
-
-    func showCertCheckOptions() {
-        let certificateCheckController = CertificateCheckController(dcContext: dcContext, sectionTitle: String.localized("login_certificate_checks"))
-        navigationController.pushViewController(certificateCheckController, animated: true)
-    }
-
-    func showImapSecurityOptions() {
-        let securitySettingsController = SecuritySettingsController(dcContext: dcContext, title: String.localized("login_imap_security"),
-                                                                      type: SecurityType.IMAPSecurity)
-        navigationController.pushViewController(securitySettingsController, animated: true)
-    }
-
-    func showSmptpSecurityOptions() {
-        let securitySettingsController = SecuritySettingsController(dcContext: dcContext,
-                                                                    title: String.localized("login_imap_security"),
-                                                                    type: SecurityType.SMTPSecurity)
-        navigationController.pushViewController(securitySettingsController, animated: true)
-    }
-
-    func openProviderInfo(provider: DcProvider) {
-        guard let url = URL(string: provider.getOverviewPage) else { return }
-        UIApplication.shared.open(url)
-    }
-
-    func navigateBack() {
-        navigationController.popViewController(animated: true)
-    }
-}
-
 // MARK: - ChatViewCoordinator
 class ChatViewCoordinator: NSObject, Coordinator {
     var dcContext: DcContext