Browse Source

addProgressAlertListener now takse Notification.Name as argument

nayooti 5 years ago
parent
commit
a6f21e3e8a

+ 0 - 4
deltachat-ios.xcodeproj/project.pbxproj

@@ -160,7 +160,6 @@
 		AEC67A1E241FCFE0007DDBE1 /* ChatListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */; };
 		AECEF03E244F2D55006C90DA /* QrPageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECEF03D244F2D55006C90DA /* QrPageController.swift */; };
 		AEE56D762253431E007DC082 /* AccountSetupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D752253431E007DC082 /* AccountSetupController.swift */; };
-		AEE56D7D2253ADB4007DC082 /* HudHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7C2253ADB4007DC082 /* HudHandler.swift */; };
 		AEE56D80225504DB007DC082 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7F225504DB007DC082 /* Extensions.swift */; };
 		AEE6EC3F2282C59C00EDC689 /* GroupMembersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */; };
 		AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */; };
@@ -446,7 +445,6 @@
 		AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListViewModel.swift; sourceTree = "<group>"; };
 		AECEF03D244F2D55006C90DA /* QrPageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QrPageController.swift; sourceTree = "<group>"; };
 		AEE56D752253431E007DC082 /* AccountSetupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSetupController.swift; sourceTree = "<group>"; tabWidth = 4; };
-		AEE56D7C2253ADB4007DC082 /* HudHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HudHandler.swift; sourceTree = "<group>"; };
 		AEE56D7F225504DB007DC082 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
 		AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupMembersViewController.swift; sourceTree = "<group>"; };
 		AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailboxViewController.swift; sourceTree = "<group>"; };
@@ -949,7 +947,6 @@
 			isa = PBXGroup;
 			children = (
 				AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */,
-				AEE56D7C2253ADB4007DC082 /* HudHandler.swift */,
 				AE8519E92272FDCA00ED86F0 /* DeviceContactsHandler.swift */,
 				AEE700242438E0E500D6992E /* ProgressAlertHandler.swift */,
 			);
@@ -1370,7 +1367,6 @@
 				7A9FB1441FB061E2001FEA36 /* AppDelegate.swift in Sources */,
 				AE76E5EE242BF2EA003CF461 /* WelcomeViewController.swift in Sources */,
 				305961F52346125100C80F33 /* TypingIndicatorCell.swift in Sources */,
-				AEE56D7D2253ADB4007DC082 /* HudHandler.swift in Sources */,
 				305961FF2346125100C80F33 /* AvatarView.swift in Sources */,
 				3059620C2346125100C80F33 /* MessageSizeCalculator.swift in Sources */,
 				305962042346125100C80F33 /* MessagesCollectionViewLayoutAttributes.swift in Sources */,

+ 1 - 0
deltachat-ios/Controller/AccountSetupController.swift

