Prechádzať zdrojové kódy

remove NewChatCoordinator

B. Petersen 5 rokov pred
rodič
commit
36085e346c

+ 48 - 14
deltachat-ios/Controller/NewChatViewController.swift

@@ -4,8 +4,6 @@ import UIKit
 import DcCore
 import DcCore
 
 
 class NewChatViewController: UITableViewController {
 class NewChatViewController: UITableViewController {
-    weak var coordinator: NewChatCoordinator?
-
     private let dcContext: DcContext
     private let dcContext: DcContext
 
 
     private let sectionNew = 0
     private let sectionNew = 0
@@ -214,11 +212,11 @@ class NewChatViewController: UITableViewController {
 
 
         if section == sectionNew {
         if section == sectionNew {
             if row == sectionNewRowNewGroup {
             if row == sectionNewRowNewGroup {
-                coordinator?.showNewGroupController(isVerified: false)
+                showNewGroupController(isVerified: false)
             } else if row == sectionNewRowNewVerifiedGroup {
             } else if row == sectionNewRowNewVerifiedGroup {
-                coordinator?.showNewGroupController(isVerified: true)
+                showNewGroupController(isVerified: true)
             } else if row == sectionNewRowNewContact {
             } else if row == sectionNewRowNewContact {
-                coordinator?.showNewContactController()
+                showNewContactController()
             }
             }
         } else if section == sectionImportedContacts {
         } else if section == sectionImportedContacts {
             if deviceContactAccessGranted {
             if deviceContactAccessGranted {
@@ -238,19 +236,16 @@ class NewChatViewController: UITableViewController {
             let edit = UITableViewRowAction(style: .normal, title: String.localized("info")) { [unowned self] _, _ in
             let edit = UITableViewRowAction(style: .normal, title: String.localized("info")) { [unowned self] _, _ in
                 if self.searchController.isActive {
                 if self.searchController.isActive {
                     self.searchController.dismiss(animated: false) {
                     self.searchController.dismiss(animated: false) {
-                        self.coordinator?.showContactDetail(contactId: contactId)
+                        self.showContactDetail(contactId: contactId)
                     }
                     }
                 } else {
                 } else {
-                    self.coordinator?.showContactDetail(contactId: contactId)
+                    self.showContactDetail(contactId: contactId)
                 }
                 }
             }
             }
 
 
             let delete = UITableViewRowAction(style: .destructive, title: String.localized("delete")) { [unowned self] _, _ in
             let delete = UITableViewRowAction(style: .destructive, title: String.localized("delete")) { [unowned self] _, _ in
-                //handle delete
-                if let dcContext = self.coordinator?.dcContext {
-                    let contactId = self.contactIdByRow(indexPath.row)
-                    self.askToDeleteContact(contactId: contactId, context: dcContext)
-                }
+                let contactId = self.contactIdByRow(indexPath.row)
+                self.askToDeleteContact(contactId: contactId, context: self.dcContext)
             }
             }
 
 
             edit.backgroundColor = DcColors.primary
             edit.backgroundColor = DcColors.primary
@@ -295,7 +290,7 @@ class NewChatViewController: UITableViewController {
     private func askToChatWith(contactId: Int) {
     private func askToChatWith(contactId: Int) {
         if dcContext.getChatIdByContactId(contactId: contactId) != 0 {
         if dcContext.getChatIdByContactId(contactId: contactId) != 0 {
             self.dismiss(animated: true, completion: nil)
             self.dismiss(animated: true, completion: nil)
-            self.coordinator?.showNewChat(contactId: contactId)
+            self.showNewChat(contactId: contactId)
         } else {
         } else {
             let dcContact = DcContact(id: contactId)
             let dcContact = DcContact(id: contactId)
             let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
             let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
@@ -303,7 +298,7 @@ class NewChatViewController: UITableViewController {
                                           preferredStyle: .safeActionSheet)
                                           preferredStyle: .safeActionSheet)
             alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
             alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
                 self.dismiss(animated: true, completion: nil)
                 self.dismiss(animated: true, completion: nil)
-                self.coordinator?.showNewChat(contactId: contactId)
+                self.showNewChat(contactId: contactId)
             }))
             }))
             alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
             alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
                 self.reactivateSearchBarIfNeeded()
                 self.reactivateSearchBarIfNeeded()
@@ -336,6 +331,45 @@ class NewChatViewController: UITableViewController {
         tableView.reloadData()
         tableView.reloadData()
         tableView.scrollToTop()
         tableView.scrollToTop()
     }
     }
+
+    // MARK: - coordinator
+
+    func showNewGroupController(isVerified: Bool) {
+        if let navigationController = self.parent as? UINavigationController {
+            let newGroupController = NewGroupController(dcContext: dcContext, isVerified: isVerified)
+            navigationController.pushViewController(newGroupController, animated: true)
+        }
+    }
+
+    func showNewContactController() {
+        if let navigationController = self.parent as? UINavigationController {
+            let newContactController = NewContactController(dcContext: dcContext)
+            navigationController.pushViewController(newContactController, animated: true)
+        }
+    }
+
+    func showNewChat(contactId: Int) {
+        let chatId = dcContext.createChatByContactId(contactId: contactId)
+        showChat(chatId: Int(chatId))
+    }
+
+    func showChat(chatId: Int) {
+        if let navigationController = self.parent as? UINavigationController {
+            let chatViewController = ChatViewController(dcContext: dcContext, chatId: chatId)
+            let coordinator = ChatViewCoordinator(dcContext: dcContext, navigationController: navigationController, chatId: chatId)
+            chatViewController.coordinator = coordinator
+            navigationController.pushViewController(chatViewController, animated: true)
+            navigationController.viewControllers.remove(at: 1)
+        }
+    }
+
+    func showContactDetail(contactId: Int) {
+        if let navigationController = self.parent as? UINavigationController {
+            let viewModel = ContactDetailViewModel(contactId: contactId, chatId: nil, context: dcContext)
+            let contactDetailController = ContactDetailViewController(viewModel: viewModel)
+            navigationController.pushViewController(contactDetailController, animated: true)
+        }
+    }
 }
 }
 
 
 extension NewChatViewController: ContactListDelegate {
 extension NewChatViewController: ContactListDelegate {

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

@@ -252,9 +252,6 @@ class ChatListCoordinator: Coordinator {
 
 
     func showNewChatController() {
     func showNewChatController() {
         let newChatVC = NewChatViewController(dcContext: dcContext)
         let newChatVC = NewChatViewController(dcContext: dcContext)
-        let coordinator = NewChatCoordinator(dcContext: dcContext, navigationController: navigationController)
-        childCoordinators.append(coordinator)
-        newChatVC.coordinator = coordinator
         navigationController.pushViewController(newChatVC, animated: true)
         navigationController.pushViewController(newChatVC, animated: true)
     }
     }
 
 
@@ -401,50 +398,6 @@ class AccountSetupCoordinator: Coordinator {
     }
     }
 }
 }
 
 
-// MARK: - NewChatCoordinator
-class NewChatCoordinator: Coordinator {
-    var dcContext: DcContext
-    let navigationController: UINavigationController
-
-    private var childCoordinators: [Coordinator] = []
-
-    init(dcContext: DcContext, navigationController: UINavigationController) {
-        self.dcContext = dcContext
-        self.navigationController = navigationController
-    }
-
-    func showNewGroupController(isVerified: Bool) {
-        let newGroupController = NewGroupController(dcContext: dcContext, isVerified: isVerified)
-        navigationController.pushViewController(newGroupController, animated: true)
-    }
-
-    func showNewContactController() {
-        let newContactController = NewContactController(dcContext: dcContext)
-        navigationController.pushViewController(newContactController, animated: true)
-    }
-
-    func showNewChat(contactId: Int) {
-        let chatId = dcContext.createChatByContactId(contactId: contactId)
-        showChat(chatId: Int(chatId))
-    }
-
-    func showChat(chatId: Int) {
-        let chatViewController = ChatViewController(dcContext: dcContext, chatId: chatId)
-        let coordinator = ChatViewCoordinator(dcContext: dcContext, navigationController: navigationController, chatId: chatId)
-        childCoordinators.append(coordinator)
-        chatViewController.coordinator = coordinator
-        navigationController.pushViewController(chatViewController, animated: true)
-        navigationController.viewControllers.remove(at: 1)
-    }
-
-    func showContactDetail(contactId: Int) {
-        let viewModel = ContactDetailViewModel(contactId: contactId, chatId: nil, context: dcContext)
-        let contactDetailController = ContactDetailViewController(viewModel: viewModel)
-        navigationController.pushViewController(contactDetailController, animated: true)
-    }
-    
-}
-
 // MARK: - ChatViewCoordinator
 // MARK: - ChatViewCoordinator
 class ChatViewCoordinator: NSObject, Coordinator {
 class ChatViewCoordinator: NSObject, Coordinator {
     var dcContext: DcContext
     var dcContext: DcContext