Browse Source

Merge pull request #653 from deltachat/tweak_qr_view

Tweak qr view
cyBerta 5 years ago
parent
commit
8a8df735f2

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -151,6 +151,7 @@
 		AEACE2E51FB32E1900DCDD78 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E41FB32E1900DCDD78 /* Utils.swift */; };
 		AEC67A1C241CE9E4007DDBE1 /* AppStateRestorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */; };
 		AEC67A1E241FCFE0007DDBE1 /* ChatListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */; };
+		AECEF03E244F2D55006C90DA /* QrPageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECEF03D244F2D55006C90DA /* QrPageController.swift */; };
 		AEE56D762253431E007DC082 /* AccountSetupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D752253431E007DC082 /* AccountSetupController.swift */; };
 		AEE56D7D2253ADB4007DC082 /* HudHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7C2253ADB4007DC082 /* HudHandler.swift */; };
 		AEE56D80225504DB007DC082 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7F225504DB007DC082 /* Extensions.swift */; };
@@ -402,6 +403,7 @@
 		AEACE2E41FB32E1900DCDD78 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
 		AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateRestorer.swift; sourceTree = "<group>"; };
 		AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListViewModel.swift; sourceTree = "<group>"; };
+		AECEF03D244F2D55006C90DA /* QrPageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QrPageController.swift; sourceTree = "<group>"; };
 		AEE56D752253431E007DC082 /* AccountSetupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSetupController.swift; sourceTree = "<group>"; tabWidth = 4; };
 		AEE56D7C2253ADB4007DC082 /* HudHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HudHandler.swift; sourceTree = "<group>"; };
 		AEE56D7F225504DB007DC082 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
@@ -796,6 +798,7 @@
 				AEA0F6A024474146009F887B /* ProfileInfoViewController.swift */,
 				789E879521D6CB58003ED1C5 /* QrCodeReaderController.swift */,
 				30A4D9AD2332672600544344 /* QrInviteViewController.swift */,
+				AECEF03D244F2D55006C90DA /* QrPageController.swift */,
 				30149D9222F21129003C12B5 /* QrViewController.swift */,
 				B21005DA23383664004C70C5 /* SettingsClassicViewController.swift */,
 				78E45E3921D3CFBC00D4B15E /* SettingsController.swift */,
@@ -1298,6 +1301,7 @@
 				AE851AC5227C755A00ED86F0 /* Protocols.swift in Sources */,
 				AE728F15229D5C390047565B /* PhotoPickerAlertAction.swift in Sources */,
 				305961F42346125100C80F33 /* TextMessageCell.swift in Sources */,
+				AECEF03E244F2D55006C90DA /* QrPageController.swift in Sources */,
 				AEACE2E31FB32B5C00DCDD78 /* Constants.swift in Sources */,
 				305962052346125100C80F33 /* ContactMessageSizeCalculator.swift in Sources */,
 			);

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

@@ -9,7 +9,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     private let dcContext: DcContext
     private var skipOauth = false
     private var backupProgressObserver: Any?
-    var configureProgressObserver: Any?
+    var progressObserver: Any?
     var onProgressSuccess: VoidFunction? // not needed here
 
     private var oauth2Observer: Any?
