Эх сурвалжийг харах

remove SettingsCoordinator

B. Petersen 5 жил өмнө
parent
commit
56535ff582

+ 67 - 9
deltachat-ios/Controller/SettingsController.swift

@@ -1,6 +1,7 @@
 import JGProgressHUD
 import UIKit
 import DcCore
+import DBDebugToolkit
 
 internal final class SettingsViewController: UITableViewController {
 
@@ -25,8 +26,6 @@ internal final class SettingsViewController: UITableViewController {
         case autodel = 11
     }
 
-    weak var coordinator: SettingsCoordinator?
-
     private var dcContext: DcContext
 
     private let externalPathDescr = "File Sharing/Delta Chat"
@@ -302,18 +301,18 @@ internal final class SettingsViewController: UITableViewController {
         tableView.deselectRow(at: indexPath, animated: false) // to achieve highlight effect
 
         switch cellTag {
-        case .profile: self.coordinator?.showEditSettingsController()
-        case .contactRequest: self.coordinator?.showContactRequests()
-        case .showEmails: coordinator?.showClassicMail()
-        case .blockedContacts: coordinator?.showBlockedContacts()
-        case .autodel: coordinator?.showAutodelOptions()
+        case .profile: showEditSettingsController()
+        case .contactRequest: showContactRequests()
+        case .showEmails: showClassicMail()
+        case .blockedContacts: showBlockedContacts()
+        case .autodel: showAutodelOptions()
         case .notifications: break
         case .receiptConfirmation: break
         case .autocryptPreferences: break
         case .sendAutocryptMessage: sendAutocryptSetupMessage()
         case .exportBackup: createBackup()
         case .advanced: showAdvancedDialog()
-        case .help: coordinator?.showHelp()
+        case .help: showHelp()
         }
     }
 
@@ -412,7 +411,7 @@ internal final class SettingsViewController: UITableViewController {
         }))
 
         let logAction = UIAlertAction(title: String.localized("pref_view_log"), style: .default, handler: { [unowned self] _ in
-            self.coordinator?.showDebugToolkit()
+            self.showDebugToolkit()
         })
         alert.addAction(logAction)
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
@@ -442,4 +441,63 @@ internal final class SettingsViewController: UITableViewController {
 
         autodelCell.detailTextLabel?.text = autodelSummary()
     }
+
+    // MARK: - coordinator
+
+    func showEditSettingsController() {
+        if let navigationController = self.parent as? UINavigationController {
+            let editController = EditSettingsController(dcContext: dcContext)
+            let coordinator = EditSettingsCoordinator(dcContext: dcContext, navigationController: navigationController)
+            editController.coordinator = coordinator
+            navigationController.pushViewController(editController, animated: true)
+        }
+    }
+
+    func showClassicMail() {
+        if let navigationController = self.parent as? UINavigationController {
+            let settingsClassicViewController = SettingsClassicViewController(dcContext: dcContext)
+            navigationController.pushViewController(settingsClassicViewController, animated: true)
+        }
+    }
+
+    func showBlockedContacts() {
+        if let navigationController = self.parent as? UINavigationController {
+            let blockedContactsController = BlockedContactsViewController()
+            navigationController.pushViewController(blockedContactsController, animated: true)
+        }
+    }
+
+    func showAutodelOptions() {
+        if let navigationController = self.parent as? UINavigationController {
+            let settingsAutodelOverviewController = SettingsAutodelOverviewController(dcContext: dcContext)
+            navigationController.pushViewController(settingsAutodelOverviewController, animated: true)
+        }
+    }
+
+    func showContactRequests() {
+        if let navigationController = self.parent as? UINavigationController {
+            let deaddropViewController = MailboxViewController(dcContext: dcContext, chatId: Int(DC_CHAT_ID_DEADDROP))
+            let deaddropCoordinator = MailboxCoordinator(dcContext: dcContext, navigationController: navigationController)
+            deaddropViewController.coordinator = deaddropCoordinator
+            navigationController.pushViewController(deaddropViewController, animated: true)
+        }
+    }
+
+    func showHelp() {
+        if let navigationController = self.parent as? UINavigationController {
+            let helpViewController = HelpViewController()
+            navigationController.pushViewController(helpViewController, animated: true)
+        }
+    }
+
+    func showDebugToolkit() {
+        DBDebugToolkit.setup(with: [])  // emtpy array will override default device shake trigger
+        DBDebugToolkit.setupCrashReporting()
+        let info: [DBCustomVariable] = dcContext.getInfo().map { kv in
+            let value = kv.count > 1 ? kv[1] : ""
+            return DBCustomVariable(name: kv[0], value: value)
+        }
+        DBDebugToolkit.add(info)
+        DBDebugToolkit.showMenu()
+    }
 }

