Ver código fonte

Merge pull request #632 from deltachat/qr_follow_up

qr-Account creation enhancements
bjoern 5 anos atrás
pai
commit
6ffdb15474

+ 15 - 29
deltachat-ios/Controller/WelcomeViewController.swift

@@ -133,44 +133,30 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         let success = dcContext.configureAccountFromQR(qrCode: code)
         scannedQrCode = nil
         if success {
-            if let loginCompletion = self.onProgressSuccess {
-                addProgressAlertListener(onSuccess: loginCompletion)
-                showProgressAlert(title: String.localized("qraccount_use_on_new_install"))
-            }
+            addProgressAlertListener(onSuccess: handleLoginSuccess)
+            showProgressAlert(title: String.localized("login_header"))
+            activateSpinner(false)
             dcContext.configure()
         } else {
             accountCreationErrorAlert()
         }
     }
 
-    private func accountCreationErrorAlert() {
-        func handleRepeat() {
-            showQRReader(completion: { [unowned self] in
-                self.activateSpinner(false)
-            })
-        }
+    private func handleLoginSuccess() {
+        onProgressSuccess?()
+    }
 
-        let title = String.localized("qraccount_creation_failed")
+    private func accountCreationErrorAlert() {
+        activateSpinner(false)
+        let title = DcContext.shared.lastErrorString ?? String.localized("error")
         let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
-        let okAction = UIAlertAction(
-            title: String.localized("ok"),
-            style: .default,
-            handler: { [unowned self] _ in
-                self.activateSpinner(false)
-            }
-        )
-
-        let repeatAction = UIAlertAction(
-            title: String.localized("global_menu_edit_redo_desktop"),
-            style: .default,
-            handler: { _ in
-                handleRepeat()
-            }
-        )
-        alert.addAction(okAction)
-        alert.addAction(repeatAction)
+        alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default))
         present(alert, animated: true)
     }
+
+    func progressAlertWillDismiss() {
+        activateSpinner(true)
+    }
 }
 
 extension WelcomeViewController: QrCodeReaderDelegate {
@@ -193,7 +179,7 @@ extension WelcomeViewController: QrCodeReaderDelegate {
             style: .default,
             handler: { [unowned self] _ in
                 self.activateSpinner(true)
-                self.qrCodeReaderNav.dismiss(animated: true) {
+                self.qrCodeReaderNav.dismiss(animated: false) {
                     self.createAccountFromQRCode()
                 }
             }

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

@@ -4,12 +4,12 @@ import DcCore
 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)
+    func progressAlertWillDismiss()
 }
 
 extension ProgressAlertHandler {
@@ -38,6 +38,8 @@ 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) {
                 onComplete?()
@@ -63,5 +65,9 @@ extension ProgressAlertHandler {
             }
         }
     }
+
+    func progressAlertWillDismiss() {
+        // can be overwritten if needed
+    }
 }
 

+ 0 - 1
tools/untranslated.xml

@@ -5,5 +5,4 @@
     <string name="import_contacts">Import device contacts</string>
     <string name="import_contacts_message">To chat with contacts from your device open Settings and enable Contacts.</string>
     <string name="stop_sharing_location">Stop sharing location</string>
-    <string  name="qraccount_config_failed">Account creation failed.</string>
 </resources>