@@ -370,7 +370,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
 
     override func viewWillDisappear(_ animated: Bool) {
         resignFirstResponderOnAllCells()
-        configureProgressObserver = nil
+        progressObserver = nil
     }
 
     override func viewDidDisappear(_: Bool) {
@@ -379,7 +379,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         if let backupProgressObserver = self.backupProgressObserver {
             nc.removeObserver(backupProgressObserver)
         }
-        if let configureProgressObserver = self.configureProgressObserver {
+        if let configureProgressObserver = self.progressObserver {
             nc.removeObserver(configureProgressObserver)
         }
         if let oauth2Observer = self.oauth2Observer {
@@ -652,7 +652,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
 
     private func addProgressHudLoginListener() {
         let nc = NotificationCenter.default
-        configureProgressObserver = nc.addObserver(
+        progressObserver = nc.addObserver(
             forName: dcNotificationConfigureProgress,
             object: nil,
             queue: nil

+ 239 - 0
deltachat-ios/Controller/QrPageController.swift

@@ -0,0 +1,239 @@
+import UIKit
+import DcCore
+
+class QrPageController: UIPageViewController, ProgressAlertHandler {
+
+    weak var coordinator: QrViewCoordinator?
+    private let dcContext: DcContext
+    weak var progressAlert: UIAlertController?
+    var progressObserver: Any?
+
+    private var selectedIndex: Int = 0
+
+    private lazy var qrSegmentControl: UISegmentedControl = {
+        let control = UISegmentedControl(
+            items: [String.localized("qrshow_title"), String.localized("qrscan_title")]
+        )
+        control.tintColor = DcColors.primary
+        control.addTarget(self, action: #selector(qrSegmentControlChanged), for: .valueChanged)
+        control.selectedSegmentIndex = 0
+        return control
+    }()
+
+    init(dcContext: DcContext) {
+        self.dcContext = dcContext
+        super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: [:])
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    // MARK: - lifecycle
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        dataSource = self
+        delegate = self
+        navigationItem.titleView = qrSegmentControl
+
+        let qrController = QrViewController(dcContext: dcContext)
+        setViewControllers(
+            [qrController],
+            direction: .forward,
+            animated: true,
+            completion: nil
+        )
+    }
+
+    override func viewWillDisappear(_ animated: Bool) {
+        self.progressObserver = nil
+    }
+
+    // MARK: - actions
+    @objc private func qrSegmentControlChanged(_ sender: UISegmentedControl) {
+        if sender.selectedSegmentIndex == 0 {
+            let qrController = QrViewController(dcContext: dcContext)
+            setViewControllers([qrController], direction: .reverse, animated: true, completion: nil)
+        } else {
+            let qrCodeReaderController = makeQRReader()
+            setViewControllers([qrCodeReaderController], direction: .forward, animated: true, completion: nil)
+        }
+    }
+
+    // MARK: - factory
+    private func makeQRReader() -> QrCodeReaderController {
+        let qrReader = QrCodeReaderController()
+        qrReader.delegate = self
+        return qrReader
+    }
+}
+
+// MARK: - UIPageViewControllerDataSource, UIPageViewControllerDelegate
+extension QrPageController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
+    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
+        if viewController is QrViewController {
+            return nil
+        }
+        return QrViewController(dcContext: dcContext)
+    }
+
+    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
+        if viewController is QrViewController {
+            return makeQRReader()
+        }
+        return nil
+    }
+
+    func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
+        if completed {
+            if previousViewControllers.first is QrViewController {
+                qrSegmentControl.selectedSegmentIndex = 1
+            } else {
+                qrSegmentControl.selectedSegmentIndex = 0
+            }
+        }
+    }
+}
+
+// MARK: - QRCodeDelegate
+extension QrPageController: QrCodeReaderDelegate {
+
+    func handleQrCode(_ code: String) {
+        self.processQrCode(code)
+    }
+
+    private func processQrCode(_ code: String) {
+        let qrParsed: DcLot = self.dcContext.checkQR(qrCode: code)
+        let state = Int32(qrParsed.state)
+        switch state {
+        case DC_QR_ASK_VERIFYCONTACT:
+            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
+            joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), nameAndAddress), code: code)
+
+        case DC_QR_ASK_VERIFYGROUP:
+            let groupName = qrParsed.text1 ?? "ErrGroupName"
+            joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("qrscan_ask_join_group"), groupName), code: code)
+
+        case DC_QR_FPR_WITHOUT_ADDR:
+            let msg = String.localized("qrscan_no_addr_found") + "\n\n" +
+                String.localized("qrscan_fingerprint_label") + ":\n" + (qrParsed.text1 ?? "")
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
+        case DC_QR_FPR_MISMATCH:
+            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
+            let msg = String.localizedStringWithFormat(String.localized("qrscan_fingerprint_mismatch"), nameAndAddress)
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
+        case DC_QR_ADDR, DC_QR_FPR_OK:
+            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
+            let msg = String.localizedStringWithFormat(String.localized(state==DC_QR_ADDR ? "ask_start_chat_with" : "qrshow_x_verified"), nameAndAddress)
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
+                let chatId = self.dcContext.createChatByContactId(contactId: qrParsed.id)
+                self.coordinator?.showChat(chatId: chatId)
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
+        case DC_QR_TEXT:
+            let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), qrParsed.text1 ?? "")
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
+        case DC_QR_URL:
+            let url = qrParsed.text1 ?? ""
+            let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_url"), url)
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("open"), style: .default, handler: { _ in
+                if let url = URL(string: url) {
+                    UIApplication.shared.open(url)
+                }
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
+        case DC_QR_ACCOUNT:
+            let alert = UIAlertController(title: String.localized("qraccount_use_on_new_install"), message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default))
+            present(alert, animated: true)
+
+        default:
+            var msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), code)
+            if state == DC_QR_ERROR {
+                if let errorMsg = qrParsed.text1 {
+                    msg = errorMsg + "\n\n" + msg
+                }
+            }
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+        }
+    }
+
+    private func joinSecureJoin(alertMessage: String, code: String) {
+        let alert = UIAlertController(title: alertMessage,
+                                      message: nil,
+                                      preferredStyle: .alert)
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
+        alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
+            alert.dismiss(animated: true, completion: nil)
+            self.showProgressAlert(title: String.localized("one_moment")+"\n\n", dcContext: self.dcContext)
+            // execute blocking secure join in background
+            DispatchQueue.global(qos: .background).async {
+                self.addSecureJoinProgressListener()
+                self.dcContext.lastErrorString = nil
+                let chatId = self.dcContext.joinSecurejoin(qrCode: code)
+                let errorString = self.dcContext.lastErrorString
+                self.removeSecureJoinProgressListener()
+
+                DispatchQueue.main.async {
+                    self.progressAlert?.dismiss(animated: true, completion: nil)
+                    if chatId != 0 {
+                        self.coordinator?.showChat(chatId: chatId)
+                    } else if errorString != nil {
+                        self.showErrorAlert(error: errorString!)
+                    }
+                }
+            }
+        }))
+        present(alert, animated: true, completion: nil)
+    }
+
+    private func showErrorAlert(error: String) {
+        let alert = UIAlertController(title: String.localized("error"), message: error, preferredStyle: .alert)
+        alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
+            alert.dismiss(animated: true, completion: nil)
+        }))
+    }
+
+    private func addSecureJoinProgressListener() {
+        let nc = NotificationCenter.default
+        progressObserver = nc.addObserver(
+            forName: dcNotificationSecureJoinerProgress,
+            object: nil,
+            queue: nil
+        ) { notification in
+            if let ui = notification.userInfo,
+                ui["progress"] as? Int == 400,
+                let contactId = ui["contact_id"] as? Int {
+                self.progressAlert?.message = String.localizedStringWithFormat(
+                    String.localized("qrscan_x_verified_introduce_myself"),
+                    DcContact(id: contactId).nameNAddr
+                )
+            }
+        }
+    }
+
+    private func removeSecureJoinProgressListener() {
+        let nc = NotificationCenter.default
+        if let observer = self.progressObserver {
+            nc.removeObserver(observer)
+        }
+    }
+
+}

