Browse Source

use contact cell for profile layout

cyberta 5 years ago
parent
commit
60c4b8ea93

+ 12 - 1
deltachat-ios/Controller/ChatListController.swift

@@ -154,7 +154,7 @@ class ChatListController: UITableViewController {
         tableView.register(ContactCell.self, forCellReuseIdentifier: chatCellReuseIdentifier)
         tableView.register(ContactCell.self, forCellReuseIdentifier: chatCellReuseIdentifier)
         tableView.register(ContactCell.self, forCellReuseIdentifier: deadDropCellReuseIdentifier)
         tableView.register(ContactCell.self, forCellReuseIdentifier: deadDropCellReuseIdentifier)
         tableView.register(ContactCell.self, forCellReuseIdentifier: contactCellReuseIdentifier)
         tableView.register(ContactCell.self, forCellReuseIdentifier: contactCellReuseIdentifier)
-        tableView.rowHeight = 80
+        tableView.rowHeight = ContactCell.cellHeight
     }
     }
 
 
     // MARK: - actions
     // MARK: - actions
@@ -169,6 +169,12 @@ class ChatListController: UITableViewController {
         updateTitle()
         updateTitle()
     }
     }
 
 
+    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        if previousTraitCollection?.preferredContentSizeCategory !=
+            traitCollection.preferredContentSizeCategory {
+            tableView.rowHeight = ContactCell.cellHeight
+        }
+    }
     private func quitSearch(animated: Bool) {
     private func quitSearch(animated: Bool) {
         searchController.searchBar.text = nil
         searchController.searchBar.text = nil
         self.viewModel.endSearch()
         self.viewModel.endSearch()
@@ -179,6 +185,7 @@ class ChatListController: UITableViewController {
 
 
     // MARK: - UITableViewDelegate + UITableViewDatasource
     // MARK: - UITableViewDelegate + UITableViewDatasource
 
 
+    
     override func numberOfSections(in tableView: UITableView) -> Int {
     override func numberOfSections(in tableView: UITableView) -> Int {
         return viewModel.numberOfSections
         return viewModel.numberOfSections
     }
     }
@@ -213,6 +220,8 @@ class ChatListController: UITableViewController {
                 contactCell.updateCell(cellViewModel: cellData)
                 contactCell.updateCell(cellViewModel: cellData)
                 return contactCell
                 return contactCell
             }
             }
+        case .profile:
+            safe_fatalError("CellData type profile not allowed")
         }
         }
         safe_fatalError("Could not find/dequeue or recycle UITableViewCell.")
         safe_fatalError("Could not find/dequeue or recycle UITableViewCell.")
         return UITableViewCell()
         return UITableViewCell()
@@ -242,6 +251,8 @@ class ChatListController: UITableViewController {
             } else {
             } else {
                 self.askToChatWith(contactId: contactId)
                 self.askToChatWith(contactId: contactId)
             }
             }
+        case .profile:
+            safe_fatalError("CellData type profile not allowed")
         }
         }
         tableView.deselectRow(at: indexPath, animated: false)
         tableView.deselectRow(at: indexPath, animated: false)
     }
     }

+ 10 - 12
deltachat-ios/Controller/SettingsController.swift

@@ -36,14 +36,12 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
 
 
     // MARK: - cells
     // MARK: - cells
 
 
-    private let profileHeader = ContactDetailHeader()
-
-    private lazy var profileCell: ProfileCell = {
-        let displayName = dcContext.displayname ?? String.localized("pref_your_name")
-        let email = dcContext.addr ?? ""
-        let selfContact = DcContact(id: Int(DC_CONTACT_ID_SELF))
-        let cell = ProfileCell(contact: selfContact, displayName: displayName, address: email)
+    private lazy var profileCell: ContactCell = {
+        let cell = ContactCell(style: .default, reuseIdentifier: "profile_cell")
+        let cellViewModel = ProfileViewModell(context: dcContext)
+        cell.updateCell(cellViewModel: cellViewModel)
         cell.tag = CellTags.profile.rawValue
         cell.tag = CellTags.profile.rawValue
+        cell.accessoryType = .disclosureIndicator
         return cell
         return cell
     }()
     }()
 
 