@@ -649,6 +649,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     }
 
     private func addProgressHudLoginListener() {
+
         let nc = NotificationCenter.default
         progressObserver = nc.addObserver(
             forName: dcNotificationConfigureProgress,

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

@@ -33,15 +33,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
     let documentInteractionController = UIDocumentInteractionController()
     weak var progressAlert: UIAlertController?
     var progressObserver: Any?
-/*
-    var backupProgressObserver: Any?
-    var configureProgressObserver: Any?
 
-    private lazy var hudHandler: HudHandler = {
-        let hudHandler = HudHandler(parentView: self.view)
-        return hudHandler
-    }()
-*/
     // MARK: - cells
 
     private let profileHeader = ContactDetailHeader()
@@ -237,45 +229,10 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
     override func viewDidAppear(_ animated: Bool) {
 
         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,
-            queue: nil
-        ) { [weak self] notification in
-            guard let self = self else { return }
-            if let ui = notification.userInfo {
-                if ui["error"] as? Bool ?? false {
-                    self.hudHandler.setHudError(ui["errorMessage"] as? String)
-                } else if ui["done"] as? Bool ?? false {
-                    self.hudHandler.setHudDone(callback: nil)
-                } else {
-                    self.hudHandler.setHudProgress(ui["progress"] as? Int ?? 0)
-                }
-            }
-        }
-        configureProgressObserver = nc.addObserver(
-            forName: dcNotificationConfigureProgress,
-            object: nil,
-            queue: nil
-        ) { [weak self] notification in
-            guard let self = self else { return }
-            if let ui = notification.userInfo {
-                if ui["error"] as? Bool ?? false {
-                    self.hudHandler.setHudError(ui["errorMessage"] as? String)
-                } else if ui["done"] as? Bool ?? false {
-                    self.hudHandler.setHudDone(callback: nil)
-                } else {
-                    self.hudHandler.setHudProgress(ui["progress"] as? Int ?? 0)
-                }
-            }
-        }
-        */
     }
 
     override func viewDidDisappear(_ animated: Bool) {
@@ -429,8 +386,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
     private func startImex(what: Int32) {
         let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
         if !documents.isEmpty {
-            showProgressAlert(title: "", dcContext: dcContext)
-            // self.hudHandler.showHud(String.localized("one_moment"))
+            showProgressAlert(title: String.localized("imex_progress_title_desktop"), dcContext: dcContext)
             DispatchQueue.main.async {
                 self.dcContext.imex(what: what, directory: documents[0])
             }

+ 1 - 1
deltachat-ios/Controller/WelcomeViewController.swift

@@ -112,7 +112,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     private func createAccountFromQRCode(qrCode: String) {
         let success = dcContext.setConfigFromQR(qrCode: qrCode)
         if success {
-            addProgressAlertListener(onSuccess: handleLoginSuccess)
+            addProgressAlertListener(progressName: dcNotificationConfigureProgress, onSuccess: handleLoginSuccess)
             showProgressAlert(title: String.localized("login_header"), dcContext: dcContext)
             dcContext.configure()
         } else {

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

@@ -1,72 +0,0 @@
-import JGProgressHUD
-import UIKit
-
-/*
-class HudHandler {
-    var backupHud: JGProgressHUD?
-    weak var view: UIView?
-
-    init(parentView: UIView) {
-        view = parentView
-    }
-
-    func setHudProgress(_ progress: Int) {
-        if let hud = self.backupHud {
-            hud.progress = Float(progress) / 1000.0
-            hud.detailTextLabel.text = "\(progress / 10)%"
-        }
-    }
-
-    func showHud(_ text: String) {
-        DispatchQueue.main.async {
-            let hud = JGProgressHUD(style: .dark)
-            hud.vibrancyEnabled = true
-            hud.indicatorView = JGProgressHUDPieIndicatorView()
-            hud.detailTextLabel.text = "0%"
-            hud.textLabel.text = text
-            if let view = self.view {
-                hud.show(in: view)
-            }
-            self.backupHud = hud
-        }
-    }
-
-    func setHudError(_ message: String?) {
-        if let hud = self.backupHud {
-            DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
-                UIView.animate(
-                    withDuration: 0.1, animations: {
-                        hud.textLabel.text = message ?? String.localized("error")
-                        hud.detailTextLabel.text = nil
-                        hud.indicatorView = JGProgressHUDErrorIndicatorView()
-                    }
-                )
-                hud.dismiss(afterDelay: 5.0)
-            }
-        }
-    }
-
-    func setHudDone(callback: (() -> Void)?) {
-        let delay = 1.0
-
-        if let hud = self.backupHud {
-            hud.setProgress(1.0, animated: true)
-            hud.detailTextLabel.text = "100%"
-            DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
-                UIView.animate(
-                    withDuration: 0.1, animations: {
-                        hud.textLabel.text = String.localized("done")
-                        hud.detailTextLabel.text = nil
-                        hud.indicatorView = JGProgressHUDSuccessIndicatorView()
-                    }
-                )
-            }
-
-            DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
-                callback?()
-                hud.dismiss()
-            }
-        }
-    }
-}
-*/

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

@@ -58,7 +58,7 @@ extension ProgressAlertHandler {
         })
     }
 
-    func addProgressAlertListener(progressName: Notification.Name = dcNotificationConfigureProgress, onSuccess: @escaping VoidFunction) {
+    func addProgressAlertListener(progressName: Notification.Name, onSuccess: @escaping VoidFunction) {
         let nc = NotificationCenter.default
         progressObserver = nc.addObserver(
             forName: progressName, //dcNotificationConfigureProgress,