|
@@ -2,34 +2,46 @@ import UIKit
|
|
|
import DcCore
|
|
|
|
|
|
protocol ProgressAlertHandler: UIViewController {
|
|
|
- var progressAlert: UIAlertController { get }
|
|
|
+ var progressAlert: UIAlertController? { get set }
|
|
|
var configureProgressObserver: Any? { get set }
|
|
|
- func showProgressAlert(title: String)
|
|
|
+ func showProgressAlert(title: String, dcContext: DcContext)
|
|
|
func updateProgressAlertValue(value: Int?)
|
|
|
func updateProgressAlert(error: String?)
|
|
|
func updateProgressAlertSuccess(completion: VoidFunction?)
|
|
|
func addProgressAlertListener(onSuccess: @escaping VoidFunction)
|
|
|
- func progressAlertWillDismiss()
|
|
|
}
|
|
|
|
|
|
extension ProgressAlertHandler {
|
|
|
|
|
|
- func showProgressAlert(title: String) {
|
|
|
+ func showProgressAlert(title: String, dcContext: DcContext) {
|
|
|
+ self.progressAlert = makeProgressAlert(dcContext: dcContext)
|
|
|
+ guard let progressAlert = progressAlert else { return }
|
|
|
progressAlert.actions[0].isEnabled = true
|
|
|
progressAlert.title = title
|
|
|
progressAlert.message = String.localized("one_moment")
|
|
|
present(progressAlert, animated: true, completion: nil)
|
|
|
}
|
|
|
|
|
|
+ private func makeProgressAlert(dcContext: DcContext) -> UIAlertController {
|
|
|
+ let alert = UIAlertController(title: "", message: "", preferredStyle: .alert)
|
|
|
+ alert.addAction(UIAlertAction(
|
|
|
+ title: String.localized("cancel"),
|
|
|
+ style: .cancel,
|
|
|
+ handler: { _ in
|
|
|
+ dcContext.stopOngoingProcess()
|
|
|
+ }))
|
|
|
+ return alert
|
|
|
+ }
|
|
|
+
|
|
|
func updateProgressAlertValue(value: Int?) {
|
|
|
if let value = value {
|
|
|
- progressAlert.message = String.localized("one_moment") + " " + String(value/10) + "%"
|
|
|
+ progressAlert?.message = String.localized("one_moment") + " " + String(value/10) + "%"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func updateProgressAlert(error message: String?) {
|
|
|
DispatchQueue.main.async(execute: {
|
|
|
- self.progressAlert.dismiss(animated: false)
|
|
|
+ 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)
|
|
@@ -38,10 +50,9 @@ extension ProgressAlertHandler {
|
|
|
|
|
|
func updateProgressAlertSuccess(completion onComplete: VoidFunction?) {
|
|
|
updateProgressAlertValue(value: 1000)
|
|
|
- progressAlertWillDismiss()
|
|
|
// delay so the user has time to read the success message
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
|
|
|
- self.progressAlert.dismiss(animated: true) {
|
|
|
+ self.progressAlert?.dismiss(animated: true) {
|
|
|
onComplete?()
|
|
|
}
|
|
|
})
|
|
@@ -65,9 +76,5 @@ extension ProgressAlertHandler {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- func progressAlertWillDismiss() {
|
|
|
- // can be overwritten if needed
|
|
|
- }
|
|
|
}
|
|
|
|