فهرست منبع

Merge pull request #1805 from deltachat/copy-qr-code

copy qr code data to clipboard
cyBerta 2 سال پیش
والد
کامیت
b59bd0b7df
2فایلهای تغییر یافته به همراه44 افزوده شده و 0 حذف شده
  1. 22 0
      deltachat-ios/Controller/QrPageController.swift
  2. 22 0
      deltachat-ios/Controller/QrViewController.swift

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

@@ -39,6 +39,16 @@ class QrPageController: UIPageViewController {
         return control
     }()
 
+    private lazy var moreButton: UIBarButtonItem = {
+        let image: UIImage?
+        if #available(iOS 13.0, *) {
+            image = UIImage(systemName: "ellipsis.circle")
+        } else {
+            image = UIImage(named: "ic_more")
+        }
+        return UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(showMoreOptions))
+    }()
+
     init(dcAccounts: DcAccounts) {
         self.dcAccounts = dcAccounts
         self.dcContext = dcAccounts.getSelected()
@@ -55,6 +65,7 @@ class QrPageController: UIPageViewController {
         dataSource = self
         delegate = self
         navigationItem.titleView = qrSegmentControl
+        navigationItem.rightBarButtonItem = moreButton
 
         let qrController = QrViewController(dcContext: dcContext, qrCodeHint: qrCodeHint)
         setViewControllers(
@@ -94,6 +105,17 @@ class QrPageController: UIPageViewController {
         }
     }
 
+    @objc private func showMoreOptions() {
+        let alert = UIAlertController(title: String.localized("qrshow_title"), message: nil, preferredStyle: .safeActionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("menu_copy_to_clipboard"), style: .default, handler: copyToClipboard(_:)))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+        self.present(alert, animated: true, completion: nil)
+    }
+
+    @objc func copyToClipboard(_ action: UIAlertAction) {
+        UIPasteboard.general.string = dcContext.getSecurejoinQr(chatId: 0)
+    }
+
     // MARK: - factory
     private func makeQRReader() -> QrCodeReaderController {
         let qrReader = QrCodeReaderController()

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

@@ -17,6 +17,16 @@ class QrViewController: UIViewController {
         return view
     }()
 
+    private lazy var moreButton: UIBarButtonItem = {
+        let image: UIImage?
+        if #available(iOS 13.0, *) {
+            image = UIImage(systemName: "ellipsis.circle")
+        } else {
+            image = UIImage(named: "ic_more")
+        }
+        return UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(showMoreOptions))
+    }()
+
     var qrCodeHint: String {
         willSet {
             let svg = dcContext.getSecurejoinQrSVG(chatId: chatId)
@@ -43,6 +53,7 @@ class QrViewController: UIViewController {
         title = String.localized("qrshow_title")
         setupSubviews()
         view.backgroundColor = DcColors.defaultBackgroundColor
+        navigationItem.rightBarButtonItem = moreButton
     }
 
     override func viewDidDisappear(_ animated: Bool) {
@@ -71,4 +82,15 @@ class QrViewController: UIViewController {
         return nil
     }
 
+    // MARK: - actions
+    @objc private func showMoreOptions() {
+        let alert = UIAlertController(title: String.localized("qrshow_title"), message: nil, preferredStyle: .safeActionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("menu_copy_to_clipboard"), style: .default, handler: copyToClipboard(_:)))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+        self.present(alert, animated: true, completion: nil)
+    }
+
+    @objc func copyToClipboard(_ action: UIAlertAction) {
+        UIPasteboard.general.string = dcContext.getSecurejoinQr(chatId: chatId)
+    }
 }