فهرست منبع

remove QrViewCoordinator

B. Petersen 5 سال پیش
والد
کامیت
674198565b
2فایلهای تغییر یافته به همراه16 افزوده شده و 27 حذف شده
  1. 16 5
      deltachat-ios/Controller/QrPageController.swift
  2. 0 22
      deltachat-ios/Coordinator/AppCoordinator.swift

+ 16 - 5
deltachat-ios/Controller/QrPageController.swift

@@ -2,8 +2,6 @@ import UIKit
 import DcCore
 
 class QrPageController: UIPageViewController, ProgressAlertHandler {
-
-    weak var coordinator: QrViewCoordinator?
     private let dcContext: DcContext
     weak var progressAlert: UIAlertController?
     var progressObserver: Any?
@@ -80,6 +78,19 @@ class QrPageController: UIPageViewController, ProgressAlertHandler {
         qrReader.delegate = self
         return qrReader
     }
+
+    // MARK: - coordinator
+    func showChats() {
+        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+            appDelegate.appCoordinator.showTab(index: appDelegate.appCoordinator.chatsTab)
+        }
+    }
+
+    func showChat(chatId: Int) {
+        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+            appDelegate.appCoordinator.showChat(chatId: chatId)
+        }
+    }
 }
 
 // MARK: - UIPageViewControllerDataSource, UIPageViewControllerDelegate
@@ -113,7 +124,7 @@ extension QrPageController: UIPageViewControllerDataSource, UIPageViewController
 extension QrPageController: QrCodeReaderDelegate {
 
     func handleQrCode(_ code: String) {
-        self.coordinator?.showChats()
+        self.showChats()
         let qrParsed: DcLot = self.dcContext.checkQR(qrCode: code)
         let state = Int32(qrParsed.state)
         switch state {
@@ -145,7 +156,7 @@ extension QrPageController: QrCodeReaderDelegate {
             let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
                 let chatId = self.dcContext.createChatByContactId(contactId: qrParsed.id)
-                self.coordinator?.showChat(chatId: chatId)
+                self.showChat(chatId: chatId)
             }))
             alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
             present(alert, animated: true, completion: nil)
@@ -205,7 +216,7 @@ extension QrPageController: QrCodeReaderDelegate {
                 DispatchQueue.main.async {
                     self.progressAlert?.dismiss(animated: true, completion: nil)
                     if chatId != 0 {
-                        self.coordinator?.showChat(chatId: chatId)
+                        self.showChat(chatId: chatId)
                     } else if errorString != nil {
                         self.showErrorAlert(error: errorString!)
                     }

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

@@ -46,9 +46,6 @@ class AppCoordinator: NSObject, Coordinator {
     private lazy var qrPageController: UINavigationController = {
         let pageController = QrPageController(dcContext: dcContext)
         let nav = UINavigationController(rootViewController: pageController)
-        let coordinator = QrViewCoordinator(navigationController: nav)
-        self.childCoordinators.append(coordinator)
-        pageController.coordinator = coordinator
         let settingsImage = UIImage(named: "qr_code")
         nav.tabBarItem = UITabBarItem(title: String.localized("qr_code"), image: settingsImage, tag: qrTab)
         return nav
@@ -220,25 +217,6 @@ class MailboxCoordinator: ChatViewCoordinator {
     }
 }
 
-class QrViewCoordinator: Coordinator {
-    var navigationController: UINavigationController
-    init(navigationController: UINavigationController) {
-        self.navigationController = navigationController
-    }
-
-    func showChats() {
-        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-            appDelegate.appCoordinator.showTab(index: appDelegate.appCoordinator.chatsTab)
-        }
-    }
-
-    func showChat(chatId: Int) {
-        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-            appDelegate.appCoordinator.showChat(chatId: chatId)
-        }
-    }
-}
-
 class ChatListCoordinator: Coordinator {
     var dcContext: DcContext
     let navigationController: UINavigationController