Selaa lähdekoodia

moved progressAlertHandler into seperate file

nayooti 5 vuotta sitten
vanhempi
commit
eac2ac7102

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

@@ -157,6 +157,7 @@
 		AEE6EC3F2282C59C00EDC689 /* GroupMembersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */; };
 		AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */; };
 		AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC472283045D00EDC689 /* EditSettingsController.swift */; };
+		AEE700252438E0E500D6992E /* ProgressAlertHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE700242438E0E500D6992E /* ProgressAlertHandler.swift */; };
 		AEFBE22F23FEF23D0045327A /* ProviderInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */; };
 		AEFBE23123FF09B20045327A /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEFBE23023FF09B20045327A /* TypeAlias.swift */; };
 		B20462E42440A4A600367A57 /* SettingsAutodelOverviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20462E32440A4A600367A57 /* SettingsAutodelOverviewController.swift */; };
@@ -395,6 +396,7 @@
 		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>"; };
 		AEE6EC472283045D00EDC689 /* EditSettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditSettingsController.swift; sourceTree = "<group>"; };
+		AEE700242438E0E500D6992E /* ProgressAlertHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressAlertHandler.swift; sourceTree = "<group>"; };
 		AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderInfoCell.swift; sourceTree = "<group>"; };
 		AEFBE23023FF09B20045327A /* TypeAlias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = "<group>"; };
 		B20462E02440805C00367A57 /* id */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = id; path = id.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@@ -851,6 +853,7 @@
 				AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */,
 				AEE56D7C2253ADB4007DC082 /* HudHandler.swift */,
 				AE8519E92272FDCA00ED86F0 /* DeviceContactsHandler.swift */,
+				AEE700242438E0E500D6992E /* ProgressAlertHandler.swift */,
 			);
 			path = Handler;
 			sourceTree = "<group>";
@@ -1196,6 +1199,7 @@
 				305961E62346125100C80F33 /* LocationMessageSnapshotOptions.swift in Sources */,
 				AEE6EC3F2282C59C00EDC689 /* GroupMembersViewController.swift in Sources */,
 				B26B3BC7236DC3DC008ED35A /* SwitchCell.swift in Sources */,
+				AEE700252438E0E500D6992E /* ProgressAlertHandler.swift in Sources */,
 				78E45E3A21D3CFBC00D4B15E /* SettingsController.swift in Sources */,
 				AE8519EA2272FDCA00ED86F0 /* DeviceContactsHandler.swift in Sources */,
 				3059620B2346125100C80F33 /* LocationMessageSizeCalculator.swift in Sources */,

+ 0 - 64
deltachat-ios/Controller/WelcomeViewController.swift

@@ -452,67 +452,3 @@ class WelcomeContentView: UIView {
         buttonStack.isHidden = show
     }
 }