@@ -428,15 +426,15 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
 
 
     // MARK: - updates
     // MARK: - updates
     private func updateCells() {
     private func updateCells() {
-        let displayName = dcContext.displayname ?? String.localized("pref_your_name")
-        let email = dcContext.addr ?? ""
-        let selfContact = DcContact(id: Int(DC_CONTACT_ID_SELF))
-        profileCell.update(contact: selfContact, displayName: displayName, address: email)
-
         showEmailsCell.detailTextLabel?.text = SettingsClassicViewController.getValString(val: dcContext.showEmails)
         showEmailsCell.detailTextLabel?.text = SettingsClassicViewController.getValString(val: dcContext.showEmails)
         mediaQualityCell.detailTextLabel?.text = MediaQualityController.getValString(val: dcContext.getConfigInt("media_quality"))
         mediaQualityCell.detailTextLabel?.text = MediaQualityController.getValString(val: dcContext.getConfigInt("media_quality"))
 
 
         autodelCell.detailTextLabel?.text = autodelSummary()
         autodelCell.detailTextLabel?.text = autodelSummary()
+       // let displayName = dcContext.displayname ?? String.localized("pref_your_name")
+       // let email = dcContext.addr ?? ""
+       // let selfContact = DcContact(id: Int(DC_CONTACT_ID_SELF))
+        //profileCell.update(contact: selfContact, displayName: displayName, address: email)
+        profileCell.updateCell(cellViewModel: ProfileViewModell(context: dcContext))
     }
     }
 
 
     // MARK: - coordinator
     // MARK: - coordinator

+ 30 - 5
deltachat-ios/View/ContactCell.swift

@@ -8,7 +8,13 @@ protocol ContactCellDelegate: class {
 class ContactCell: UITableViewCell {
 class ContactCell: UITableViewCell {
 
 
     static let reuseIdentifier = "contact_cell_reuse_identifier"
     static let reuseIdentifier = "contact_cell_reuse_identifier"
-    static let cellHeight: CGFloat = 74.5
+    static var cellHeight: CGFloat {
+        let textHeight = UIFont.preferredFont(forTextStyle: .headline).pointSize + UIFont.preferredFont(forTextStyle: .subheadline).pointSize + 24
+        if textHeight > 74.5 {
+            return textHeight
+        }
+        return 74.5
+    }
 
 
     weak var delegate: ContactCellDelegate?
     weak var delegate: ContactCellDelegate?
     private let badgeSize: CGFloat = 54
     private let badgeSize: CGFloat = 54
@@ -156,7 +162,9 @@ class ContactCell: UITableViewCell {
             avatar.constraintWidthTo(badgeSize),
             avatar.constraintWidthTo(badgeSize),
             avatar.constraintHeightTo(badgeSize),
             avatar.constraintHeightTo(badgeSize),
             avatar.constraintAlignLeadingTo(contentView, paddingLeading: badgeSize / 4),
             avatar.constraintAlignLeadingTo(contentView, paddingLeading: badgeSize / 4),
-            avatar.constraintCenterYTo(contentView),
+            avatar.constraintAlignTopTo(contentView, paddingTop: badgeSize / 4, priority: .defaultLow),
+            avatar.constraintAlignBottomTo(contentView, paddingBottom: badgeSize / 4, priority: .defaultLow),
+            avatar.constraintCenterYTo(contentView, priority: .required),
         ])
         ])
 
 
         deliveryStatusIndicator.translatesAutoresizingMaskIntoConstraints = false
         deliveryStatusIndicator.translatesAutoresizingMaskIntoConstraints = false
