Forráskód Böngészése

refactored coordinators - groupNameController now as TableView - WIP

Bastian van de Wetering 6 éve
szülő
commit
69a8081473

+ 29 - 13
deltachat-ios/Controller/GroupNameController.swift

@@ -8,7 +8,10 @@
 
 import UIKit
 
-class GroupNameController: UIViewController {
+class GroupNameController: UITableViewController {
+
+	weak var coordinator: GroupNameCoordinator?
+
   var doneButton: UIBarButtonItem!
   let groupNameTextField = UITextField()
   let contactIdsForGroup: Set<Int>
@@ -26,32 +29,25 @@ class GroupNameController: UIViewController {
 
   init(contactIdsForGroup: Set<Int>) {
     self.contactIdsForGroup = contactIdsForGroup
-    super.init(nibName: nil, bundle: nil)
+    super.init(style: .grouped)
   }
 
   required init?(coder _: NSCoder) {
     fatalError("init(coder:) has not been implemented")
   }
 
-  func layoutTextField() {
-    groupNameTextField.translatesAutoresizingMaskIntoConstraints = false
-    view.addSubview(groupNameTextField)
-    groupNameTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
-    groupNameTextField.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true
-    groupNameTextField.placeholder = "Group Name"
-    groupNameTextField.becomeFirstResponder()
-  }
 
   override func viewDidLoad() {
     super.viewDidLoad()
     title = "Group Name"
+		view.backgroundColor = UIColor.white
     groupNameTextField.delegate = self
-    layoutTextField()
-
     doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(didPressDoneButton))
     navigationItem.rightBarButtonItem = doneButton
     doneButton.isEnabled = false
-  }
+		setupSubviews()
+
+	}
 
   @objc func didPressDoneButton() {
     logger.info("Done Button pressed")
@@ -79,6 +75,26 @@ class GroupNameController: UIViewController {
     super.didReceiveMemoryWarning()
     // Dispose of any resources that can be recreated.
   }
+
+	func setupSubviews() {
+		groupNameTextField.translatesAutoresizingMaskIntoConstraints = false
+		view.addSubview(groupNameTextField)
+		groupNameTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
+		groupNameTextField.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true
+		groupNameTextField.placeholder = "Group Name"
+		groupNameTextField.becomeFirstResponder()
+	}
+
+	override func numberOfSections(in tableView: UITableView) -> Int {
+		return 2
+	}
+
+	/*
+	override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+
+	}
+	*/
+
 }
 
 extension GroupNameController: UITextFieldDelegate {

+ 3 - 1
deltachat-ios/Controller/NewGroupViewController.swift

@@ -9,6 +9,8 @@
 import UIKit
 
 class NewGroupViewController: UITableViewController {
+	weak var coordinator: NewGroupCoordinator?
+
   let contactCellReuseIdentifier = "xyz"
   var contactIds: [Int] = Utils.getContactIds()
   var contactIdsForGroup: Set<Int> = [] {
@@ -19,7 +21,7 @@ class NewGroupViewController: UITableViewController {
   }
 
   @objc func didPressGroupCreationNextButton() {
-    navigationController?.pushViewController(GroupNameController(contactIdsForGroup: contactIdsForGroup), animated: true)
+		coordinator?.showGroupNameController(contactIdsForGroup: contactIdsForGroup)
   }
 
   override func viewDidLoad() {

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

@@ -35,7 +35,7 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		let nav = NavigationController(rootViewController: controller)
 		let settingsImage = UIImage(named: "contacts")
 		nav.tabBarItem = UITabBarItem(title: "Contacts", image: settingsImage, tag: 4)
-		let coordinator = ContactListCoordinator(rootViewController: nav)
+		let coordinator = ContactListCoordinator(navigationController: nav)
 		self.childCoordinators.append(coordinator)
 		controller.coordinator = coordinator
 		return nav
@@ -47,7 +47,7 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		let nav = NavigationController(rootViewController: controller)
 		let settingsImage = UIImage(named: "message")
 		nav.tabBarItem = UITabBarItem(title: "Mailbox", image: settingsImage, tag: 4)
-		let coordinator = ChatViewCoordinator(navigationController: nav)
+		let coordinator = MailboxCoordinator(navigationController: nav)
 		self.childCoordinators.append(coordinator)
 		controller.coordinator = coordinator
 		return nav
@@ -106,35 +106,21 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		let accountSetupNavigationController = UINavigationController(rootViewController: accountSetupController)
 		rootViewController.present(accountSetupNavigationController, animated: false, completion: nil)
 	}
-
-
 }
 
 class ContactListCoordinator: Coordinator {
-	var rootViewController: UIViewController
-
-	init(rootViewController: UIViewController) {
-		self.rootViewController = rootViewController
-	}
-}
-
-class ChatViewCoordinator: Coordinator {
-	var rootViewController: UIViewController
 	let navigationController: UINavigationController
 
-	var childCoordinators: [Coordinator] = []
-
 	init(navigationController: UINavigationController) {
-		self.rootViewController = navigationController.viewControllers.first!
 		self.navigationController = navigationController
 	}
+}
 
-	func showChatDetail(chatId: Int) {
-		let chatDetailViewController = ChatDetailViewController(chatId: chatId)
-		let coordinator = ChatDetailCoordinator(navigationController: self.navigationController)
-		childCoordinators.append(coordinator)
-		chatDetailViewController.coordinator = coordinator 
-		navigationController.pushViewController(chatDetailViewController, animated: true)
+// since mailbox and chatView -tab both use ChatViewController we want to be able to assign different functionality via coordinators -> therefore we override unneeded functions such as showChatDetail -> maybe find better solution in longterm
+class MailboxCoordinator: ChatViewCoordinator {
+
+	override func showChatDetail(chatId: Int) {
+		// ignore for now
 	}
 }
 
@@ -147,13 +133,11 @@ class ProfileCoordinator: Coordinator {
 }
 
 class ChatListCoordinator: Coordinator {
-	var rootViewController: UIViewController
 	let navigationController: UINavigationController
 
 	var childCoordinators: [Coordinator] = []
 
 	init(navigationController: UINavigationController) {
-		self.rootViewController = navigationController.viewControllers.first!
 		self.navigationController = navigationController
 	}
 
@@ -178,11 +162,9 @@ class ChatListCoordinator: Coordinator {
 }
 
 class SettingsCoordinator: Coordinator {
-	var rootViewController: UIViewController
 	let navigationController: UINavigationController
 
 	init(navigationController: UINavigationController) {
-		self.rootViewController = navigationController.viewControllers.first!
 		self.navigationController = navigationController
 	}
 
@@ -195,19 +177,20 @@ class SettingsCoordinator: Coordinator {
 }
 
 class NewChatCoordinator: Coordinator {
-	var rootViewController: UIViewController
 	let navigationController: UINavigationController
 
 	private var childCoordinators:[Coordinator] = []
 
 	init(navigationController: UINavigationController) {
-		self.rootViewController = navigationController.viewControllers.first!
 		self.navigationController = navigationController
 	}
 
 
 	func showNewGroupController() {
 		let newGroupController = NewGroupViewController()
+		let coordinator = NewGroupCoordinator(navigationController: self.navigationController)
+		childCoordinators.append(coordinator)
+		newGroupController.coordinator = coordinator
 		navigationController.pushViewController(newGroupController, animated: true)
 	}
 
@@ -239,15 +222,65 @@ class NewChatCoordinator: Coordinator {
 }
 
 class ChatDetailCoordinator: Coordinator {
-	var rootViewController: UIViewController
 	let navigationController: UINavigationController
 
-	private var childCoordinators:[Coordinator] = []
+	private var childCoordinators: [Coordinator] = []
 
 	init(navigationController: UINavigationController) {
-		self.rootViewController = navigationController.viewControllers.first!
 		self.navigationController = navigationController
 	}
 }
 
+class ChatViewCoordinator: Coordinator {
+	let navigationController: UINavigationController
+
+	var childCoordinators: [Coordinator] = []
+
+	init(navigationController: UINavigationController) {
+		self.navigationController = navigationController
+	}
 
+	func showChatDetail(chatId: Int) {
+		let chatDetailViewController = ChatDetailViewController(chatId: chatId)
+		let coordinator = ChatDetailCoordinator(navigationController: self.navigationController)
+		childCoordinators.append(coordinator)
+		chatDetailViewController.coordinator = coordinator
+		navigationController.pushViewController(chatDetailViewController, animated: true)
+	}
+}
+
+class NewGroupCoordinator: Coordinator {
+
+	let navigationController: UINavigationController
+
+	private var childCoordinators: [Coordinator] = []
+
+	init(navigationController: UINavigationController) {
+		self.navigationController = navigationController
+	}
+
+	func showGroupNameController(contactIdsForGroup: Set<Int>) {
+		let groupNameController = GroupNameController(contactIdsForGroup: contactIdsForGroup)
+		let coordinator = GroupNameCoordinator(navigationController: navigationController)
+		childCoordinators.append(coordinator)
+		groupNameController.coordinator = coordinator
+		navigationController.pushViewController(groupNameController, animated: true)
+	}
+
+}
+
+
+class GroupNameCoordinator: Coordinator {
+
+	let navigationController: UINavigationController
+
+	private var childCoordinators: [Coordinator] = []
+
+	init(navigationController: UINavigationController) {
+		self.navigationController = navigationController
+	}
+
+	func showGroupChat(chatId: Int) {
+
+	}
+}

+ 2 - 1
deltachat-ios/Helper/Protocols.swift

@@ -9,7 +9,8 @@
 import UIKit
 
 protocol Coordinator: class {
-	var rootViewController: UIViewController { get }
+	// var rootViewController: UIViewController { get }
+	// func start()
 }
 
 protocol QrCodeReaderDelegate: class {