Преглед изворни кода

Merge pull request #637 from deltachat/qr-fix-spinner

remove delay after dismissing qr-scan-viewcontroller, cleanup
nayooti пре 5 година
родитељ
комит
9fc08a1c61

+ 2 - 7
DcCore/DcCore/DC/Wrapper.swift

@@ -154,13 +154,8 @@ public class DcContext {
         return DcLot(dc_check_qr(contextPointer, qrCode))
         return DcLot(dc_check_qr(contextPointer, qrCode))
     }
     }
 
 
-    public func configureAccountFromQR(qrCode: String) -> Bool {
-        let state = checkQR(qrCode: qrCode).state
-        if state != DC_QR_ACCOUNT {
-            return false
-        }
-        let success = dc_set_config_from_qr(contextPointer, qrCode)
-        return success == 1
+    public func setConfigFromQR(qrCode: String) -> Bool {
+        return dc_set_config_from_qr(contextPointer, qrCode) != 0
     }
     }
 
 
     public func stopOngoingProcess() {
     public func stopOngoingProcess() {

+ 1 - 1
deltachat-ios/Controller/AccountSetupController.swift

@@ -788,7 +788,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             appDelegate.open()
             appDelegate.open()
             appDelegate.start()
             appDelegate.start()
 
 
-            appDelegate.appCoordinator.presentWelcomeController(animated: true)
+            appDelegate.appCoordinator.presentWelcomeController()
         }))
         }))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
         present(alert, animated: true, completion: nil)
         present(alert, animated: true, completion: nil)

+ 3 - 53
deltachat-ios/Controller/WelcomeViewController.swift

@@ -113,11 +113,6 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         frameGuide.widthAnchor.constraint(equalTo: contentGuide.widthAnchor).isActive = true
         frameGuide.widthAnchor.constraint(equalTo: contentGuide.widthAnchor).isActive = true
     }
     }
 
 
-    /// if active the welcomeViewController will show nothing but a centered activity indicator
-    func activateSpinner(_ active: Bool) {
-        welcomeView.showSpinner(active)
-    }
-
     // MARK: - actions
     // MARK: - actions
 
 
     private func showQRReader(completion onComplete: VoidFunction? = nil) {
     private func showQRReader(completion onComplete: VoidFunction? = nil) {
@@ -130,12 +125,11 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         guard let code = scannedQrCode else {
         guard let code = scannedQrCode else {
             return
             return
         }
         }
-        let success = dcContext.configureAccountFromQR(qrCode: code)
+        let success = dcContext.setConfigFromQR(qrCode: code)
         scannedQrCode = nil
         scannedQrCode = nil
         if success {
         if success {
             addProgressAlertListener(onSuccess: handleLoginSuccess)
             addProgressAlertListener(onSuccess: handleLoginSuccess)
             showProgressAlert(title: String.localized("login_header"))
             showProgressAlert(title: String.localized("login_header"))
-            activateSpinner(false)
             dcContext.configure()
             dcContext.configure()
         } else {
         } else {
             accountCreationErrorAlert()
             accountCreationErrorAlert()
@@ -147,16 +141,11 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     }
     }
 
 
     private func accountCreationErrorAlert() {
     private func accountCreationErrorAlert() {
-        activateSpinner(false)
         let title = DcContext.shared.lastErrorString ?? String.localized("error")
         let title = DcContext.shared.lastErrorString ?? String.localized("error")
         let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
         let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
         alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default))
         alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default))
         present(alert, animated: true)
         present(alert, animated: true)
     }
     }
-
-    func progressAlertWillDismiss() {
-        activateSpinner(true)
-    }
 }
 }
 
 
 extension WelcomeViewController: QrCodeReaderDelegate {
 extension WelcomeViewController: QrCodeReaderDelegate {
@@ -178,10 +167,8 @@ extension WelcomeViewController: QrCodeReaderDelegate {
             title: String.localized("ok"),
             title: String.localized("ok"),
             style: .default,
             style: .default,
             handler: { [unowned self] _ in
             handler: { [unowned self] _ in
-                self.activateSpinner(true)
-                self.qrCodeReaderNav.dismiss(animated: false) {
-                    self.createAccountFromQRCode()
-                }
+                self.qrCodeReaderNav.dismiss(animated: false)
+                self.createAccountFromQRCode()
             }
             }
         )
         )
 
 
@@ -210,17 +197,7 @@ extension WelcomeViewController: QrCodeReaderDelegate {
                 self.qrCordeReader.startSession()
                 self.qrCordeReader.startSession()
             }
             }
         )
         )
