nayooti 5 жил өмнө
parent
commit
e41079bc35

+ 7 - 7
deltachat-ios/Controller/ChatListController.swift

@@ -237,25 +237,25 @@ class ChatListController: UITableViewController {
         }
         let archiveActionTitle: String = String.localized(viewModel.isArchive ? "unarchive" : "archive")
 
-        let archive = UITableViewRowAction(style: .destructive, title: archiveActionTitle) { [unowned self] _, _ in
+        let archiveAction = UITableViewRowAction(style: .destructive, title: archiveActionTitle) { [unowned self] _, _ in
             self.viewModel.archiveChat(chatId: chatId)
             self.updateArchivedCell()
         }
-        archive.backgroundColor = UIColor.lightGray
+        archiveAction.backgroundColor = UIColor.lightGray
 
         let chat = DcChat(id: chatId)
         let pinned = chat.visibility==DC_CHAT_VISIBILITY_PINNED
-        let pin = UITableViewRowAction(style: .destructive, title: String.localized(pinned ? "unpin" : "pin")) { [unowned self] _, _ in
+        let pinAction = UITableViewRowAction(style: .destructive, title: String.localized(pinned ? "unpin" : "pin")) { [unowned self] _, _ in
             self.viewModel.pinChat(chatId: chat.id)
         }
-        pin.backgroundColor = UIColor.systemGreen
+        pinAction.backgroundColor = UIColor.systemGreen
 
-        let delete = UITableViewRowAction(style: .normal, title: String.localized("delete")) { [unowned self] _, _ in
+        let deleteAction = UITableViewRowAction(style: .normal, title: String.localized("delete")) { [unowned self] _, _ in
             self.showDeleteChatConfirmationAlert(chatId: chatId)
         }
-        delete.backgroundColor = UIColor.systemRed
+        deleteAction.backgroundColor = UIColor.systemRed
 
-        return [archive, pin, delete]
+        return [archiveAction, pinAction, deleteAction]
     }
 
     // MARK: updates

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

@@ -16,6 +16,7 @@ protocol ChatListViewModelProtocol: class, UISearchResultsUpdating {
     var searchActive: Bool { get }
     func beginFiltering()
     func endFiltering()
+    func titleForHeaderIn(section: Int) -> String?
 
     /// returns ROW of table
     func deleteChat(chatId: Int) -> Int
@@ -30,6 +31,30 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
 
     var onChatListUpdate: VoidFunction?
 
+    enum ChatListSectionType {
+        case chats
+        case contacts
+        case messages
+    }
+
+    class ChatListSection {
+        let type: ChatListSectionType
+        var title: String {
+            switch type {
+            case .chats:
+                return String.localized("pref_chats")
+            case .contacts:
+                return String.localized("contacts_headline")
+            case .messages:
+                return String.localized("pref_messages")
+            }
+        }
+        var cellData: [AvatarCellViewModel] = []
+        init(type: ChatListSectionType) {
+            self.type = type
+        }
+    }
+
     var isArchive: Bool
     private let dcContext: DcContext
 
@@ -37,6 +62,16 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
 
     private var chatList: DcChatlist!
 
+    // for search filtering
+    var filteredChats: ChatListSection = ChatListSection(type: .chats)
+    var filteredContacts: ChatListSection = ChatListSection(type: .contacts)
+    var filteredMessages: ChatListSection = ChatListSection(type: .messages)
+
+    private var searchResultSections: [ChatListSection] {
+        return [filteredChats, filteredContacts, filteredMessages]
+            .filter { !$0.cellData.isEmpty } //
+    }
+
     init(dcContext: DcContext, isArchive: Bool) {
         dcContext.updateDeviceChats()
         self.isArchive = isArchive
@@ -78,6 +113,13 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
         return viewModel
     }
 
+    func titleForHeaderIn(section: Int) -> String? {
+        if searchActive {
+            return searchResultSections[section].title
+        }
+        return nil
+    }
+
     func chatIdFor(section: Int, row: Int) -> Int? {
         let cellData = cellDataFor(section: section, row: row)
         switch cellData.type {