Bastian van de Wetering 6 лет назад
Родитель
Сommit
c4cc5c24cc

+ 4 - 4
deltachat-ios.xcodeproj/project.pbxproj

@@ -97,7 +97,7 @@
 		AE851AC7227C776400ED86F0 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC6227C776400ED86F0 /* Location.swift */; };
 		AE851AC9227C77CF00ED86F0 /* Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC8227C77CF00ED86F0 /* Media.swift */; };
 		AE851ACE227CA54400ED86F0 /* InitialsLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACD227CA54300ED86F0 /* InitialsLabel.swift */; };
-		AE851AD0227DF50900ED86F0 /* ChatDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACF227DF50900ED86F0 /* ChatDetailViewController.swift */; };
+		AE851AD0227DF50900ED86F0 /* SingleChatDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACF227DF50900ED86F0 /* SingleChatDetailViewController.swift */; };
 		AEACE2DD1FB323CA00DCDD78 /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */; };
 		AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DE1FB3246400DCDD78 /* Message.swift */; };
 		AEACE2E31FB32B5C00DCDD78 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E21FB32B5C00DCDD78 /* Constants.swift */; };
@@ -290,7 +290,7 @@
 		AE851AC6227C776400ED86F0 /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
 		AE851AC8227C77CF00ED86F0 /* Media.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = "<group>"; };
 		AE851ACD227CA54300ED86F0 /* InitialsLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsLabel.swift; sourceTree = "<group>"; };
-		AE851ACF227DF50900ED86F0 /* ChatDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatDetailViewController.swift; sourceTree = "<group>"; };
+		AE851ACF227DF50900ED86F0 /* SingleChatDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleChatDetailViewController.swift; sourceTree = "<group>"; };
 		AEA9CC2F22522DA20061D113 /* librpgp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = librpgp.h; sourceTree = "<group>"; };
 		AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
 		AEACE2DE1FB3246400DCDD78 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
@@ -597,7 +597,7 @@
 				78E45E3921D3CFBC00D4B15E /* SettingsController.swift */,
 				7070FB3C20FDD9FE000DC258 /* NewGroupViewController.swift */,
 				7070FB9A2101ECBB000DC258 /* GroupNameController.swift */,
-				AE851ACF227DF50900ED86F0 /* ChatDetailViewController.swift */,
+				AE851ACF227DF50900ED86F0 /* SingleChatDetailViewController.swift */,
 			);
 			path = Controller;
 			sourceTree = "<group>";
@@ -1002,7 +1002,7 @@
 				7A451D941FB1B1DB00177250 /* wrapper.c in Sources */,
 				7092474120B3869500AF8799 /* ContactDetailViewController.swift in Sources */,
 				7070FB5E20FF345F000DC258 /* dc_token.c in Sources */,
-				AE851AD0227DF50900ED86F0 /* ChatDetailViewController.swift in Sources */,
+				AE851AD0227DF50900ED86F0 /* SingleChatDetailViewController.swift in Sources */,
 				7070FB6C20FF345F000DC258 /* dc_keyring.c in Sources */,
 				7A451DB01FB1F84900177250 /* AppCoordinator.swift in Sources */,
 				AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */,

+ 0 - 40
deltachat-ios/Controller/ChatDetailViewController.swift

@@ -1,40 +0,0 @@
-//
-//  ChatDetailViewController.swift
-//  deltachat-ios
-//
-//  Created by Bastian van de Wetering on 04.05.19.
-//  Copyright © 2019 Jonas Reinsch. All rights reserved.
-//
-
-import UIKit
-
-// TODO: checkout if it makes sense to  run group chats and single chats within this chatDetailViewController or maybe seperate these
-
-class ChatDetailViewController: UIViewController {
-  weak var coordinator: ChatDetailCoordinator?
-
-  init(chatId _: Int) {
-    super.init(nibName: nil, bundle: nil)
-  }
-
-  required init?(coder _: NSCoder) {
-    fatalError("init(coder:) has not been implemented")
-  }
-
-  override func viewDidLoad() {
-    super.viewDidLoad()
-    view.backgroundColor = UIColor.white
-
-    // Do any additional setup after loading the view.
-  }
-
-  /*
-   // MARK: - Navigation
-
-   // In a storyboard-based application, you will often want to do a little preparation before navigation
-   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-   // Get the new view controller using segue.destination.
-   // Pass the selected object to the new view controller.
-   }
-   */
-}

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

@@ -129,12 +129,6 @@ class ContactDetailViewController: UITableViewController {
 	private func displayNewChat(contactId: Int) {
 		let chatId = dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId))
 		coordinator?.showChat(chatId: Int(chatId))
-		/*
-		let chatVC = ChatViewController(chatId: Int(chatId))
-
-		chatVC.hidesBottomBarWhenPushed = true
-		navigationController?.pushViewController(chatVC, animated: true)
-		*/
 }
 
 }

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

