Browse Source

Account Setup Progress bar now actually shows progress

Bastian van de Wetering 6 years ago
parent
commit
1c509d6ffb
1 changed files with 54 additions and 0 deletions
  1. 54 0
      deltachat-ios/AccountSetupController.swift

+ 54 - 0
deltachat-ios/AccountSetupController.swift

@@ -12,6 +12,9 @@ import JGProgressHUD
 
 
 class AccountSetupController: UITableViewController {
 class AccountSetupController: UITableViewController {
     
     
+    var backupProgressObserver: Any?
+    var configureProgressObserver: Any?
+    
     lazy var hudHandler: HudHandler = {
     lazy var hudHandler: HudHandler = {
         let hudHandler = HudHandler(parentView: self.tableView)
         let hudHandler = HudHandler(parentView: self.tableView)
         return hudHandler
         return hudHandler
@@ -45,6 +48,21 @@ class AccountSetupController: UITableViewController {
     self.title = "Login to your server"
     self.title = "Login to your server"
     self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Login", style: .done, target: self, action: #selector(loginButtonPressed))
     self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Login", style: .done, target: self, action: #selector(loginButtonPressed))
   }
   }
+    
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
+        addProgressHudEventListener()
+    }
+    
+    override func viewDidDisappear(_ animated: Bool) {
+        let nc = NotificationCenter.default
+        if let backupProgressObserver = self.backupProgressObserver {
+            nc.removeObserver(backupProgressObserver)
+        }
+        if let configureProgressObserver = self.configureProgressObserver {
+            nc.removeObserver(configureProgressObserver)
+        }
+    }
 
 
     // MARK: - Table view data source
     // MARK: - Table view data source
 
 
@@ -113,6 +131,42 @@ class AccountSetupController: UITableViewController {
         dc_configure(mailboxPointer)
         dc_configure(mailboxPointer)
         hudHandler.showBackupHud("Configuring account")
         hudHandler.showBackupHud("Configuring account")
     }
     }
+    
+    private func addProgressHudEventListener() {
+        let nc = NotificationCenter.default
+        backupProgressObserver = nc.addObserver(
+            forName: dcNotificationBackupProgress,
+            object: nil,
+            queue: nil
+        ) {
+            notification in
+            if let ui = notification.userInfo {
+                if ui["error"] as! Bool {
+                    self.hudHandler.setHudError(ui["errorMessage"] as? String)
+                } else if ui["done"] as! Bool {
+                    self.hudHandler.setHudDone(callback: nil)
+                } else {
+                    self.hudHandler.setHudProgress(ui["progress"] as! Int)
+                }
+            }
+        }
+        configureProgressObserver = nc.addObserver(
+            forName: dcNotificationConfigureProgress,
+            object: nil,
+            queue: nil
+        ) {
+            notification in
+            if let ui = notification.userInfo {
+                if ui["error"] as! Bool {
+                    self.hudHandler.setHudError(ui["errorMessage"] as? String)
+                } else if ui["done"] as! Bool {
+                    self.hudHandler.setHudDone(callback: nil)
+                } else {
+                    self.hudHandler.setHudProgress(ui["progress"] as! Int)
+                }
+            }
+        }
+    }
 }
 }