Kaynağa Gözat

replaced ChatDetailController by ContactDetailController

Bastian van de Wetering 6 yıl önce
ebeveyn
işleme
e8d404ebb7

+ 5 - 116
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -8,11 +8,12 @@
 
 import UIKit
 
+// this is also used as ChatDetail for SingleChats
 class ContactDetailViewController: UITableViewController {
-	weak var coordinator: ContactDetailCoordinator?
+	weak var coordinator: ContactDetailCoordinatorProtocol?
 	var showChatCell: Bool = false // if this is set to true it will show a "goToChat-cell"
 
-	private enum CellIdentifiers: String  {
+	private enum CellIdentifiers: String {
 		case notification = "notificationCell"
 		case block = "blockContactCell"
 		case chat = "chatCell"
@@ -30,7 +31,7 @@ class ContactDetailViewController: UITableViewController {
 		cell.accessibilityIdentifier = CellIdentifiers.notification.rawValue
 		cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
 		cell.selectionStyle = .none
-		// TODO: add notification status
+		// TODO: add current notification status
 		return cell
 	}()
 
@@ -64,7 +65,7 @@ class ContactDetailViewController: UITableViewController {
 	override func viewDidLoad() {
 		super.viewDidLoad()
 		navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Edit", style: .plain, target: self, action: #selector(editButtonPressed))
-		self.title = "Contact"
+		self.title = "Contact Info"
 	}
 
 	override func viewWillAppear(_ animated: Bool) {
@@ -98,7 +99,6 @@ class ContactDetailViewController: UITableViewController {
 		} else {
 			return blockContactCell
 		}
-
 	}
 
 	override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
@@ -159,115 +159,4 @@ class ContactDetailViewController: UITableViewController {
 	@objc private func editButtonPressed() {
 		coordinator?.showEditContact(contactId: contactId)
 	}
-
-
-
-
-
-
-
-	/*
-	override func viewDidLoad() {
-	super.viewDidLoad()
-	title = "Info"
-	}
-
-	override func viewWillAppear(_: Bool) {
-	navigationController?.navigationBar.prefersLargeTitles = false
-	tableView.reloadData()
-	}
-
-	override func didReceiveMemoryWarning() {
-	super.didReceiveMemoryWarning()
-	// Dispose of any resources that can be recreated.
-	}
-
-	// MARK: - Table view data source
-
-	override func numberOfSections(in _: UITableView) -> Int {
-	return 1
-	}
-
-	override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
-	if section == 0 {
-	return 3
-	}
-
-	return 0
-	}
-
-	override func tableView(_: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-	let row = indexPath.row
-
-	let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
-
-	let settingsImage = #imageLiteral(resourceName: "baseline_settings_black_18pt").withRenderingMode(.alwaysTemplate)
-	cell.imageView?.image = settingsImage
-	cell.imageView?.tintColor = UIColor.clear
-
-	if row == 0 {
-	cell.textLabel?.text = "Settings"
-	cell.imageView?.tintColor = UIColor.gray
-	}
-	if row == 1 {
-	cell.textLabel?.text = "Edit name"
-	}
-
-	if row == 2 {
-	cell.textLabel?.text = "New chat"
-	}
-	return cell
-	}
-
-	override func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
-	let row = indexPath.row
-
-	if row == 0 {
-	let alert = UIAlertController(title: "Not implemented", message: "Settings are not implemented yet.", preferredStyle: .alert)
-	alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
-	present(alert, animated: true, completion: nil)
-	}
-	if row == 1 {
-	let newContactController = NewContactController(contactIdForUpdate: contactId)
-	navigationController?.pushViewController(newContactController, animated: true)
-	}
-	if row == 2 {
-	displayNewChat(contactId: contactId)
-	}
-	}
-
-	override func tableView(_: UITableView, heightForHeaderInSection _: Int) -> CGFloat {
-	return 80
-	}
-
-	override func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
-	let bg = UIColor(red: 248 / 255, green: 248 / 255, blue: 255 / 255, alpha: 1.0)
-	if section == 0 {
-	let contactCell = ContactCell()
-	contactCell.backgroundColor = bg
-	contactCell.nameLabel.text = contact.name
-	contactCell.emailLabel.text = contact.email
-	contactCell.darkMode = false
-	contactCell.selectionStyle = .none
-	if let img = contact.profileImage {
-	contactCell.setImage(img)
-	} else {
-	contactCell.setBackupImage(name: contact.name, color: contact.color)
-	}
-	contactCell.setVerified(isVerified: contact.isVerified)
-	return contactCell
-	}
-
-	let vw = UIView()
-	vw.backgroundColor = bg
-
-	return vw
-	}
-
-	private func displayNewChat(contactId: Int) {
-	let chatId = dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId))
-	coordinator?.showChat(chatId: Int(chatId))
-	}
-
-	*/
 }

+ 0 - 87
deltachat-ios/Controller/SingleChatDetailViewController.swift

@@ -59,94 +59,7 @@ class ChatDetailViewController: UIViewController {
   }
 }
 
-class SingleChatDetailViewController: ChatDetailViewController {
-  var contact: MRContact? {
-    if let id = chat.contactIds.first {
-      return MRContact(id: id)
-    }
-    return nil
-  }
-
-  override func viewDidLoad() {
-    super.viewDidLoad()
-    title = "Info"
-    chatDetailTable.delegate = self
-    chatDetailTable.dataSource = self
-  }
-
-  @objc override func editButtonPressed() {
-    if let id = chat.contactIds.first {
-      coordinator?.showSingleChatEdit(contactId: id)
-    }
-  }
-}
-
-extension SingleChatDetailViewController: UITableViewDelegate, UITableViewDataSource {
-  func numberOfSections(in _: UITableView) -> Int {
-    return 2
-  }
-
-  func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
-    return 1
-  }
-
-  func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
-    if section == 0 {
-      guard let contact = contact else {
-        return nil
-      }
-      let bg = UIColor(red: 248 / 255, green: 248 / 255, blue: 255 / 255, alpha: 1.0)
-
-      let contactCell = ContactCell()
-      contactCell.backgroundColor = bg
-      contactCell.nameLabel.text = contact.name
-      contactCell.emailLabel.text = contact.email
-      contactCell.darkMode = false
-      contactCell.selectionStyle = .none
-      if let img = chat.profileImage {
-        contactCell.setImage(img)
-      } else {
-        contactCell.setBackupImage(name: contact.name, color: contact.color)
-      }
-      contactCell.setVerified(isVerified: chat.isVerified)
-      return contactCell
-    } else {
-      return nil
-    }
-  }
-
-  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-    let section = indexPath.section
-
-    if section == 0 {
-      let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath)
-      cell.textLabel?.text = "Notifications"
-      cell.selectionStyle = .none
-      return cell
-    } else if section == 1 {
-      let cell = tableView.dequeueReusableCell(withIdentifier: "actionCell", for: indexPath) as! ActionCell
-      if let contact = contact {
-        cell.actionTitle = contact.isBlocked ? "Unblock Contact" : "Block Contact"
-        cell.actionColor = contact.isBlocked ? SystemColor.blue.uiColor : UIColor.red // SystemColor.red.uiColor
-      }
-      return cell
-    }
-    return UITableViewCell(frame: .zero)
-  }
-
-  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
-    let section = indexPath.section
 
