Explorar el Código

Merge pull request #1316 from deltachat/archived_chats_in_settings

add archived chats entry to settings
bjoern hace 3 años
padre
commit
892f45c12c

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

@@ -74,8 +74,8 @@ class ChatListController: UITableViewController {
     // MARK: - lifecycle
     override func viewDidLoad() {
         super.viewDidLoad()
-        navigationItem.rightBarButtonItem = newButton
         if !viewModel.isArchive {
+            navigationItem.rightBarButtonItem = newButton
             navigationItem.searchController = searchController
         }
         configureTableView()
@@ -169,7 +169,7 @@ class ChatListController: UITableViewController {
     // MARK: - setup
     private func setupSubviews() {
         emptySearchStateLabel.addCenteredTo(parentView: view)
-        navigationItem.backButtonTitle = String.localized("pref_chats")
+        navigationItem.backButtonTitle = viewModel.isArchive ? String.localized("chat_archived_chats_title") : String.localized("pref_chats")
     }
 
     @objc
@@ -302,7 +302,7 @@ class ChatListController: UITableViewController {
         case .chat(let chatData):
             let chatId = chatData.chatId
             if chatId == DC_CHAT_ID_ARCHIVED_LINK {
-                showArchive()
+                showArchive(animated: true)
             } else {
                 showChat(chatId: chatId, highlightedMsg: chatData.highlightMsgId)
             }
@@ -504,10 +504,10 @@ class ChatListController: UITableViewController {
         navigationController?.pushViewController(chatVC, animated: animated)
     }
 
-    private func showArchive() {
+    public func showArchive(animated: Bool) {
         let viewModel = ChatListViewModel(dcContext: dcContext, isArchive: true)
         let controller = ChatListController(dcContext: dcContext, viewModel: viewModel)
-        navigationController?.pushViewController(controller, animated: true)
+        navigationController?.pushViewController(controller, animated: animated)
     }
 
     private func showNewChat(contactId: Int) {

+ 16 - 1
deltachat-ios/Controller/SettingsController.swift

@@ -13,6 +13,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
 
     private enum CellTags: Int {
         case profile = 0
+        case showArchive = 1
         case showEmails = 2
         case blockedContacts = 3
         case notifications = 4
@@ -52,6 +53,14 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         return cell
     }()
 
+    private lazy var showArchiveCell: UITableViewCell = {
+        let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
+        cell.tag = CellTags.showArchive.rawValue
+        cell.textLabel?.text = String.localized("chat_archived_chats_title")
+        cell.accessoryType = .disclosureIndicator
+        return cell
+    }()
+
     private lazy var showEmailsCell: UITableViewCell = {
         let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
         cell.tag = CellTags.showEmails.rawValue
@@ -211,7 +220,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         let preferencesSection = SectionConfigs(
             headerTitle: String.localized("pref_chats_and_media"),
             footerTitle: String.localized("pref_read_receipts_explain"),
-            cells: [showEmailsCell, blockedContactsCell, autodelCell, mediaQualityCell, videoChatInstanceCell, notificationCell, receiptConfirmationCell]
+            cells: [showArchiveCell, showEmailsCell, blockedContactsCell, autodelCell, mediaQualityCell, videoChatInstanceCell, notificationCell, receiptConfirmationCell]
         )
         let autocryptSection = SectionConfigs(
             headerTitle: String.localized("autocrypt"),
@@ -316,6 +325,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
 
         switch cellTag {
         case .profile: showEditSettingsController()
+        case .showArchive: showArchivedCharts()
         case .showEmails: showClassicMail()
         case .blockedContacts: showBlockedContacts()
         case .autodel: showAutodelOptions()
@@ -563,6 +573,11 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         navigationController?.pushViewController(videoInstanceController, animated: true)
     }
 
+    private func showArchivedCharts() {
+        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
+        appDelegate.appCoordinator.showArchivedChats()
+    }
+
     private func showBlockedContacts() {
         let blockedContactsController = BlockedContactsViewController(dcContext: dcContext)
         navigationController?.pushViewController(blockedContactsController, animated: true)

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

@@ -84,6 +84,16 @@ class AppCoordinator {
         tabBarController.selectedIndex = index
     }
 
+    func showArchivedChats() {
+        showTab(index: chatsTab)
+
+        if let rootController = self.tabBarController.selectedViewController as? UINavigationController,
+           let chatListController = rootController.viewControllers.first as? ChatListController {
+            rootController.popToRootViewController(animated: false)
+            chatListController.showArchive(animated: false)
+        }
+    }
+
     func showChat(chatId: Int, msgId: Int? = nil, animated: Bool = true, clearViewControllerStack: Bool = false) {
         showTab(index: chatsTab)