-        let qrCancelAction = UIAlertAction(
-             title: String.localized("cancel"),
-             style: .cancel,
-             handler: { [unowned self] _ in
-                 self.qrCodeReaderNav.dismiss(animated: true) {
-                     self.scannedQrCode = nil
-                 }
-             }
-         )
         alert.addAction(okAction)
         alert.addAction(okAction)
-        alert.addAction(qrCancelAction)
         qrCodeReaderNav.present(alert, animated: true, completion: nil)
         qrCodeReaderNav.present(alert, animated: true, completion: nil)
     }
     }
 }
 }
@@ -315,18 +292,6 @@ class WelcomeContentView: UIView {
         return button
         return button
     }()
     }()
 
 
-    private var activityIndicator: UIActivityIndicatorView = {
-        let view: UIActivityIndicatorView
-        if #available(iOS 13, *) {
-             view = UIActivityIndicatorView(style: .large)
-        } else {
-            view = UIActivityIndicatorView(style: .whiteLarge)
-            view.color = UIColor.gray
-        }
-        view.isHidden = true
-        return view
-    }()
-
     private let defaultSpacing: CGFloat = 20
     private let defaultSpacing: CGFloat = 20
 
 
     init() {
     init() {
@@ -401,11 +366,6 @@ class WelcomeContentView: UIView {
             $0.priority = .defaultLow
             $0.priority = .defaultLow
             $0.isActive = true
             $0.isActive = true
         }
         }
-
-        addSubview(activityIndicator)
-        activityIndicator.translatesAutoresizingMaskIntoConstraints = false
-        activityIndicator.centerYAnchor.constraint(equalTo: buttonContainerGuide.centerYAnchor).isActive = true
-        activityIndicator.centerXAnchor.constraint(equalTo: container.centerXAnchor).isActive = true
     }
     }
 
 
     private func calculateLogoHeight() -> CGFloat {
     private func calculateLogoHeight() -> CGFloat {
@@ -428,14 +388,4 @@ class WelcomeContentView: UIView {
      @objc private func importBackupButtonPressed(_ sender: UIButton) {
      @objc private func importBackupButtonPressed(_ sender: UIButton) {
          onImportBackup?()
          onImportBackup?()
      }
      }
-
-    func showSpinner(_ show: Bool) {
-        if show {
-            activityIndicator.startAnimating()
-        } else {
-            activityIndicator.stopAnimating()
-        }
-        activityIndicator.isHidden = !show
-        buttonStack.isHidden = show
-    }
 }
 }

+ 2 - 17
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -91,7 +91,7 @@ class AppCoordinator: NSObject, Coordinator {
         if dcContext.isConfigured() {
         if dcContext.isConfigured() {
             presentTabBarController()
             presentTabBarController()
         } else {
         } else {
-            showWelcomeController()
+            presentWelcomeController()
         }
         }
     }
     }
 
 
@@ -133,19 +133,7 @@ class AppCoordinator: NSObject, Coordinator {
         }
         }
     }
     }
 
 
-    func presentWelcomeController(animated: Bool) {
-        if animated {
-            welcomeController.activateSpinner(true)
-            showWelcomeController()
-            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
-                self.welcomeController.activateSpinner(false)
-            }
-        } else {
-            showWelcomeController()
-        }
-    }
-
-    private func showWelcomeController() {
+    func presentWelcomeController() {
         // the applicationIconBadgeNumber is remembered by the system even on reinstalls (just tested on ios 13.3.1),
         // the applicationIconBadgeNumber is remembered by the system even on reinstalls (just tested on ios 13.3.1),
         // to avoid appearing an old number of a previous installation, we reset the counter manually.
         // to avoid appearing an old number of a previous installation, we reset the counter manually.
         // but even when this changes in ios, we need the reset as we allow account-deletion also in-app.
         // but even when this changes in ios, we need the reset as we allow account-deletion also in-app.
@@ -181,18 +169,15 @@ extension AppCoordinator: WelcomeCoordinator {
     
     
 
 
     func handleLoginSuccess() {
     func handleLoginSuccess() {
-        welcomeController.activateSpinner(true) // this will hide welcomeController's content
         DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
         DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
             self.loginController.dismiss(animated: true) { // this is ignored if loginController is not shown
             self.loginController.dismiss(animated: true) { // this is ignored if loginController is not shown
                 self.presentTabBarController()
                 self.presentTabBarController()
-                self.welcomeController.activateSpinner(false)
             }
             }
         }
         }
     }
     }
 
 
     func handleQRAccountCreationSuccess() {
     func handleQRAccountCreationSuccess() {
         self.presentTabBarController()
         self.presentTabBarController()
-        self.welcomeController.activateSpinner(false)
     }
     }
 
 
     @objc private func cancelButtonPressed(_ sender: UIBarButtonItem) {
     @objc private func cancelButtonPressed(_ sender: UIBarButtonItem) {