@@ -168,12 +176,12 @@ class ContactCell: UITableViewCell {
         verticalStackView.clipsToBounds = true
         verticalStackView.clipsToBounds = true
 
 
         contentView.addSubview(verticalStackView)
         contentView.addSubview(verticalStackView)
+        verticalStackView.addArrangedSubview(toplineStackView)
+        verticalStackView.addArrangedSubview(bottomlineStackView)
         verticalStackView.leadingAnchor.constraint(equalTo: avatar.trailingAnchor, constant: margin).isActive = true
         verticalStackView.leadingAnchor.constraint(equalTo: avatar.trailingAnchor, constant: margin).isActive = true
-        verticalStackView.centerYAnchor.constraint(equalTo: avatar.centerYAnchor).isActive = true
+        verticalStackView.constraintCenterYTo(avatar, priority: .required).isActive = true
         verticalStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -margin).isActive = true
         verticalStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -margin).isActive = true
         verticalStackView.axis = .vertical
         verticalStackView.axis = .vertical
-        verticalStackView.addArrangedSubview(toplineStackView)
-        verticalStackView.addArrangedSubview(bottomlineStackView)
 
 
         toplineStackView.addConstraints([
         toplineStackView.addConstraints([
             pinnedIndicator.constraintHeightTo(titleLabel.font.pointSize * 1.2),
             pinnedIndicator.constraintHeightTo(titleLabel.font.pointSize * 1.2),
@@ -315,6 +323,23 @@ class ContactCell: UITableViewCell {
                                 visibility: 0,
                                 visibility: 0,
                                 isLocationStreaming: false,
                                 isLocationStreaming: false,
                                 isMuted: false)
                                 isMuted: false)
+        case .profile:
+            let contact = DcContact(id: Int(DC_CONTACT_ID_SELF))
+            titleLabel.text = cellViewModel.title
+            subtitleLabel.text = cellViewModel.subtitle
+            if let profileImage = contact.profileImage {
+                avatar.setImage(profileImage)
+            } else {
+                avatar.setName(cellViewModel.title)
+                avatar.setColor(contact.color)
+            }
+            setVerified(isVerified: false)
+            setStatusIndicators(unreadCount: 0,
+            status: 0,
+            visibility: 0,
+            isLocationStreaming: false,
+            isMuted: false)
         }
         }
+
     }
     }
 }
 }

+ 2 - 0
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -144,6 +144,8 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
             return data.chatId
             return data.chatId
         case .contact:
         case .contact:
             return nil
             return nil
+        case .profile:
+            return nil
         }
         }
     }
     }
 
 

+ 27 - 0
deltachat-ios/ViewModel/ContactCellViewModel.swift

@@ -13,6 +13,7 @@ enum CellModel {
     case contact(ContactCellData)
     case contact(ContactCellData)
     case chat(ChatCellData)
     case chat(ChatCellData)
     case deaddrop(DeaddropCellData)
     case deaddrop(DeaddropCellData)
+    case profile
 }
 }
 
 
 struct ContactCellData {
 struct ContactCellData {
@@ -59,6 +60,32 @@ class ContactCellViewModel: AvatarCellViewModel {
     }
     }
 }
 }
 
 
+class ProfileViewModell: AvatarCellViewModel {
+    var type: CellModel {
+        return CellModel.profile
+    }
+
+    var title: String
+
+    private let contact: DcContact
+
+    var titleHighlightIndexes: [Int] {
+        return []
+    }
+
+    var subtitle: String
+
+    var subtitleHighlightIndexes: [Int] {
+        return []
+    }
+
+    init(context: DcContext) {
+        contact = DcContact(id: Int(DC_CONTACT_ID_SELF))
+        title = context.displayname ?? String.localized("pref_your_name")
+        subtitle = context.addr ?? ""
+    }
+}
+
 class ChatCellViewModel: AvatarCellViewModel {
 class ChatCellViewModel: AvatarCellViewModel {
 
 
     private let chat: DcChat
     private let chat: DcChat