-    if section == 0 {
-      showNotificationSetup()
-    } else if section == 1 {
-      if let contact = contact {
-        contact.isBlocked ? contact.unblock() : contact.block()
-        tableView.reloadData()
-      }
-    }
-  }
-}
 
 class GroupChatDetailViewController: ChatDetailViewController {
   private var currentUser: MRContact? {

+ 75 - 65
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -10,13 +10,13 @@ import UIKit
 
 class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 	private let window: UIWindow
-
+	
 	var rootViewController: UIViewController {
 		return tabBarController
 	}
-
+	
 	private var childCoordinators: [Coordinator] = []
-
+	
 	private lazy var tabBarController: UITabBarController = {
 		let tabBarController = UITabBarController()
 		tabBarController.viewControllers = [contactListController, mailboxController, profileController, chatListController, settingsController]
@@ -26,9 +26,9 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		// tabBarController.tabBar.isTranslucent = false
 		return tabBarController
 	}()
-
+	
 	// MARK: viewControllers
-
+	
 	private lazy var contactListController: UIViewController = {
 		let controller = ContactListController()
 		let nav = NavigationController(rootViewController: controller)
@@ -39,7 +39,7 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		controller.coordinator = coordinator
 		return nav
 	}()
-
+	
 	private lazy var mailboxController: UIViewController = {
 		let controller = MailboxViewController(chatId: Int(DC_CHAT_ID_DEADDROP), title: "Mailbox")
 		controller.disableWriting = true
@@ -51,7 +51,7 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		controller.coordinator = coordinator
 		return nav
 	}()
-
+	
 	private lazy var profileController: UIViewController = {
 		let controller = ProfileViewController()
 		let nav = NavigationController(rootViewController: controller)
@@ -62,7 +62,7 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		controller.coordinator = coordinator
 		return nav
 	}()
-
+	
 	private lazy var chatListController: UIViewController = {
 		let controller = ChatListController()
 		let nav = NavigationController(rootViewController: controller)
@@ -73,7 +73,7 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		controller.coordinator = coordinator
 		return nav
 	}()
-
+	
 	private lazy var settingsController: UIViewController = {
 		let controller = SettingsViewController()
 		let nav = NavigationController(rootViewController: controller)
@@ -84,22 +84,22 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 		controller.coordinator = coordinator
 		return nav
 	}()
-
+	
 	init(window: UIWindow) {
 		self.window = window
 		super.init()
 		window.rootViewController = rootViewController
 		window.makeKeyAndVisible()
 	}
-
+	
 	public func start() {
 		showTab(index: 3)
 	}
-
+	
 	func showTab(index: Int) {
 		tabBarController.selectedIndex = index
 	}
-
+	
 	func presentLoginController() {
 		let accountSetupController = AccountSetupController()
 		let accountSetupNavigationController = UINavigationController(rootViewController: accountSetupController)
@@ -111,7 +111,7 @@ extension AppCoordinator: UITabBarDelegate {
 	func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
 		print("item selected")
 	}
-
+	
 	func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
 		print("shouldSelect")
 		return true 
@@ -120,13 +120,13 @@ extension AppCoordinator: UITabBarDelegate {
 
 class ContactListCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	var childCoordinators: [Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showContactDetail(contactId: Int) {
 		let contactDetailController = ContactDetailViewController(contactId: contactId)
 		contactDetailController.showChatCell = true
@@ -135,7 +135,7 @@ class ContactListCoordinator: Coordinator {
 		contactDetailController.coordinator = coordinator
 		navigationController.pushViewController(contactDetailController, animated: true)
 	}
-
+	
 	func showChat(chatId: Int) {
 		let chatVC = ChatViewController(chatId: chatId)
 		let coordinator = ChatViewCoordinator(navigationController: navigationController)
@@ -154,7 +154,7 @@ class MailboxCoordinator: ChatViewCoordinator {
 
 class ProfileCoordinator: Coordinator {
 	var rootViewController: UIViewController
-
+	
 	init(rootViewController: UIViewController) {
 		self.rootViewController = rootViewController
 	}
@@ -162,13 +162,13 @@ class ProfileCoordinator: Coordinator {
 
 class ChatListCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	var childCoordinators: [Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showNewChatController() {
 		let newChatVC = NewChatViewController()
 		let coordinator = NewChatCoordinator(navigationController: navigationController)
@@ -176,7 +176,7 @@ class ChatListCoordinator: Coordinator {
 		newChatVC.coordinator = coordinator
 		navigationController.pushViewController(newChatVC, animated: true)
 	}
-
+	
 	func showChat(chatId: Int) {
 		let chatVC = ChatViewController(chatId: chatId)
 		let coordinator = ChatViewCoordinator(navigationController: navigationController)
@@ -188,13 +188,13 @@ class ChatListCoordinator: Coordinator {
 
 class SettingsCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	var childCoordinators:[Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showAccountSetupController() {
 		let accountSetupVC = AccountSetupController()
 		let coordinator = AccountSetupCoordinator(navigationController: navigationController)
@@ -202,7 +202,7 @@ class SettingsCoordinator: Coordinator {
 		accountSetupVC.coordinator = coordinator
 		navigationController.pushViewController(accountSetupVC, animated: true)
 	}
-
+	
 	func showEditSettingsController(option: SettingsEditOption) {
 		let editController = EditSettingsController()
 		editController.activateField(option: option)
@@ -212,11 +212,11 @@ class SettingsCoordinator: Coordinator {
 
 class AccountSetupCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showImapPortOptions() {
 		let currentMailPort = MRConfig.mailPort ?? MRConfig.configuredMailPort
 		let currentPort = Int(currentMailPort)
@@ -228,7 +228,7 @@ class AccountSetupCoordinator: Coordinator {
 		}
 		navigationController.pushViewController(portSettingsController, animated: true)
 	}
-
+	
 	func showImapSecurityOptions() {
 		let currentSecurityOption = MRConfig.getImapSecurity()
 		let convertedOption = SecurityConverter.convertHexToString(type: .IMAPSecurity, hex: currentSecurityOption)
@@ -243,7 +243,7 @@ class AccountSetupCoordinator: Coordinator {
 		}
 		navigationController.pushViewController(securitySettingsController, animated: true)
 	}
-
+	
 	func showSmtpPortsOptions() {
 		let currentMailPort = MRConfig.sendPort ?? MRConfig.configuredSendPort
 		let currentPort = Int(currentMailPort)
@@ -255,7 +255,7 @@ class AccountSetupCoordinator: Coordinator {
 		}
 		navigationController.pushViewController(portSettingsController, animated: true)
 	}
-
+	
 	func showSmptpSecurityOptions() {
 		let currentSecurityOption = MRConfig.getSmtpSecurity()
 		let convertedOption = SecurityConverter.convertHexToString(type: .SMTPSecurity, hex: currentSecurityOption)
@@ -274,13 +274,13 @@ class AccountSetupCoordinator: Coordinator {
 
 class NewChatCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	private var childCoordinators: [Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showNewGroupController() {
 		let newGroupController = NewGroupViewController()
 		let coordinator = NewGroupCoordinator(navigationController: navigationController)
@@ -288,23 +288,23 @@ class NewChatCoordinator: Coordinator {
 		newGroupController.coordinator = coordinator
 		navigationController.pushViewController(newGroupController, animated: true)
 	}
-
+	
 	func showQRCodeController() {
 		let controller = QrCodeReaderController()
 		// controller.delegate = self
 		// present(controller, animated: true, completion: nil)
 	}
-
+	
 	func showNewContactController() {
 		let newContactController = NewContactController()
 		navigationController.pushViewController(newContactController, animated: true)
 	}
-
+	
 	func showNewChat(contactId: Int) {
 		let chatId = dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId))
 		showChat(chatId: Int(chatId))
 	}
-
+	
 	func showChat(chatId: Int) {
 		let chatViewController = ChatViewController(chatId: chatId)
 		let coordinator = ChatViewCoordinator(navigationController: navigationController)
@@ -317,18 +317,18 @@ class NewChatCoordinator: Coordinator {
 
 class ChatDetailCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	private var childCoordinators: [Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showSingleChatEdit(contactId: Int) {
 		let newContactController = NewContactController(contactIdForUpdate: contactId)
 		navigationController.pushViewController(newContactController, animated: true)
 	}
-
+	
 	func showAddGroupMember(chatId: Int) {
 		let groupMemberViewController = AddGroupMembersViewController(chatId: chatId)
 		navigationController.pushViewController(groupMemberViewController, animated: true)
@@ -337,28 +337,33 @@ class ChatDetailCoordinator: Coordinator {
 
 class ChatViewCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	var childCoordinators: [Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showChatDetail(chatId: Int) {
 		let chat = MRChat(id: chatId)
-		let chatDetailViewController: ChatDetailViewController
 		switch chat.chatType {
 		case .SINGLE:
-			chatDetailViewController = SingleChatDetailViewController(chatId: chatId) // inherits from ChatDetailViewController
+			if let contactId = chat.contactIds.first {
+				let contactDetailController = ContactDetailViewController(contactId: contactId)
+				let coordinator = ContactDetailCoordinator(navigationController: navigationController)
+				childCoordinators.append(coordinator)
+				contactDetailController.coordinator = coordinator
+				navigationController.pushViewController(contactDetailController, animated: true)
+			}
 		case .GROUP, .VERYFIEDGROUP:
-			chatDetailViewController = GroupChatDetailViewController(chatId: chatId) // inherits from ChatDetailViewController
+			let groupChatDetailViewController = GroupChatDetailViewController(chatId: chatId) // inherits from ChatDetailViewController
+			let coordinator = ChatDetailCoordinator(navigationController: navigationController)
+			childCoordinators.append(coordinator)
+			groupChatDetailViewController.coordinator = coordinator
+			navigationController.pushViewController(groupChatDetailViewController, animated: true)
 		}
-		let coordinator = ChatDetailCoordinator(navigationController: navigationController)
-		childCoordinators.append(coordinator)
-		chatDetailViewController.coordinator = coordinator
-		navigationController.pushViewController(chatDetailViewController, animated: true)
 	}
-
+	
 	func showContactDetail(of contactId: Int) {
 		let contactDetailController = ContactDetailViewController(contactId: contactId)
 		//let nav = UINavigationController(rootViewController: contactDetailController)
@@ -371,13 +376,13 @@ class ChatViewCoordinator: Coordinator {
 
 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)
@@ -389,13 +394,13 @@ class NewGroupCoordinator: Coordinator {
 
 class GroupNameCoordinator: Coordinator {
 	let navigationController: UINavigationController
-
+	
 	private var childCoordinators: [Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showGroupChat(chatId: Int) {
 		let chatViewController = ChatViewController(chatId: chatId)
 		let coordinator = ChatViewCoordinator(navigationController: navigationController)
@@ -406,15 +411,15 @@ class GroupNameCoordinator: Coordinator {
 	}
 }
 
-class ContactDetailCoordinator: Coordinator {
+class ContactDetailCoordinator: Coordinator, ContactDetailCoordinatorProtocol {
 	let navigationController: UINavigationController
-
+	
 	private var childCoordinators: [Coordinator] = []
-
+	
 	init(navigationController: UINavigationController) {
 		self.navigationController = navigationController
 	}
-
+	
 	func showChat(chatId: Int) {
 		let chatViewController = ChatViewController(chatId: chatId)
 		let coordinator = ChatViewCoordinator(navigationController: navigationController)
@@ -423,9 +428,14 @@ class ContactDetailCoordinator: Coordinator {
 		navigationController.popToRootViewController(animated: false)
 		navigationController.pushViewController(chatViewController, animated: true)
 	}
-
+	
 	func showEditContact(contactId: Int) {
 		let newContactController = NewContactController(contactIdForUpdate: contactId)
 		navigationController.pushViewController(newContactController, animated: true)
 	}
 }
+
+protocol ContactDetailCoordinatorProtocol: class {
+	func showEditContact(contactId: Int)
+	func showChat(chatId: Int)
+}