+ 0 - 64
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -3,7 +3,6 @@ import KK_ALCameraViewController
 import Photos
 import MobileCoreServices
 import DcCore
-import DBDebugToolkit
 
 // MARK: - AppCoordinator
 class AppCoordinator: NSObject, Coordinator {
@@ -68,9 +67,6 @@ class AppCoordinator: NSObject, Coordinator {
         let nav = UINavigationController(rootViewController: controller)
         let settingsImage = UIImage(named: "settings")
         nav.tabBarItem = UITabBarItem(title: String.localized("menu_settings"), image: settingsImage, tag: settingsTab)
-        let coordinator = SettingsCoordinator(dcContext: dcContext, navigationController: nav)
-        self.childCoordinators.append(coordinator)
-        controller.coordinator = coordinator
         return nav
     }()
 
@@ -256,66 +252,6 @@ class ChatListCoordinator: Coordinator {
     }
 }
 
-// MARK: - SettingsCoordinator
-class SettingsCoordinator: Coordinator {
-    let dcContext: DcContext
-    let navigationController: UINavigationController
-
-    var childCoordinators: [Coordinator] = []
-
-    init(dcContext: DcContext, navigationController: UINavigationController) {
-        self.dcContext = dcContext
-        self.navigationController = navigationController
-    }
-
-    func showEditSettingsController() {
-        let editController = EditSettingsController(dcContext: dcContext)
-        let coordinator = EditSettingsCoordinator(dcContext: dcContext, navigationController: navigationController)
-        childCoordinators.append(coordinator)
-        editController.coordinator = coordinator
-        navigationController.pushViewController(editController, animated: true)
-    }
-
-    func showClassicMail() {
-        let settingsClassicViewController = SettingsClassicViewController(dcContext: dcContext)
-        navigationController.pushViewController(settingsClassicViewController, animated: true)
-    }
-
-    func showBlockedContacts() {
-        let blockedContactsController = BlockedContactsViewController()
-        navigationController.pushViewController(blockedContactsController, animated: true)
-    }
-
-    func showAutodelOptions() {
-        let settingsAutodelOverviewController = SettingsAutodelOverviewController(dcContext: dcContext)
-        navigationController.pushViewController(settingsAutodelOverviewController, animated: true)
-    }
-
-    func showContactRequests() {
-        let deaddropViewController = MailboxViewController(dcContext: dcContext, chatId: Int(DC_CHAT_ID_DEADDROP))
-        let deaddropCoordinator = MailboxCoordinator(dcContext: dcContext, navigationController: navigationController)
-        deaddropViewController.coordinator = deaddropCoordinator
-        childCoordinators.append(deaddropCoordinator)
-        navigationController.pushViewController(deaddropViewController, animated: true)
-    }
-
-    func showHelp() {
-        let helpViewController = HelpViewController()
-        navigationController.pushViewController(helpViewController, animated: true)
-    }
-
-    func showDebugToolkit() {
-        DBDebugToolkit.setup(with: [])  // emtpy array will override default device shake trigger
-        DBDebugToolkit.setupCrashReporting()
-        let info: [DBCustomVariable] = dcContext.getInfo().map { kv in
-            let value = kv.count > 1 ? kv[1] : ""
-            return DBCustomVariable(name: kv[0], value: value)
-        }
-        DBDebugToolkit.add(info)
-        DBDebugToolkit.showMenu()
-    }
-}
-
 // MARK: - EditSettingsCoordinator
 class EditSettingsCoordinator: Coordinator {
     var dcContext: DcContext