فهرست منبع

open contact details on tap on group member's avatar (#82)

cyberta 5 سال پیش
والد
کامیت
0f7b8485f9

+ 16 - 5
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -1,6 +1,6 @@
 import UIKit
 
-class GroupChatDetailViewController: UIViewController {
+class GroupChatDetailViewController: UIViewController, ContactCellDelegate {
 
     private let sectionConfig = 0
     private let sectionMembers = 1
@@ -185,6 +185,8 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
                     contactCell.emailLabel.text = contact.email
                     contactCell.initialsLabel.text = Utils.getInitials(inputName: displayName)
                     contactCell.setColor(contact.color)
+                    contactCell.rowIndex = indexPath.row
+                    contactCell.delegate = self
                 }
                 return cell
             }
@@ -237,13 +239,11 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         if section == sectionMembers, row >= staticCellCountMemberSection, groupMembers[row - staticCellCountMemberSection].id != currentUser?.id {
             let delete = UITableViewRowAction(style: .destructive, title: String.localized("remove_desktop")) { [unowned self] _, indexPath in
 
-                let memberId = self.groupMembers[row - self.staticCellCountMemberSection].id
-                let contact = DcContact(id: memberId)
-
+                let contact = self.getGroupMember(at: row)
                 let title = String.localizedStringWithFormat(String.localized("ask_remove_members"), contact.nameNAddr)
                 let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
                 alert.addAction(UIAlertAction(title: String.localized("remove_desktop"), style: .destructive, handler: { _ in
-                    let success = dc_remove_contact_from_chat(mailboxPointer, UInt32(self.chat.id), UInt32(memberId))
+                    let success = dc_remove_contact_from_chat(mailboxPointer, UInt32(self.chat.id), UInt32(contact.id))
                     if success == 1 {
                         self.groupMembers.remove(at: row - self.staticCellCountMemberSection)
                         tableView.deleteRows(at: [indexPath], with: .fade)
@@ -259,4 +259,15 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
             return nil
         }
     }
+
+    func getGroupMember(at row: Int) -> DcContact {
+        let memberId = self.groupMembers[row - self.staticCellCountMemberSection].id
+        return DcContact(id: memberId)
+    }
+
+    func onAvatarTapped(at index: Int) {
+        let contact = getGroupMember(at: index)
+        coordinator?.showContactDetail(of: contact.id)
+    }
+
 }

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

@@ -354,6 +354,14 @@ class GroupChatDetailCoordinator: Coordinator {
         editGroupViewController.coordinator = coordinator
         navigationController.pushViewController(editGroupViewController, animated: true)
     }
+
+    func showContactDetail(of contactId: Int) {
+        let contactDetailController = ContactDetailViewController(contactId: contactId)
+        let coordinator = ContactDetailCoordinator(dcContext: dcContext, navigationController: navigationController)
+        childCoordinators.append(coordinator)
+        contactDetailController.coordinator = coordinator
+        navigationController.pushViewController(contactDetailController, animated: true)
+    }
 }
 
 class ChatViewCoordinator: NSObject, Coordinator {

+ 18 - 0
deltachat-ios/View/ContactCell.swift

@@ -13,8 +13,14 @@ enum MessageDeliveryState: Int {
     case OUTMDNRCVD = 28
 }
 
+protocol ContactCellDelegate: class {
+    func onAvatarTapped(at index: Int)
+}
+
 class ContactCell: UITableViewCell {
 
+    weak var delegate: ContactCellDelegate?
+    var rowIndex = -1
     private let initialsLabelSize: CGFloat = 54
     private let imgSize: CGFloat = 25
 
@@ -158,6 +164,9 @@ class ContactCell: UITableViewCell {
 
         imgView.center.x = avatar.center.x + (avatar.frame.width / 2) + imgSize - 5
         imgView.center.y = avatar.center.y + (avatar.frame.height / 2) + imgSize - 5
+
+        let tap = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))
+        avatar.addGestureRecognizer(tap)
     }
 
     func setVerified(isVerified: Bool) {
@@ -231,6 +240,15 @@ class ContactCell: UITableViewCell {
         initialsLabel.backgroundColor = color
     }
 
+    @objc func onAvatarTapped() {
+        if let delegate = delegate {
+            if rowIndex == -1 {
+                return
+            }
+            delegate.onAvatarTapped(at: rowIndex)
+        }
+    }
+
     required init?(coder _: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }