Explorar el Código

update header on viewWillAppear in ContactDetail

nayooti hace 5 años
padre
commit
1706dc5e45

+ 7 - 2
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -85,6 +85,7 @@ class ContactDetailViewController: UITableViewController {
 
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
+        updateHeader() // maybe contact name has been edited
         tableView.reloadData()
     }
 
@@ -94,10 +95,10 @@ class ContactDetailViewController: UITableViewController {
         tableView.register(ContactCell.self, forCellReuseIdentifier: ContactCell.reuseIdentifier)
         headerCell.frame = CGRect(0, 0, tableView.frame.width, ContactCell.cellHeight)
         tableView.tableHeaderView = headerCell
-
     }
 
     // MARK: - UITableViewDatasource, UITableViewDelegate
+
     override func numberOfSections(in tableView: UITableView) -> Int {
         return viewModel.numberOfSections
     }
@@ -171,8 +172,12 @@ class ContactDetailViewController: UITableViewController {
         return Constants.defaultHeaderHeight
     }
 
-    // MARK: - actions
+    // MARK: - updates
+    private func updateHeader() {
+        headerCell.updateDetails(title: viewModel.contact.displayName, subtitle: viewModel.contact.email)
+    }
 
+    // MARK: - actions
     private func handleCellAction(for index: Int) {
         let action = viewModel.chatActionFor(row: index)
         switch action {

+ 5 - 2
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -18,6 +18,7 @@ protocol ContactDetailViewModelProtocol {
 class ContactDetailViewModel: ContactDetailViewModelProtocol {
 
     let context: DcContext
+
     enum ProfileSections {
         case startChat
         case attachments
@@ -38,7 +39,10 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
 
     var contactId: Int
 
-    var contact: DcContact
+    var contact: DcContact {
+        return DcContact(id: contactId)
+    }
+
     private let chatId: Int?
     private let sharedChats: DcChatlist
     private var sections: [ProfileSections] = []
@@ -50,7 +54,6 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
         self.context = context
         self.contactId = contactId
         self.chatId = chatId
-        self.contact = DcContact(id: contactId)
         self.sharedChats = context.getChatlist(flags: 0, queryString: nil, queryId: contactId)
 
         sections.append(.attachments)