Эх сурвалжийг харах

settingscontroller now reuses progressalerthandler

nayooti 5 жил өмнө
parent
commit
75b5481293

+ 14 - 7
deltachat-ios/Controller/SettingsController.swift

@@ -3,7 +3,7 @@ import UIKit
 import DcCore
 import DBDebugToolkit
 
-internal final class SettingsViewController: UITableViewController {
+internal final class SettingsViewController: UITableViewController, ProgressAlertHandler {
 
     private struct SectionConfigs {
         let headerTitle: String?
@@ -31,6 +31,9 @@ internal final class SettingsViewController: UITableViewController {
     private let externalPathDescr = "File Sharing/Delta Chat"
 
     let documentInteractionController = UIDocumentInteractionController()
+    weak var progressAlert: UIAlertController?
+    var progressObserver: Any?
+/*
     var backupProgressObserver: Any?
     var configureProgressObserver: Any?
 
@@ -38,7 +41,7 @@ internal final class SettingsViewController: UITableViewController {
         let hudHandler = HudHandler(parentView: self.view)
         return hudHandler
     }()
-
+*/
     // MARK: - cells
 
     private let profileHeader = ContactDetailHeader()
@@ -235,6 +238,11 @@ internal final class SettingsViewController: UITableViewController {
 
         super.viewDidAppear(animated)
         let nc = NotificationCenter.default
+        addProgressAlertListener(progressName: dcNotificationImexProgress) { [weak self] in
+            guard let self = self else { return }
+            self.progressAlert?.dismiss(animated: true, completion: nil)
+        }
+        /*
         backupProgressObserver = nc.addObserver(
             forName: dcNotificationImexProgress,
             object: nil,
@@ -267,18 +275,16 @@ internal final class SettingsViewController: UITableViewController {
                 }
             }
         }
+        */
     }
 
     override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
 
         let nc = NotificationCenter.default
-        if let backupProgressObserver = self.backupProgressObserver {
+        if let backupProgressObserver = self.progressObserver {
             nc.removeObserver(backupProgressObserver)
         }
-        if let configureProgressObserver = self.configureProgressObserver {
-            nc.removeObserver(configureProgressObserver)
-        }
     }
 
     // MARK: - UITableViewDelegate + UITableViewDatasource
@@ -423,7 +429,8 @@ internal final class SettingsViewController: UITableViewController {
     private func startImex(what: Int32) {
         let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
         if !documents.isEmpty {
-            self.hudHandler.showHud(String.localized("one_moment"))
+            showProgressAlert(title: "", dcContext: dcContext)
+            // self.hudHandler.showHud(String.localized("one_moment"))
             DispatchQueue.main.async {
                 self.dcContext.imex(what: what, directory: documents[0])
             }

+ 2 - 0
deltachat-ios/Handler/HudHandler.swift

@@ -1,6 +1,7 @@
 import JGProgressHUD
 import UIKit
 
+/*
 class HudHandler {
     var backupHud: JGProgressHUD?
     weak var view: UIView?
@@ -68,3 +69,4 @@ class HudHandler {
         }
     }
 }
+*/

+ 3 - 3
deltachat-ios/Handler/ProgressAlertHandler.swift

@@ -8,7 +8,7 @@ protocol ProgressAlertHandler: UIViewController {
     func updateProgressAlertValue(value: Int?)
     func updateProgressAlert(error: String?)
     func updateProgressAlertSuccess(completion: VoidFunction?)
-    func addProgressAlertListener(onSuccess: @escaping VoidFunction)
+    func addProgressAlertListener(progressName: Notification.Name, onSuccess: @escaping VoidFunction)
 }
 
 extension ProgressAlertHandler {
@@ -58,10 +58,10 @@ extension ProgressAlertHandler {
         })
     }
 
-    func addProgressAlertListener(onSuccess: @escaping VoidFunction) {
+    func addProgressAlertListener(progressName: Notification.Name = dcNotificationConfigureProgress, onSuccess: @escaping VoidFunction) {
         let nc = NotificationCenter.default
         progressObserver = nc.addObserver(
-            forName: dcNotificationConfigureProgress,
+            forName: progressName, //dcNotificationConfigureProgress,
             object: nil,
             queue: nil
         ) { [weak self] notification in