+ 0 - 211
deltachat-ios/Controller/QrViewController.swift

@@ -4,11 +4,7 @@ import DcCore
 
 class QrViewController: UITableViewController {
     private let rowQRCode = 0
-    private let rowScanQR = 1
 
-    weak var coordinator: QrViewCoordinator?
-    let qrCodeReaderController = QrCodeReaderController()
-    var secureJoinObserver: Any?
     var dcContext: DcContext
     var contact: DcContact? {
         // This is nil if we do not have an account setup yet
@@ -30,7 +26,6 @@ class QrViewController: UITableViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         title = String.localized("qr_code")
-        qrCodeReaderController.delegate = self
         tableView.separatorStyle = .none
     }
     
@@ -39,8 +34,6 @@ class QrViewController: UITableViewController {
         switch row {
         case rowQRCode:
             return createQRCodeCell()
-        case rowScanQR:
-            return createQRCodeScanCell()
         default:
             return UITableViewCell(style: .default, reuseIdentifier: nil)
         }
@@ -58,107 +51,11 @@ class QrViewController: UITableViewController {
         switch indexPath.row {
         case rowQRCode:
             return 325
-        case rowScanQR:
-            return 48
         default:
             return 10
         }
     }
 
-    private lazy var progressAlert: UIAlertController = {
-        var title = String.localized("one_moment")+"\n\n"
-        let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
-
-        let rect = CGRect(x: 0, y: 0, width: 25, height: 25)
-        let activityIndicator = UIActivityIndicatorView(frame: rect)
-        activityIndicator.translatesAutoresizingMaskIntoConstraints = false
-        activityIndicator.style = .gray
-
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: { _ in
-            self.dcContext.stopOngoingProcess()
-            self.dismiss(animated: true, completion: nil)
-        }))
-        return alert
-    }()
-
-    private func showProgressAlert() {
-        self.present(self.progressAlert, animated: true, completion: {
-            let rect = CGRect(x: 10, y: 10, width: 20, height: 20)
-            let progressView = UIActivityIndicatorView(frame: rect)
-            progressView.tintColor = .blue
-            progressView.startAnimating()
-            progressView.translatesAutoresizingMaskIntoConstraints = false
-            self.progressAlert.view.addSubview(progressView)
-            self.progressAlert.view.addConstraints([
-                progressView.constraintCenterXTo(self.progressAlert.view),
-                progressView.constraintAlignTopTo(self.progressAlert.view, paddingTop: 45)
-            ])
-        })
-    }
-
-    private func showErrorAlert(error: String) {
-        let alert = UIAlertController(title: String.localized("error"), message: error, preferredStyle: .alert)
-        alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
-            alert.dismiss(animated: true, completion: nil)
-        }))
-    }
-
-    private func addSecureJoinProgressListener() {
-        let nc = NotificationCenter.default
-        secureJoinObserver = nc.addObserver(
-            forName: dcNotificationSecureJoinerProgress,
-            object: nil,
-            queue: nil
-        ) { notification in
-            print("secure join: ", notification)
-            if let ui = notification.userInfo {
-                if ui["progress"] as? Int == 400 {
-                    if let contactId = ui["contact_id"] as? Int {
-                        self.progressAlert.message = String.localizedStringWithFormat(
-                            String.localized("qrscan_x_verified_introduce_myself"),
-                            DcContact(id: contactId).nameNAddr)
-                    }
-                }
-            }
-        }
-    }
-
-    private func removeSecureJoinProgressListener() {
-        let nc = NotificationCenter.default
-        if let secureJoinObserver = self.secureJoinObserver {
-            nc.removeObserver(secureJoinObserver)
-        }
-    }
-
-      private func joinSecureJoin(alertMessage: String, code: String) {
-        let alert = UIAlertController(title: alertMessage,
-                                      message: nil,
-                                      preferredStyle: .alert)
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
-        alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
-            alert.dismiss(animated: true, completion: nil)
-            self.showProgressAlert()
-            // execute blocking secure join in background
-            DispatchQueue.global(qos: .background).async {
-                self.addSecureJoinProgressListener()
-                self.dcContext.lastErrorString = nil
-                let chatId = self.dcContext.joinSecurejoin(qrCode: code)
-                let errorString = self.dcContext.lastErrorString
-                self.removeSecureJoinProgressListener()
-
-                DispatchQueue.main.async {
-                    self.progressAlert.dismiss(animated: true, completion: nil)
-                    if chatId != 0 {
-                        self.coordinator?.showChat(chatId: chatId)
-                    } else if errorString != nil {
-                        self.showErrorAlert(error: errorString!)
-                    }
-                }
-            }
-        }))
-        present(alert, animated: true, completion: nil)
-    }
-
     private func createQRCodeCell() -> UITableViewCell {
         let cell = UITableViewCell(style: .default, reuseIdentifier: "qrCodeCell")
         let qrCode = createQRCodeView()
@@ -178,17 +75,6 @@ class QrViewController: UITableViewController {
         return cell
     }
 
-    private func createQRCodeScanCell() -> UITableViewCell {
-        let cell = UITableViewCell(style: .default, reuseIdentifier: "scanQR")
-        let scanButton = createQRCodeScannerButton()
-        cell.contentView.addSubview(scanButton)
-        cell.selectionStyle = .none
-        let scanButtonConstraints = [scanButton.constraintCenterXTo(cell.contentView),
-                                     scanButton.constraintCenterYTo(cell.contentView)]
-        cell.contentView.addConstraints(scanButtonConstraints)
-        return cell
-    }
-
     private func createInfoLabel() -> UIView {
         let label = UILabel.init()
         label.translatesAutoresizingMaskIntoConstraints = false
@@ -202,20 +88,6 @@ class QrViewController: UITableViewController {
         return label
     }
 
-    private func createQRCodeScannerButton() -> UIView {
-        let btn = UIButton.init(type: UIButton.ButtonType.system)
-        btn.translatesAutoresizingMaskIntoConstraints = false
-        btn.setTitle(String.localized("qrscan_title"), for: .normal)
-        btn.addTarget(self, action: #selector(self.openQRCodeScanner), for: .touchUpInside)
-        return btn
-    }
-
-    @objc func openQRCodeScanner() {
-        let nav = UINavigationController(rootViewController: qrCodeReaderController)
-        nav.modalPresentationStyle = .fullScreen
-        present(nav, animated: true)
-    }
-
     private func createQRCodeView() -> UIView {
         let width: CGFloat = 230
         let frame = CGRect(origin: .zero, size: .init(width: width, height: width))
@@ -241,86 +113,3 @@ class QrViewController: UITableViewController {
         navigationController?.pushViewController(chatVC, animated: true)
     }
 }
-
-// MARK: - QRCodeDelegate
-extension QrViewController: QrCodeReaderDelegate {
-
-    func handleQrCode(_ code: String) {
-        qrCodeReaderController.dismiss(animated: true) {
-            self.processQrCode(code)
-        }
-    }
-
-    private func processQrCode(_ code: String) {
-        let qrParsed: DcLot = self.dcContext.checkQR(qrCode: code)
-        let state = Int32(qrParsed.state)
-        switch state {
-        case DC_QR_ASK_VERIFYCONTACT:
-            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
-            joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), nameAndAddress), code: code)
-
-        case DC_QR_ASK_VERIFYGROUP:
-            let groupName = qrParsed.text1 ?? "ErrGroupName"
-            joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("qrscan_ask_join_group"), groupName), code: code)
-
-        case DC_QR_FPR_WITHOUT_ADDR:
-            let msg = String.localized("qrscan_no_addr_found") + "\n\n" +
-                String.localized("qrscan_fingerprint_label") + ":\n" + (qrParsed.text1 ?? "")
-            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
-            present(alert, animated: true, completion: nil)
-
-        case DC_QR_FPR_MISMATCH:
-            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
-            let msg = String.localizedStringWithFormat(String.localized("qrscan_fingerprint_mismatch"), nameAndAddress)
-            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
-            present(alert, animated: true, completion: nil)
-
-        case DC_QR_ADDR, DC_QR_FPR_OK:
-            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
-            let msg = String.localizedStringWithFormat(String.localized(state==DC_QR_ADDR ? "ask_start_chat_with" : "qrshow_x_verified"), nameAndAddress)
-            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
-                let chatId = self.dcContext.createChatByContactId(contactId: qrParsed.id)
-                self.coordinator?.showChat(chatId: chatId)
-            }))
-            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
-            present(alert, animated: true, completion: nil)
-
-        case DC_QR_TEXT:
-            let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), qrParsed.text1 ?? "")
-            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
-            present(alert, animated: true, completion: nil)
-
-        case DC_QR_URL:
-            let url = qrParsed.text1 ?? ""
-            let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_url"), url)
-            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("open"), style: .default, handler: { _ in
-                if let url = URL(string: url) {
-                    UIApplication.shared.open(url)
-                }
-            }))
-            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
-            present(alert, animated: true, completion: nil)
-
-        case DC_QR_ACCOUNT:
-            let alert = UIAlertController(title: String.localized("qraccount_use_on_new_install"), message: nil, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default))
-            present(alert, animated: true)
-
-        default:
-            var msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), code)
-            if state == DC_QR_ERROR {
-                if let errorMsg = qrParsed.text1 {
-                    msg = errorMsg + "\n\n" + msg
-                }
-            }
-            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
-            present(alert, animated: true, completion: nil)
-        }
-    }
-}

