Просмотр исходного кода

Merge pull request #198 from deltachat/archive-chats3

archive chats
björn petersen 5 лет назад
Родитель
Сommit
6199034645

+ 13 - 4
deltachat-ios/Controller/ChatListController.swift

@@ -84,7 +84,12 @@ class ChatListController: UIViewController {
 
     override func viewDidLoad() {
         super.viewDidLoad()
+
         title = String.localized("pref_chats")
+        if showArchive {
+            title = String.localized("chat_archived_chats_title")
+        }
+
         navigationController?.navigationBar.prefersLargeTitles = true
 
         newButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.compose, target: self, action: #selector(didPressNewChat))
@@ -171,7 +176,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
         let row = indexPath.row
         if let chatId = chatList?.getChatId(index: row) {
             if chatId==DC_CHAT_ID_ARCHIVED_LINK {
-                // TODO
+                coordinator?.showArchive()
             } else {
                 coordinator?.showChat(chatId: chatId)
             }
@@ -191,10 +196,14 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
             // see https://forums.developer.apple.com/thread/115030
         }
 
-        let archive = UITableViewRowAction(style: .destructive, title: String.localized("menu_archive_chat")) { [unowned self] _, _ in
-            self.dcContext.archiveChat(chatId: chatId, archive: true)
+        var title = String.localized("menu_archive_chat")
+        if showArchive {
+            title = String.localized("menu_unarchive_chat")
+        }
+        let archive = UITableViewRowAction(style: .destructive, title: title) { [unowned self] _, _ in
+            self.dcContext.archiveChat(chatId: chatId, archive: !self.showArchive)
         }
-        archive.backgroundColor = UIColor.gray
+        archive.backgroundColor = UIColor.lightGray
 
         let delete = UITableViewRowAction(style: .destructive, title: String.localized("menu_delete_chat")) { [unowned self] _, _ in
             self.showDeleteChatConfirmationAlert(chatId: chatId)

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

@@ -230,6 +230,14 @@ class ChatListCoordinator: Coordinator {
         chatVC.coordinator = coordinator
         navigationController.pushViewController(chatVC, animated: true)
     }
+
+    func showArchive() {
+        let controller = ChatListController(dcContext: dcContext, showArchive: true)
+        let coordinator = ChatListCoordinator(dcContext: dcContext, navigationController: navigationController)
+        childCoordinators.append(coordinator)
+        controller.coordinator = coordinator
+        navigationController.pushViewController(controller, animated: true)
+    }
 }
 
 class SettingsCoordinator: Coordinator {