Browse Source

contact cell now can be updated via cellViewModel

nayooti 5 years ago
parent
commit
a628b22c08

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

@@ -308,6 +308,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
             cell.setDeliveryStatusIndicator(summary.state)
         case .CONTACT(let contactData):
             let contactId = contactData.contactId
+            cell.updateCell(cellViewModel: cellViewModel)
         }
     }
 

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

@@ -192,4 +192,20 @@ class ContactCell: UITableViewCell {
     required init?(coder _: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
+
+    func updateCell(cellViewModel: AvatarCellViewModel) {
+
+        // title
+        nameLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: nameLabel.font.pointSize)
+        // subtitle
+        emailLabel.attributedText = cellViewModel.subtitle.boldAt(indexes: cellViewModel.subtitleHighlightIndexes, fontSize: emailLabel.font.pointSize)
+
+        switch cellViewModel.type {
+        case .CHAT(let chatData):
+            break
+        case .CONTACT(let contactData):
+            break
+        }
+    }
+
 }

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

@@ -3,7 +3,9 @@ import UIKit
 protocol AvatarCellViewModel {
     var type: CellModel { get }
     var title: String { get }
+    var titleHighlightIndexes: [Int] { get }
     var subtitle: String { get }
+    var subtitleHighlightIndexes: [Int] { get }
     var avartarTitle: String { get }
     // var avatarColor: String { get }
     // add highlighting search results
@@ -55,8 +57,13 @@ class ContactCellViewModel: AvatarCellViewModel {
         return "CON"
     }
 
-    init(contactData: ContactCellData) {
+    var titleHighlightIndexes: [Int]
+    var subtitleHighlightIndexes: [Int]
+
+    init(contactData: ContactCellData, titleHighlightIndexes: [Int] = [], subtitleHighlightIndexes: [Int] = []) {
         type = CellModel.CONTACT(contactData)
+        self.titleHighlightIndexes = titleHighlightIndexes
+        self.subtitleHighlightIndexes = subtitleHighlightIndexes
     }
 }
 
@@ -75,8 +82,13 @@ class ChatCellViewModel: AvatarCellViewModel{
         return "ABC"
     }
 
-    init(chatData: ChatCellData) {
+    var titleHighlightIndexes: [Int]
+    var subtitleHighlightIndexes: [Int]
+
+    init(chatData: ChatCellData, titleHighlightIndexes: [Int] = [], subtitleHighlightIndexes: [Int] = []) {
         self.type = CellModel.CHAT(chatData)
+        self.titleHighlightIndexes = titleHighlightIndexes
+        self.subtitleHighlightIndexes = subtitleHighlightIndexes
     }
 }