-
-protocol ProgressAlertHandler: UIViewController {
-    var progressAlert: UIAlertController { get }
-    var configureProgressObserver: Any? { get set }
-    var onProgressSuccess: VoidFunction? { get set }
-    func showProgressAlert(title: String)
-    func updateProgressAlertValue(value: Int?)
-    func updateProgressAlert(error: String?)
-    func updateProgressAlertSuccess(completion: VoidFunction?)
-    func addProgressAlertListener(onSuccess: @escaping VoidFunction)
-}
-
-extension ProgressAlertHandler {
-
-    func showProgressAlert(title: String) {
-        progressAlert.actions[0].isEnabled = true
-        progressAlert.title = title
-        progressAlert.message = String.localized("one_moment")
-        present(progressAlert, animated: true, completion: nil)
-    }
-
-    func updateProgressAlertValue(value: Int?) {
-        if let value = value {
-            progressAlert.message = String.localized("one_moment") + " " + String(value/10) + "%"
-        }
-    }
-
-    func updateProgressAlert(error message: String?) {
-        DispatchQueue.main.async(execute: {
-            self.progressAlert.dismiss(animated: false)
-            let errorAlert = UIAlertController(title: String.localized("error"), message: message, preferredStyle: .alert)
-            errorAlert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
-            self.present(errorAlert, animated: true, completion: nil)
-        })
-    }
-
-    func updateProgressAlertSuccess(completion onComplete: VoidFunction?) {
-        updateProgressAlertValue(value: 1000)
-        DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
-            self.progressAlert.dismiss(animated: true) {
-                onComplete?()
-            }
-        })
-    }
-
-    func addProgressAlertListener(onSuccess: @escaping VoidFunction) {
-        let nc = NotificationCenter.default
-        configureProgressObserver = nc.addObserver(
-            forName: dcNotificationConfigureProgress,
-            object: nil,
-            queue: nil
-        ) { notification in
-            if let ui = notification.userInfo {
-                if ui["error"] as! Bool {
-                    self.updateProgressAlert(error: ui["errorMessage"] as? String)
-                } else if ui["done"] as! Bool {
-                    self.updateProgressAlertSuccess(completion: onSuccess)
-                } else {
-                    self.updateProgressAlertValue(value: ui["progress"] as? Int)
-                }
-            }
-        }
-    }
-}

+ 0 - 1
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -854,7 +854,6 @@ class EditContactCoordinator: Coordinator, EditContactCoordinatorProtocol {
     }
 }
 
-
 /*
  boilerplate - I tend to remove that interface (cyberta)
  */

+ 66 - 0
deltachat-ios/Handler/ProgressAlertHandler.swift

@@ -0,0 +1,66 @@
+import UIKit
+
+protocol ProgressAlertHandler: UIViewController {
+    var progressAlert: UIAlertController { get }
+    var configureProgressObserver: Any? { get set }
+    var onProgressSuccess: VoidFunction? { get set }
+    func showProgressAlert(title: String)
+    func updateProgressAlertValue(value: Int?)
+    func updateProgressAlert(error: String?)
+    func updateProgressAlertSuccess(completion: VoidFunction?)
+    func addProgressAlertListener(onSuccess: @escaping VoidFunction)
+}
+
+extension ProgressAlertHandler {
+
+    func showProgressAlert(title: String) {
+        progressAlert.actions[0].isEnabled = true
+        progressAlert.title = title
+        progressAlert.message = String.localized("one_moment")
+        present(progressAlert, animated: true, completion: nil)
+    }
+
+    func updateProgressAlertValue(value: Int?) {
+        if let value = value {
+            progressAlert.message = String.localized("one_moment") + " " + String(value/10) + "%"
+        }
+    }
+
+    func updateProgressAlert(error message: String?) {
+        DispatchQueue.main.async(execute: {
+            self.progressAlert.dismiss(animated: false)
+            let errorAlert = UIAlertController(title: String.localized("error"), message: message, preferredStyle: .alert)
+            errorAlert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            self.present(errorAlert, animated: true, completion: nil)
+        })
+    }
+
+    func updateProgressAlertSuccess(completion onComplete: VoidFunction?) {
+        updateProgressAlertValue(value: 1000)
+        DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
+            self.progressAlert.dismiss(animated: true) {
+                onComplete?()
+            }
+        })
+    }
+
+    func addProgressAlertListener(onSuccess: @escaping VoidFunction) {
+        let nc = NotificationCenter.default
+        configureProgressObserver = nc.addObserver(
+            forName: dcNotificationConfigureProgress,
+            object: nil,
+            queue: nil
+        ) { notification in
+            if let ui = notification.userInfo {
+                if ui["error"] as! Bool {
+                    self.updateProgressAlert(error: ui["errorMessage"] as? String)
+                } else if ui["done"] as! Bool {
+                    self.updateProgressAlertSuccess(completion: onSuccess)
+                } else {
+                    self.updateProgressAlertValue(value: ui["progress"] as? Int)
+                }
+            }
+        }
+    }
+}
+