Ver Fonte

cleaning - hudhandler back in initial state - stil used in SettingsController

Bastian van de Wetering há 6 anos atrás
pai
commit
9d813d5073

+ 8 - 25
deltachat-ios/Controller/AccountSetupController.swift

@@ -21,9 +21,8 @@ class AccountSetupController: UITableViewController {
 	lazy var configurationProgress: UICircularProgressRing = {
 		let progress = UICircularProgressRing()
 		progress.style = UICircularRingStyle.inside
-		//progress.backgroundColor = UIColor.white.withAlphaComponent(0)
+		progress.outerRingColor = UIColor.clear
 		progress.maxValue = 100
-		progress.outerRingColor = UIColor.init(white: 1, alpha: 0)
 		progress.innerRingColor = DCColors.primary
 		progress.innerRingWidth = 2
 		progress.startAngle = 270
@@ -32,7 +31,6 @@ class AccountSetupController: UITableViewController {
 		return progress
 	}()
 
-
 	lazy var loginProgressHud: UIAlertController = {
 		let alert = UIAlertController(title: "Configuring Account", message: "\n\n\n", preferredStyle: .alert)
 		// temp workaround: add 3 newlines to let alertbox grow to fit progress indicator
@@ -41,20 +39,12 @@ class AccountSetupController: UITableViewController {
 		alert.view.addSubview(progressView)
 		progressView.centerXAnchor.constraint(equalTo: alert.view.centerXAnchor).isActive = true
 		progressView.centerYAnchor.constraint(equalTo: alert.view.centerYAnchor, constant: 0).isActive = true
-		progressView.heightAnchor.constraint(equalToConstant: 70).isActive = true
-		progressView.widthAnchor.constraint(equalToConstant: 70).isActive = true
-		alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
+		progressView.heightAnchor.constraint(equalToConstant: 65).isActive = true
+		progressView.widthAnchor.constraint(equalToConstant: 65).isActive = true
+		alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: loginCancelled(_:)))
 		return alert
 	}()
 
-/*
-	private lazy var hudHandler: HudHandler = {
-		let hudHandler = HudHandler(parentView: self)
-		return hudHandler
-	}()
-*/
-
-
 	private lazy var emailCell: TextFieldCell = {
 		let cell = TextFieldCell.makeEmailCell(delegate: self)
 		cell.textField.tag = 0
@@ -435,10 +425,8 @@ class AccountSetupController: UITableViewController {
 					// self.hudHandler.setHudError(ui["errorMessage"] as? String)
 				} else if ui["done"] as! Bool {
 					self.updateProgressHudSuccess(callback: self.handleLoginSuccess)
-					// self.hudHandler.setHudDone(callback: self.handleLoginSuccess)
 				} else {
 					self.updateProgressHudValue(value: ui["progress"] as! Int)
-					// self.hudHandler.setHudProgress(ui["progress"] as! Int)
 				}
 			}
 		}
@@ -597,15 +585,6 @@ class AdvancedSectionHeader: UIView {
 		return label
 	}()
 
-	//
-	//	private var toggleButton:UIButton = {
-	//		let button = UIButton(type: .system)
-	//		button.setTitle("Show", for: .normal)
-	//		button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside )
-	//		//button.target(forAction: #selector(buttonTapped(_:)), withSender: self)
-	//		return button
-	//	}()
-
 	init() {
 		super.init(frame: .zero) // will be constraint from tableViewDelegate
 		setupSubviews()
@@ -666,6 +645,10 @@ extension AccountSetupController {
 		}
 	}
 
+	func loginCancelled(_ action: UIAlertAction) {
+		print("Login cancelled")
+	}
+
 
 
 

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

@@ -20,7 +20,7 @@ internal final class SettingsViewController: QuickTableViewController {
 	var configureProgressObserver: Any?
 
 	private lazy var hudHandler: HudHandler = {
-		let hudHandler = HudHandler(parentView: self)
+		let hudHandler = HudHandler(parentView: self.tableView)
 		return hudHandler
 	}()
 
@@ -30,7 +30,6 @@ internal final class SettingsViewController: QuickTableViewController {
 		documentInteractionController.delegate = self as? UIDocumentInteractionControllerDelegate
 	}
 
-
 	override func viewDidAppear(_ animated: Bool) {
 
 		super.viewDidAppear(animated)

+ 54 - 71
deltachat-ios/Handler/HudHandler.swift

@@ -10,82 +10,65 @@ import JGProgressHUD
 import UIKit
 
 class HudHandler {
+	var backupHud: JGProgressHUD?
+	unowned var view: UIView
 
-	private lazy var alertView: UIAlertController = {
-		let alertView = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
-		alertView.addAction(UIAlertAction(title: nil, style: .cancel, handler: nil))
-		return alertView
-	}()
+	init(parentView: UIView) {
+		view = parentView
+	}
 
-  // var backupHud: JGProgressHUD?
-	var viewController: UIViewController
+	func setHudProgress(_ progress: Int) {
+		if let hud = self.backupHud {
+			hud.progress = Float(progress) / 1000.0
+			hud.detailTextLabel.text = "\(progress / 10)% Complete"
+		}
+	}
 
-  init(parentView: UIViewController) {
-    viewController = parentView
-  }
+	func showBackupHud(_ text: String) {
+		DispatchQueue.main.async {
+			let hud = JGProgressHUD(style: .dark)
+			hud.vibrancyEnabled = true
+			hud.indicatorView = JGProgressHUDPieIndicatorView()
+			hud.detailTextLabel.text = "0% Complete"
+			hud.textLabel.text = text
+			hud.show(in: self.view)
+			self.backupHud = hud
+		}
+	}
 
-  func setHudProgress(_ progress: Int) {
-    //if let hud = self.alertView {
-      //hud.progress = Float(progress) / 1000.0
-      //hud.detailTextLabel.text = "\(progress / 10)% Complete"
+	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 ?? "Error"
+						hud.detailTextLabel.text = nil
+						hud.indicatorView = JGProgressHUDErrorIndicatorView()
+				}
+				)
+				hud.dismiss(afterDelay: 5.0)
+			}
+		}
+	}
 
-  }
+	func setHudDone(callback: (() -> Void)?) {
+		let delay = 1.0
 
-  func showBackupHud(_ text: String) {
-			viewController.present(alertView, animated: false, completion: nil)
-		
+		if let hud = self.backupHud {
+			DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
+				UIView.animate(
+					withDuration: 0.1, animations: {
+						hud.textLabel.text = "Success"
+						hud.detailTextLabel.text = nil
+						hud.indicatorView = JGProgressHUDSuccessIndicatorView()
+				}
+				)
+			}
 
-
-		/*
-    DispatchQueue.main.async {
-      let hud = JGProgressHUD(style: .dark)
-      hud.vibrancyEnabled = true
-      hud.indicatorView = JGProgressHUDPieIndicatorView()
-      hud.detailTextLabel.text = "0% Complete"
-      hud.textLabel.text = text
-      hud.show(in: self.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 ?? "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 {
-      DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
-        UIView.animate(
-          withDuration: 0.1, animations: {
-            hud.textLabel.text = "Success"
-            hud.detailTextLabel.text = nil
-            hud.indicatorView = JGProgressHUDSuccessIndicatorView()
-          }
-        )
-      }
-
-      DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
-        callback?()
-        hud.dismiss()
-      }
-    }
-		*/
-  }
+			DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
+				callback?()
+				hud.dismiss()
+			}
+		}
+	}
 }