+ 4 - 4
deltachat-ios/Controller/WelcomeViewController.swift

@@ -6,7 +6,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     weak var coordinator: WelcomeCoordinator?
     private let dcContext: DcContext
     private var scannedQrCode: String?
-    var configureProgressObserver: Any?
+    var progressObserver: Any?
     var onProgressSuccess: VoidFunction?
 
     private lazy var scrollView: UIScrollView = {
@@ -62,9 +62,9 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
 
     override func viewDidDisappear(_ animated: Bool) {
         let nc = NotificationCenter.default
-        if let configureProgressObserver = self.configureProgressObserver {
-            nc.removeObserver(configureProgressObserver)
-            self.configureProgressObserver = nil
+        if let observer = self.progressObserver {
+            nc.removeObserver(observer)
+            self.progressObserver = nil
         }
     }
 

+ 10 - 11
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -21,7 +21,7 @@ class AppCoordinator: NSObject, Coordinator {
     private lazy var tabBarController: UITabBarController = {
         let tabBarController = UITabBarController()
         tabBarController.delegate = appStateRestorer
-        tabBarController.viewControllers = [qrController, chatListController, settingsController]
+        tabBarController.viewControllers = [qrPageController, chatListController, settingsController]
         tabBarController.tabBar.tintColor = DcColors.primary
         return tabBarController
     }()
@@ -43,14 +43,14 @@ class AppCoordinator: NSObject, Coordinator {
 
     // MARK: viewControllers
 
-    private lazy var qrController: UIViewController = {
-        let controller = QrViewController(dcContext: dcContext)
-        let nav = UINavigationController(rootViewController: controller)
-        let settingsImage = UIImage(named: "qr_code")
-        nav.tabBarItem = UITabBarItem(title: String.localized("qr_code"), image: settingsImage, tag: qrTab)
+    private lazy var qrPageController: UINavigationController = {
+        let pageController = QrPageController(dcContext: dcContext)
+        let nav = UINavigationController(rootViewController: pageController)
         let coordinator = QrViewCoordinator(navigationController: nav)
         self.childCoordinators.append(coordinator)
-        controller.coordinator = coordinator
+        pageController.coordinator = coordinator
+        let settingsImage = UIImage(named: "qr_code")
+        nav.tabBarItem = UITabBarItem(title: String.localized("qr_code"), image: settingsImage, tag: qrTab)
         return nav
     }()
 
@@ -128,10 +128,9 @@ class AppCoordinator: NSObject, Coordinator {
 
     func handleQRCode(_ code: String) {
         showTab(index: qrTab)
-        if let navController = qrController as? UINavigationController,
-            let topViewController = navController.topViewController,
-            let qrViewController = topViewController as? QrViewController {
-            qrViewController.handleQrCode(code)
+        if let topViewController = qrPageController.topViewController,
+            let qrPageController = topViewController as? QrPageController {
+            qrPageController.handleQrCode(code)
         }
     }
 

+ 2 - 2
deltachat-ios/Handler/ProgressAlertHandler.swift

@@ -3,7 +3,7 @@ import DcCore
 
 protocol ProgressAlertHandler: UIViewController {
     var progressAlert: UIAlertController? { get set }   // needs to be implemented as weak
-    var configureProgressObserver: Any? { get set } // set to nil in viewDidDisappear
+    var progressObserver: Any? { get set } // set to nil in viewDidDisappear
     func showProgressAlert(title: String, dcContext: DcContext)
     func updateProgressAlertValue(value: Int?)
     func updateProgressAlert(error: String?)
@@ -60,7 +60,7 @@ extension ProgressAlertHandler {
 
     func addProgressAlertListener(onSuccess: @escaping VoidFunction) {
         let nc = NotificationCenter.default
-        configureProgressObserver = nc.addObserver(
+        progressObserver = nc.addObserver(
             forName: dcNotificationConfigureProgress,
             object: nil,
             queue: nil