Explorar el Código

move 'export backup' to 'chats and media' as it is explained like that everywhere

B. Petersen hace 2 años
padre
commit
2c32ac13f6

+ 5 - 44
deltachat-ios/Controller/Settings/AdvancedViewController.swift

@@ -16,7 +16,6 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
         case manageKeys
         case manageKeys
         case experimentalFeatures
         case experimentalFeatures
         case videoChat
         case videoChat
-        case exportBackup
         case viewLog
         case viewLog
     }
     }
 
 
@@ -77,13 +76,6 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
         return cell
         return cell
     }()
     }()
 
 
-    private lazy var exportBackupCell: ActionCell = {
-        let cell = ActionCell()
-        cell.tag = CellTags.exportBackup.rawValue
-        cell.actionTitle = String.localized("export_backup_desktop")
-        return cell
-    }()
-
     private lazy var viewLogCell: ActionCell = {
     private lazy var viewLogCell: ActionCell = {
         let cell = ActionCell()
         let cell = ActionCell()
         cell.tag = CellTags.viewLog.rawValue
         cell.tag = CellTags.viewLog.rawValue
@@ -101,15 +93,11 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
             headerTitle: nil,
             headerTitle: nil,
             footerTitle: nil,
             footerTitle: nil,
             cells: [manageKeysCell, experimentalFeaturesCell, videoChatInstanceCell])
             cells: [manageKeysCell, experimentalFeaturesCell, videoChatInstanceCell])
-        let backupSection = SectionConfigs(
-            headerTitle: nil,
-            footerTitle: String.localized("pref_backup_explain"),
-            cells: [exportBackupCell])
         let viewLogSection = SectionConfigs(
         let viewLogSection = SectionConfigs(
             headerTitle: nil,
             headerTitle: nil,
             footerTitle: nil,
             footerTitle: nil,
             cells: [viewLogCell])
             cells: [viewLogCell])
-        return [autocryptSection, miscSection, backupSection, viewLogSection]
+        return [autocryptSection, miscSection, viewLogSection]
     }()
     }()
 
 
     init(dcAccounts: DcAccounts) {
     init(dcAccounts: DcAccounts) {
@@ -138,19 +126,7 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
         super.viewDidAppear(animated)
         super.viewDidAppear(animated)
         addProgressAlertListener(dcAccounts: dcAccounts, progressName: dcNotificationImexProgress) { [weak self] in
         addProgressAlertListener(dcAccounts: dcAccounts, progressName: dcNotificationImexProgress) { [weak self] in
             guard let self = self else { return }
             guard let self = self else { return }
-
-            self.progressAlert?.dismiss(animated: true) {
-                let alert = UIAlertController(
-                    title: String.localized("backup_successful"),
-                    message: String.localizedStringWithFormat(String.localized("backup_successful_explain_ios"), "\(String.localized("Files")) ➔ Delta Chat"),
-                    preferredStyle: .alert)
-                alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
-                    if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-                        appDelegate.reloadDcContext()
-                    }
-                }))
-                self.present(alert, animated: true, completion: nil)
-            }
+            self.progressAlert?.dismiss(animated: true)
         }
         }
     }
     }
 
 
@@ -163,7 +139,6 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
     }
     }
 
 
     // MARK: - UITableViewDelegate + UITableViewDatasource
     // MARK: - UITableViewDelegate + UITableViewDatasource
-
     override func numberOfSections(in tableView: UITableView) -> Int {
     override func numberOfSections(in tableView: UITableView) -> Int {
         return sections.count
         return sections.count
     }
     }
@@ -189,7 +164,6 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
         case .manageKeys: showManageKeysDialog()
         case .manageKeys: showManageKeysDialog()
         case .experimentalFeatures: showExperimentalDialog()
         case .experimentalFeatures: showExperimentalDialog()
         case .videoChat: showVideoChatInstance()
         case .videoChat: showVideoChatInstance()
-        case .exportBackup: createBackup()
         case .viewLog: showLogViewController()
         case .viewLog: showLogViewController()
         }
         }
     }
     }
@@ -203,17 +177,6 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
     }
     }
 
 
     // MARK: - actions
     // MARK: - actions
-
-    private func createBackup() {
-        let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .safeActionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("pref_backup_export_start_button"), style: .default, handler: { _ in
-            self.dismiss(animated: true, completion: nil)
-            self.startImex(what: DC_IMEX_EXPORT_BACKUP)
-        }))
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
-        present(alert, animated: true, completion: nil)
-    }
-
     @objc private func handleAutocryptPreferencesToggle(_ sender: UISwitch) {
     @objc private func handleAutocryptPreferencesToggle(_ sender: UISwitch) {
         dcContext.e2eeEnabled = sender.isOn
         dcContext.e2eeEnabled = sender.isOn
     }
     }
@@ -294,7 +257,7 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
 
 
         alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_export_secret_keys"), style: .default, handler: { _ in
         alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_export_secret_keys"), style: .default, handler: { _ in
             let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_export_explain"), self.externalPathDescr)
             let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_export_explain"), self.externalPathDescr)
