Selaa lähdekoodia

remove ChatListCoordinator

B. Petersen 5 vuotta sitten
vanhempi
commit
a1454032eb

+ 37 - 8
deltachat-ios/Controller/ChatListController.swift

@@ -2,7 +2,6 @@ import UIKit
 import DcCore
 
 class ChatListController: UITableViewController {
-    weak var coordinator: ChatListCoordinator?
     let viewModel: ChatListViewModelProtocol
     let dcContext: DcContext
 
@@ -99,7 +98,7 @@ class ChatListController: UITableViewController {
             object: nil,
             queue: nil) { notification in
                 if let chatId = notification.userInfo?["chat_id"] as? Int {
-                    self.coordinator?.showChat(chatId: chatId)
+                    self.showChat(chatId: chatId)
                 }
         }
         deleteChatObserver = nc.addObserver(
@@ -141,7 +140,7 @@ class ChatListController: UITableViewController {
 
     // MARK: - actions
     @objc func didPressNewChat() {
-        coordinator?.showNewChatController()
+        showNewChatController()
     }
 
     @objc func cancelButtonPressed() {
@@ -214,14 +213,14 @@ class ChatListController: UITableViewController {
         case .chat(let chatData):
             let chatId = chatData.chatId
             if chatId == DC_CHAT_ID_ARCHIVED_LINK {
-                coordinator?.showArchive()
+                showArchive()
             } else {
-                coordinator?.showChat(chatId: chatId)
+                showChat(chatId: chatId)
             }
         case .contact(let contactData):
             let contactId = contactData.contactId
             if let chatId = contactData.chatId {
-                coordinator?.showChat(chatId: chatId)
+                showChat(chatId: chatId)
             } else {
                 self.askToChatWith(contactId: contactId)
             }
@@ -318,7 +317,7 @@ class ChatListController: UITableViewController {
         let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
         alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
             let chat = self.dcContext.createChatByMessageId(msgId)
-            self.coordinator?.showChat(chatId: chat.id)
+            self.showChat(chatId: chat.id)
         }))
         alert.addAction(UIAlertAction(title: String.localized("not_now"), style: .default, handler: { _ in
             dcContact.marknoticed()
@@ -340,7 +339,7 @@ class ChatListController: UITableViewController {
             title: String.localized("start_chat"),
             style: .default,
             handler: { _ in
-                self.coordinator?.showNewChat(contactId: contactId)
+                self.showNewChat(contactId: contactId)
         }))
         alert.addAction(UIAlertAction(
             title: String.localized("cancel"),
@@ -360,6 +359,36 @@ class ChatListController: UITableViewController {
         let row = viewModel.deleteChat(chatId: chatId)
         tableView.deleteRows(at: [IndexPath(row: row, section: 0)], with: .fade)
     }
+
+    // MARK: - coordinator
+    func showNewChatController() {
+        if let navigationController = self.parent as? UINavigationController {
+            let newChatVC = NewChatViewController(dcContext: dcContext)
+            navigationController.pushViewController(newChatVC, animated: true)
+        }
+    }
+
+    func showChat(chatId: Int) {
+        if let navigationController = self.parent as? UINavigationController {
+            let chatVC = ChatViewController(dcContext: dcContext, chatId: chatId)
+            let coordinator = ChatViewCoordinator(dcContext: dcContext, navigationController: navigationController, chatId: chatId)
+            chatVC.coordinator = coordinator
+            navigationController.pushViewController(chatVC, animated: true)
+        }
+    }
+
+    func showArchive() {
+        if let navigationController = self.parent as? UINavigationController {
+            let viewModel = ChatListViewModel(dcContext: dcContext, isArchive: true)
+            let controller = ChatListController(dcContext: dcContext, viewModel: viewModel)
+            navigationController.pushViewController(controller, animated: true)
+        }
+    }
+
+    func showNewChat(contactId: Int) {
+        let chatId = dcContext.createChatByContactId(contactId: contactId)
+        showChat(chatId: Int(chatId))
+    }
 }
 
 // MARK: - uisearchbardelegate

+ 0 - 2
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -338,8 +338,6 @@ class ContactDetailViewController: UITableViewController {
             navigationController.popToRootViewController(animated: false) // in main ChatList now
             let chatlistVM = ChatListViewModel(dcContext: viewModel.context, isArchive: true)
             let controller = ChatListController(dcContext: viewModel.context, viewModel: chatlistVM)
-            let coordinator = ChatListCoordinator(dcContext: viewModel.context, navigationController: navigationController)
-            controller.coordinator = coordinator
             navigationController.pushViewController(controller, animated: false)
         }
 

+ 0 - 2
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -263,8 +263,6 @@ class GroupChatDetailViewController: UIViewController {
                 navigationController.popToRootViewController(animated: false) // in main ChatList now
                 let viewModel = ChatListViewModel(dcContext: dcContext, isArchive: true)
                 let controller = ChatListController(dcContext: dcContext, viewModel: viewModel)
-                let coordinator = ChatListCoordinator(dcContext: dcContext, navigationController: navigationController)
-                controller.coordinator = coordinator
                 navigationController.pushViewController(controller, animated: false)
             }
 

+ 1 - 43
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -56,9 +56,6 @@ class AppCoordinator: NSObject, Coordinator {
         let nav = UINavigationController(rootViewController: controller)
         let settingsImage = UIImage(named: "ic_chat")
         nav.tabBarItem = UITabBarItem(title: String.localized("pref_chats"), image: settingsImage, tag: chatsTab)
-        let coordinator = ChatListCoordinator(dcContext: dcContext, navigationController: nav)
-        self.childCoordinators.append(coordinator)
-        controller.coordinator = coordinator
         return nav
     }()
 
@@ -115,7 +112,7 @@ class AppCoordinator: NSObject, Coordinator {
         }
 
         if let rootController = navController.viewControllers.first as? ChatListController {
-            rootController.coordinator?.showChat(chatId: chatId)
+            rootController.showChat(chatId: chatId)
         }
     }
 
@@ -213,45 +210,6 @@ class MailboxCoordinator: ChatViewCoordinator {
     }
 }
 
-class ChatListCoordinator: Coordinator {
-    var dcContext: DcContext
-    let navigationController: UINavigationController
-
-    var childCoordinators: [Coordinator] = []
-
-    init(dcContext: DcContext, navigationController: UINavigationController) {
-        self.dcContext = dcContext
-        self.navigationController = navigationController
-    }
-
-    func showNewChatController() {
-        let newChatVC = NewChatViewController(dcContext: dcContext)
-        navigationController.pushViewController(newChatVC, animated: true)
-    }
-
-    func showChat(chatId: Int) {
-        let chatVC = ChatViewController(dcContext: dcContext, chatId: chatId)
-        let coordinator = ChatViewCoordinator(dcContext: dcContext, navigationController: navigationController, chatId: chatId)
-        childCoordinators.append(coordinator)
-        chatVC.coordinator = coordinator
-        navigationController.pushViewController(chatVC, animated: true)
-    }
-
-    func showArchive() {
-        let viewModel = ChatListViewModel(dcContext: dcContext, isArchive: true)
-        let controller = ChatListController(dcContext: dcContext, viewModel: viewModel)
-        let coordinator = ChatListCoordinator(dcContext: dcContext, navigationController: navigationController)
-        childCoordinators.append(coordinator)
-        controller.coordinator = coordinator
-        navigationController.pushViewController(controller, animated: true)
-    }
-
-    func showNewChat(contactId: Int) {
-        let chatId = dcContext.createChatByContactId(contactId: contactId)
-        showChat(chatId: Int(chatId))
-    }
-}
-
 // MARK: - EditSettingsCoordinator
 class EditSettingsCoordinator: Coordinator {
     var dcContext: DcContext