@@ -0,0 +1,145 @@
+//
+//  ChatDetailViewController.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 04.05.19.
+//  Copyright © 2019 Jonas Reinsch. All rights reserved.
+//
+
+import UIKit
+
+// TODO: checkout if it makes sense to  run group chats and single chats within this chatDetailViewController or maybe seperate these
+
+
+
+
+class ChatDetailViewController: UIViewController {
+	weak var coordinator: ChatDetailCoordinator?
+
+	fileprivate let chat: MRChat
+	var chatDetailTable: UITableView = {
+		let table = UITableView(frame: .zero, style: .grouped)
+		table.bounces = false
+		table.register(UITableViewCell.self, forCellReuseIdentifier: "tableCell")
+		table.register(ActionCell.self, forCellReuseIdentifier: "actionCell")
+		return table
+	}()
+
+	init(chatId: Int) {
+		self.chat = MRChat(id: chatId)
+		super.init(nibName: nil, bundle: nil)
+		setupSubviews()
+	}
+
+	required init?(coder _: NSCoder) {
+		fatalError("init(coder:) has not been implemented")
+	}
+
+	private func setupSubviews() {
+		view.addSubview(chatDetailTable)
+		chatDetailTable.translatesAutoresizingMaskIntoConstraints = false
+
+		chatDetailTable.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
+		chatDetailTable.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
+		chatDetailTable.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
+		chatDetailTable.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
+	}
+
+	// put common actions here to avoid duplicity
+}
+
+
+
+
+class SingleChatDetailViewController: ChatDetailViewController {
+
+	override func viewDidLoad() {
+		super.viewDidLoad()
+		title = "Info"
+		chatDetailTable.delegate = self
+		chatDetailTable.dataSource = self
+
+	}
+
+}
+
+extension SingleChatDetailViewController: UITableViewDelegate, UITableViewDataSource {
+
+	func numberOfSections(in tableView: UITableView) -> Int {
+		return 2
+	}
+
+	func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+		return 1
+	}
+
+	func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+		if section == 0 {
+			let bg = UIColor(red: 248 / 255, green: 248 / 255, blue: 255 / 255, alpha: 1.0)
+			let contactCell = ContactCell()
+			contactCell.backgroundColor = bg
+			contactCell.nameLabel.text = chat.name
+			contactCell.emailLabel.text = chat.subtitle
+			contactCell.darkMode = false
+			contactCell.selectionStyle = .none
+			if let img = chat.profileImage {
+				contactCell.setImage(img)
+			} else {
+				contactCell.setBackupImage(name: chat.name, color: chat.color)
+			}
+			contactCell.setVerified(isVerified: chat.isVerified)
+			return contactCell
+		} else {
+			return nil
+		}
+	}
+
+
+	func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+		let row = indexPath.row
+		let section = indexPath.section
+
+		if section == 0 {
+			let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath)
+			cell.textLabel?.text = "Notifications"
+			return cell
+		} else if section == 1 {
+			let cell = tableView.dequeueReusableCell(withIdentifier: "actionCell", for: indexPath) as! ActionCell
+			cell.actionTitle = "Block User"
+			cell.actionColor = UIColor.red // SystemColor.red.uiColor
+			return cell
+		}
+
+		return UITableViewCell(frame: .zero)
+	}
+
+
+}
+
+
+
+class GroupChatDetailViewController: ChatDetailViewController {
+	override func viewDidLoad() {
+		super.viewDidLoad()
+		title = "Group Info"
+		chatDetailTable.delegate = self
+		chatDetailTable.dataSource = self
+	}
+}
+
+extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSource {
+	func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+		return 0
+	}
+
+	func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+		return UITableViewCell(frame: .zero)
+	}
+
+
+}
+
+
+
+
+

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

@@ -247,7 +247,14 @@ class ChatViewCoordinator: Coordinator {
   }
 
   func showChatDetail(chatId: Int) {
-    let chatDetailViewController = ChatDetailViewController(chatId: chatId)
+		let chat = MRChat(id: chatId)
+		let chatDetailViewController: ChatDetailViewController
+		switch chat.chatType  {
+		case .SINGLE:
+			chatDetailViewController = SingleChatDetailViewController(chatId: chatId)	// inherits from ChatDetailViewController
+		case .GROUP, .VERYFIEDGROUP:
+			chatDetailViewController = GroupChatDetailViewController(chatId: chatId) // inherits from ChatDetailViewController
+		}
     let coordinator = ChatDetailCoordinator(navigationController: navigationController)
     childCoordinators.append(coordinator)
     chatDetailViewController.coordinator = coordinator

+ 10 - 0
deltachat-ios/DC/Wrapper.swift

@@ -340,6 +340,12 @@ class MRMessage: MessageType {
   }
 }
 
+enum ChatType: Int {
+	case SINGLE = 100
+	case GROUP = 120
+	case VERYFIEDGROUP = 130
+}
+
 class MRChat {
   var chatPointer: UnsafeMutablePointer<dc_chat_t>
 
@@ -358,6 +364,10 @@ class MRChat {
     return Int(chatPointer.pointee.type)
   }
 
+	var chatType: ChatType {
+		return ChatType(rawValue: type) ?? ChatType.GROUP // group as fallback - shouldn't get here
+	}
+
   var color: UIColor {
     return UIColor(netHex: Int(dc_chat_get_color(chatPointer)))
   }

+ 6 - 0
deltachat-ios/View/ActionCell.swift

@@ -17,6 +17,12 @@ class ActionCell: UITableViewCell {
     }
   }
 
+	var actionColor: UIColor? {
+		didSet {
+			actionLabel.textColor = actionColor ?? UIColor.systemBlue
+		}
+	}
+
   private lazy var actionLabel: UILabel = {
     let label = UILabel()
     label.text = actionTitle