|
@@ -7,12 +7,14 @@ class AccountSetupController: UITableViewController {
|
|
|
weak var coordinator: AccountSetupCoordinator?
|
|
|
|
|
|
private var skipOauth = false
|
|
|
-
|
|
|
private var backupProgressObserver: Any?
|
|
|
private var configureProgressObserver: Any?
|
|
|
private var oauth2Observer: Any?
|
|
|
|
|
|
- lazy var configProgressIndicator: UICircularProgressRing = {
|
|
|
+
|
|
|
+ // the progress dialog
|
|
|
+
|
|
|
+ private lazy var configProgressIndicator: UICircularProgressRing = {
|
|
|
let progress = UICircularProgressRing()
|
|
|
progress.style = UICircularRingStyle.inside
|
|
|
progress.outerRingColor = UIColor.clear
|
|
@@ -25,9 +27,9 @@ class AccountSetupController: UITableViewController {
|
|
|
return progress
|
|
|
}()
|
|
|
|
|
|
- lazy var configProgressAlert: UIAlertController = {
|
|
|
- let alert = UIAlertController(title: String.localized("configuring_account"), message: "\n\n\n", preferredStyle: .alert)
|
|
|
- // temp workaround: add 3 newlines to let alertbox grow to fit progressview
|
|
|
+ private lazy var configProgressAlert: UIAlertController = {
|
|
|
+ let alert = UIAlertController(title: String.localized("one_moment"), message: "\n\n\n", preferredStyle: .alert)
|
|
|
+ // workaround: add 3 newlines to let alertbox grow to fit progressview
|
|
|
let progressView = configProgressIndicator
|
|
|
progressView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
alert.view.addSubview(progressView)
|
|
@@ -39,6 +41,48 @@ class AccountSetupController: UITableViewController {
|
|
|
return alert
|
|
|
}()
|
|
|
|
|
|
+ private func showProgressHud() {
|
|
|
+ configProgressAlert.actions[0].isEnabled = true
|
|
|
+ configProgressAlert.title = String.localized("one_moment")
|
|
|
+ configProgressAlert.message = "\n\n\n" // workaround to create space for progress indicator
|
|
|
+ configProgressIndicator.alpha = 1
|
|
|
+ configProgressIndicator.value = 0
|
|
|
+ present(configProgressAlert, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func updateProgressHud(error message: String?) {
|
|
|
+ configProgressAlert.title = String.localized("login_error_title")
|
|
|
+ configProgressAlert.message = message
|
|
|
+ configProgressIndicator.alpha = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ private func updateProgressHudSuccess() {
|
|
|
+ updateProgressHudValue(value: 1000)
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
|
|
|
+ self.configProgressAlert.dismiss(animated: true) {
|
|
|
+ self.handleLoginSuccess()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ private func updateProgressHudValue(value: Int?) {
|
|
|
+ if let value = value {
|
|
|
+ print("progress hud: \(value)")
|
|
|
+ configProgressIndicator.value = CGFloat(value / 10)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func loginCancelled(_ action: UIAlertAction) {
|
|
|
+ DcConfig.addr = nil
|
|
|
+ DcConfig.mailPw = nil
|
|
|
+ DispatchQueue.global(qos: .background).async {
|
|
|
+ dc_stop_ongoing_process(mailboxPointer) // this function freezes UI so execute in background thread
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // account setup
|
|
|
+
|
|
|
private lazy var emailCell: TextFieldCell = {
|
|
|
let cell = TextFieldCell.makeEmailCell(delegate: self)
|
|
|
cell.textField.tag = 0
|
|
@@ -204,7 +248,6 @@ class AccountSetupController: UITableViewController {
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
super.viewDidAppear(animated)
|
|
|
addProgressHudEventListener()
|
|
|
- // loginButton.isEnabled = false
|
|
|
}
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
@@ -295,7 +338,6 @@ class AccountSetupController: UITableViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // FIXME: replace if-else-if with switch-case
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
guard let tappedCell = tableView.cellForRow(at: indexPath) else { return }
|
|
|
// handle tap on password -> show oAuthDialogue
|
|
@@ -441,7 +483,7 @@ class AccountSetupController: UITableViewController {
|
|
|
private func addProgressHudEventListener() {
|
|
|
let nc = NotificationCenter.default
|
|
|
backupProgressObserver = nc.addObserver(
|
|
|
- forName: dcNotificationBackupProgress,
|
|
|
+ forName: dcNotificationImexProgress,
|
|
|
object: nil,
|
|
|
queue: nil
|
|
|
) {
|
|
@@ -450,7 +492,7 @@ class AccountSetupController: UITableViewController {
|
|
|
if ui["error"] as! Bool {
|
|
|
self.updateProgressHud(error: ui["errorMessage"] as? String)
|
|
|
} else if ui["done"] as! Bool {
|
|
|
- self.updateProgressHudSuccess(callback: self.handleLoginSuccess)
|
|
|
+ self.updateProgressHudSuccess()
|
|
|
} else {
|
|
|
self.updateProgressHudValue(value: ui["progress"] as? Int)
|
|
|
}
|
|
@@ -466,7 +508,7 @@ class AccountSetupController: UITableViewController {
|
|
|
if ui["error"] as! Bool {
|
|
|
self.updateProgressHud(error: ui["errorMessage"] as? String)
|
|
|
} else if ui["done"] as! Bool {
|
|
|
- self.updateProgressHudSuccess(callback: self.handleLoginSuccess)
|
|
|
+ self.updateProgressHudSuccess()
|
|
|
} else {
|
|
|
self.updateProgressHudValue(value: ui["progress"] as? Int)
|
|
|
}
|
|
@@ -516,19 +558,17 @@ class AccountSetupController: UITableViewController {
|
|
|
|
|
|
if let file = dc_imex_has_backup(mailboxPointer, documents[0]) {
|
|
|
logger.info("restoring backup: \(String(cString: file))")
|
|
|
-
|
|
|
- // hudHandler.showBackupHud("Restoring Backup")
|
|
|
+ showProgressHud()
|
|
|
dc_imex(mailboxPointer, DC_IMEX_IMPORT_BACKUP, file, nil)
|
|
|
-
|
|
|
- return
|
|
|
}
|
|
|
-
|
|
|
- let alert = UIAlertController(title: String.localized("import_backup_title"), message: String.localizedStringWithFormat(String.localized("import_backup_no_backup_found"), "DUMMYPATH TBD"), preferredStyle: .alert)
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("ok"), style: .cancel, handler: { _ in
|
|
|
-
|
|
|
- }))
|
|
|
- present(alert, animated: true, completion: nil)
|
|
|
- return
|
|
|
+ else {
|
|
|
+ let alert = UIAlertController(title: String.localized("import_backup_title"),
|
|
|
+ message: String.localizedStringWithFormat(String.localized("import_backup_no_backup_found"),
|
|
|
+ "iTunes / <Your Device> / File Sharing / Delta Chat"), // TOOD: maybe better use an iOS-specific string here
|
|
|
+ preferredStyle: .alert)
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("ok"), style: .cancel))
|
|
|
+ present(alert, animated: true)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
logger.error("no documents directory found")
|
|
@@ -641,50 +681,3 @@ class AdvancedSectionHeader: UIView {
|
|
|
handleTap?(toggleButton)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-extension AccountSetupController {
|
|
|
-
|
|
|
- func showProgressHud() {
|
|
|
- configProgressAlert.actions[0].isEnabled = true
|
|
|
- configProgressAlert.title = String.localized("configuring_account")
|
|
|
- configProgressAlert.message = "\n\n\n" // workaround to create space for progress indicator
|
|
|
- configProgressIndicator.alpha = 1
|
|
|
- configProgressIndicator.value = 0
|
|
|
- present(configProgressAlert, animated: true, completion: nil)
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- func updateProgressHud(error message: String?) {
|
|
|
- configProgressAlert.title = String.localized("login_error_title")
|
|
|
- configProgressAlert.message = message
|
|
|
- configProgressIndicator.alpha = 0
|
|
|
- }
|
|
|
-
|
|
|
- func updateProgressHudSuccess(callback: (()->())?) {
|
|
|
- configProgressAlert.actions[0].isEnabled = false
|
|
|
- configProgressIndicator.alpha = 0
|
|
|
- configProgressAlert.title = String.localized("login_successful_title")
|
|
|
- configProgressAlert.message = String.localized("login_successful_message")
|
|
|
- loginButton.isEnabled = dc_is_configured(mailboxPointer) == 0
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
|
|
|
- self.configProgressAlert.dismiss(animated: true) {
|
|
|
- self.handleLoginSuccess()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- private func updateProgressHudValue(value: Int?) {
|
|
|
- if let value = value {
|
|
|
- print("progress hud: \(value)")
|
|
|
- configProgressIndicator.value = CGFloat(value / 10)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func loginCancelled(_ action: UIAlertAction) {
|
|
|
- DcConfig.addr = nil
|
|
|
- DcConfig.mailPw = nil
|
|
|
- DispatchQueue.global(qos: .background).async {
|
|
|
- dc_stop_ongoing_process(mailboxPointer) // this function freezes UI so execute in background thread
|
|
|
- }
|
|
|
- }
|
|
|
-}
|