-            let alert = UIAlertController(title: nil, message: msg, preferredStyle: .alert)
+            let alert = UIAlertController(title: String.localized("pref_managekeys_export_secret_keys"), message: msg, preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
             alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
                 self.startImex(what: DC_IMEX_EXPORT_SELF_KEYS)
                 self.startImex(what: DC_IMEX_EXPORT_SELF_KEYS)
             }))
             }))
@@ -304,7 +267,7 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
 
 
         alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_import_secret_keys"), style: .default, handler: { _ in
         alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_import_secret_keys"), style: .default, handler: { _ in
             let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_import_explain"), self.externalPathDescr)
             let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_import_explain"), self.externalPathDescr)
-            let alert = UIAlertController(title: nil, message: msg, preferredStyle: .alert)
+            let alert = UIAlertController(title: String.localized("pref_managekeys_import_secret_keys"), message: msg, preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
             alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
                 self.startImex(what: DC_IMEX_IMPORT_SELF_KEYS)
                 self.startImex(what: DC_IMEX_IMPORT_SELF_KEYS)
             }))
             }))
@@ -325,7 +288,7 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
     private func startImex(what: Int32, passphrase: String? = nil) {
     private func startImex(what: Int32, passphrase: String? = nil) {
         let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
         let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
         if !documents.isEmpty {
         if !documents.isEmpty {
-            showProgressAlert(title: String.localized("imex_progress_title_desktop"), dcContext: dcContext)
+            showProgressAlert(title: String.localized(what==DC_IMEX_IMPORT_SELF_KEYS ? "pref_managekeys_import_secret_keys" : "pref_managekeys_export_secret_keys"), dcContext: dcContext)
             DispatchQueue.main.async {
             DispatchQueue.main.async {
                 self.dcAccounts.stopIo()
                 self.dcAccounts.stopIo()
                 self.dcContext.imex(what: what, directory: documents[0], passphrase: passphrase)
                 self.dcContext.imex(what: what, directory: documents[0], passphrase: passphrase)
@@ -336,13 +299,11 @@ internal final class AdvancedViewController: UITableViewController, ProgressAler
     }
     }
 
 
     // MARK: - updates
     // MARK: - updates
-
     private func updateCells() {
     private func updateCells() {
         videoChatInstanceCell.detailTextLabel?.text = VideoChatInstanceViewController.getValString(val: dcContext.getConfig("webrtc_instance") ?? "")
         videoChatInstanceCell.detailTextLabel?.text = VideoChatInstanceViewController.getValString(val: dcContext.getConfig("webrtc_instance") ?? "")
     }
     }
 
 
     // MARK: - coordinator
     // MARK: - coordinator
-
     private func showVideoChatInstance() {
     private func showVideoChatInstance() {
         let videoInstanceController = VideoChatInstanceViewController(dcContext: dcContext)
         let videoInstanceController = VideoChatInstanceViewController(dcContext: dcContext)
         navigationController?.pushViewController(videoInstanceController, animated: true)
         navigationController?.pushViewController(videoInstanceController, animated: true)

+ 58 - 2
deltachat-ios/Controller/Settings/SettingsViewController.swift

@@ -2,7 +2,7 @@ import UIKit
 import DcCore
 import DcCore
 import Intents
 import Intents
 
 
-internal final class SettingsViewController: UITableViewController {
+internal final class SettingsViewController: UITableViewController, ProgressAlertHandler {
 
 
     private struct SectionConfigs {
     private struct SectionConfigs {
         let headerTitle: String?
         let headerTitle: String?
@@ -16,6 +16,7 @@ internal final class SettingsViewController: UITableViewController {
         case blockedContacts
         case blockedContacts
         case notifications
         case notifications
         case receiptConfirmation
         case receiptConfirmation
+        case exportBackup
         case advanced
         case advanced
         case help
         case help
         case autodel
         case autodel
@@ -30,6 +31,10 @@ internal final class SettingsViewController: UITableViewController {
 
 
     private var connectivityChangedObserver: NSObjectProtocol?
     private var connectivityChangedObserver: NSObjectProtocol?
 
 
+    // MARK: - ProgressAlertHandler
+    weak var progressAlert: UIAlertController?
+    var progressObserver: NSObjectProtocol?
+
     // MARK: - cells
     // MARK: - cells
     private lazy var profileCell: ContactCell = {
     private lazy var profileCell: ContactCell = {
         let cell = ContactCell(style: .default, reuseIdentifier: nil)
         let cell = ContactCell(style: .default, reuseIdentifier: nil)
@@ -126,6 +131,14 @@ internal final class SettingsViewController: UITableViewController {
         return cell
         return cell
     }()
     }()
 
 
+    private lazy var exportBackupCell: UITableViewCell = {
+        let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
+        cell.tag = CellTags.exportBackup.rawValue
+        cell.textLabel?.text = String.localized("export_backup_desktop")
+        cell.accessoryType = .disclosureIndicator
+        return cell
+    }()
+
     private lazy var advancedCell: UITableViewCell = {
     private lazy var advancedCell: UITableViewCell = {
         let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
         let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
         cell.tag = CellTags.advanced.rawValue
         cell.tag = CellTags.advanced.rawValue
@@ -171,7 +184,7 @@ internal final class SettingsViewController: UITableViewController {
             headerTitle: String.localized("pref_chats_and_media"),
             headerTitle: String.localized("pref_chats_and_media"),
             footerTitle: String.localized("pref_read_receipts_explain"),
             footerTitle: String.localized("pref_read_receipts_explain"),
             cells: [showEmailsCell, blockedContactsCell, mediaQualityCell, downloadOnDemandCell,
             cells: [showEmailsCell, blockedContactsCell, mediaQualityCell, downloadOnDemandCell,
-                    autodelCell, notificationCell, receiptConfirmationCell]
+                    autodelCell, exportBackupCell, notificationCell, receiptConfirmationCell]
         )
         )
         let appearanceSection = SectionConfigs(
         let appearanceSection = SectionConfigs(
             headerTitle: String.localized("pref_appearance"),
             headerTitle: String.localized("pref_appearance"),
@@ -220,9 +233,28 @@ internal final class SettingsViewController: UITableViewController {
         updateCells()
         updateCells()
     }
     }
 
 
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
+        addProgressAlertListener(dcAccounts: dcAccounts, progressName: dcNotificationImexProgress) { [weak self] in
+            guard let self = self else { return }
+
+            self.progressAlert?.dismiss(animated: true) {
+                let alert = UIAlertController(
+                    title: String.localized("backup_successful"),
+                    message: String.localizedStringWithFormat(String.localized("backup_successful_explain_ios"), "\(String.localized("Files")) ➔ Delta Chat"),
+                    preferredStyle: .alert)
+                alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+                self.present(alert, animated: true, completion: nil)
+            }
+        }
+    }
+
     override func viewDidDisappear(_ animated: Bool) {
     override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
         super.viewDidDisappear(animated)
         let nc = NotificationCenter.default
         let nc = NotificationCenter.default
+        if let backupProgressObserver = self.progressObserver {
+            nc.removeObserver(backupProgressObserver)
+        }
         if let connectivityChangedObserver = self.connectivityChangedObserver {
         if let connectivityChangedObserver = self.connectivityChangedObserver {
             NotificationCenter.default.removeObserver(connectivityChangedObserver)
             NotificationCenter.default.removeObserver(connectivityChangedObserver)
         }
         }
@@ -267,6 +299,7 @@ internal final class SettingsViewController: UITableViewController {
         case .downloadOnDemand: showDownloadOnDemand()
         case .downloadOnDemand: showDownloadOnDemand()
         case .notifications: break
         case .notifications: break
         case .receiptConfirmation: break
         case .receiptConfirmation: break
+        case .exportBackup: createBackup()
         case .advanced: showAdvanced()
         case .advanced: showAdvanced()
         case .help: showHelp()
         case .help: showHelp()
         case .connectivity: showConnectivity()
         case .connectivity: showConnectivity()
@@ -284,6 +317,16 @@ internal final class SettingsViewController: UITableViewController {
 
 
     // MARK: - actions
     // MARK: - actions
 
 
+    private func createBackup() {
+        let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .safeActionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("pref_backup_export_start_button"), style: .default, handler: { _ in
+            self.dismiss(animated: true, completion: nil)
+            self.startImex(what: DC_IMEX_EXPORT_BACKUP)
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+        present(alert, animated: true, completion: nil)
+    }
+
     @objc private func handleNotificationToggle(_ sender: UISwitch) {
     @objc private func handleNotificationToggle(_ sender: UISwitch) {
         UserDefaults.standard.set(!sender.isOn, forKey: "notifications_disabled")
         UserDefaults.standard.set(!sender.isOn, forKey: "notifications_disabled")
         if sender.isOn {
         if sender.isOn {
@@ -302,6 +345,19 @@ internal final class SettingsViewController: UITableViewController {
     }
     }
 
 
     // MARK: - updates
     // MARK: - updates
+    private func startImex(what: Int32, passphrase: String? = nil) {
+        let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
+        if !documents.isEmpty {
+            showProgressAlert(title: String.localized("export_backup_desktop"), dcContext: dcContext)
+            DispatchQueue.main.async {
+                self.dcAccounts.stopIo()
+                self.dcContext.imex(what: what, directory: documents[0], passphrase: passphrase)
+            }
+        } else {
+            logger.error("document directory not found")
+        }
+    }
+
     private func updateCells() {
     private func updateCells() {
         profileCell.updateCell(cellViewModel: ProfileViewModel(context: dcContext))
         profileCell.updateCell(cellViewModel: ProfileViewModel(context: dcContext))
         showEmailsCell.detailTextLabel?.text = EmailOptionsViewController.getValString(val: dcContext.showEmails)
         showEmailsCell.detailTextLabel?.text = EmailOptionsViewController.getValString(val: dcContext.showEmails)