Skip to content

Commit

Permalink
Migrate key import/export to use new alert-view
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Jul 25, 2024
1 parent bb3bc05 commit a8d7259
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions deltachat-ios/Controller/Settings/AdvancedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UIKit
import DcCore
import Intents

internal final class AdvancedViewController: UITableViewController, LegacyProgressAlertHandler {
internal final class AdvancedViewController: UITableViewController {

private struct SectionConfigs {
let headerTitle: String?
Expand All @@ -26,9 +26,7 @@ internal final class AdvancedViewController: UITableViewController, LegacyProgre

private let externalPathDescr = "File Sharing/Delta Chat"

// MARK: - LegacyProgressAlertHandler
weak var progressAlert: UIAlertController?
var progressObserver: NSObjectProtocol?
var progressAlertHandler: ProgressAlertHandler?

// MARK: - cells
private lazy var showEmailsCell: UITableViewCell = {
Expand Down Expand Up @@ -286,21 +284,6 @@ internal final class AdvancedViewController: UITableViewController, LegacyProgre
updateCells()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
addProgressAlertListener(dcAccounts: dcAccounts, progressName: Event.importExportProgress) { [weak self] in
guard let self else { return }
self.progressAlert?.dismiss(animated: true)
}
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
if let progressObserver {
NotificationCenter.default.removeObserver(progressObserver)
}
}

// MARK: - UITableViewDelegate + UITableViewDatasource
override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
Expand Down Expand Up @@ -426,16 +409,23 @@ internal final class AdvancedViewController: UITableViewController, LegacyProgre
}

private func startImex(what: Int32, passphrase: String? = nil) {

let progressHandler = ProgressAlertHandler(dcAccounts: self.dcAccounts, notification: Event.importExportProgress)
progressHandler.dataSource = self

let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
if !documents.isEmpty {
showProgressAlert(title: String.localized(what==DC_IMEX_IMPORT_SELF_KEYS ? "pref_managekeys_import_secret_keys" : "pref_managekeys_export_secret_keys"), dcContext: dcContext)
let alertTitle = String.localized(what==DC_IMEX_IMPORT_SELF_KEYS ? "pref_managekeys_import_secret_keys" : "pref_managekeys_export_secret_keys")
progressHandler.showProgressAlert(title: alertTitle, 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")
}

self.progressAlertHandler = progressHandler
}

// MARK: - updates
Expand All @@ -450,3 +440,9 @@ internal final class AdvancedViewController: UITableViewController, LegacyProgre
navigationController?.pushViewController(videoInstanceController, animated: true)
}
}

extension AdvancedViewController: ProgressAlertHandlerDataSource {
func viewController() -> UIViewController {
self
}
}

0 comments on commit a8d7259

Please sign in to comment.