Przeglądaj źródła

add Files button to the navigation bar of webxdc selector

cyberta 2 lat temu
rodzic
commit
6495ef23d6

+ 4 - 5
deltachat-ios/Chat/ChatViewController.swift

@@ -1495,13 +1495,8 @@ class ChatViewController: UITableViewController {
                 sheet.preferredCornerRadius = 20
             }
         }
-        let leftBarBtn = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel,
-                                                            target: webxdcSelector,
-                                              action: #selector(webxdcSelector.cancelAction))
-        webxdcSelectorNavigationController.navigationBar.topItem?.setLeftBarButton(leftBarBtn, animated: false)
 
         self.present(webxdcSelectorNavigationController, animated: true)
-        //navigationController?.present(webxdcSelector, animated: true)
     }
 
     private func showDocumentLibrary() {
@@ -2415,6 +2410,10 @@ extension ChatViewController: ChatInputTextViewPasteDelegate {
 
 
 extension ChatViewController: WebxdcSelectorDelegate {
+    func onWebxdcFromFilesSelected(url: NSURL) {
+        onDocumentSelected(url: url)
+    }
+
     func onWebxdcSelected(msgId: Int) {
         keepKeyboard = true
         DispatchQueue.main.async { [weak self] in

+ 38 - 2
deltachat-ios/Controller/WebxdcSelector.swift

@@ -4,6 +4,7 @@ import QuickLook
 
 protocol WebxdcSelectorDelegate: AnyObject {
     func onWebxdcSelected(msgId: Int)
+    func onWebxdcFromFilesSelected(url: NSURL)
 }
 
 class WebxdcSelector: UIViewController {
@@ -48,7 +49,28 @@ class WebxdcSelector: UIViewController {
         return label
     }()
 
-       init(context: DcContext, mediaMessageIds: [Int]) {
+    private lazy var leftBarBtn: UIBarButtonItem = {
+        let btn = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel,
+                                                             target: self,
+                                               action: #selector(cancelAction))
+        return btn
+    }()
+
+    private lazy var rightBarBtn: UIBarButtonItem = {
+        let btn = UIBarButtonItem(title: String.localized("files"),
+                                  style: .plain,
+                                  target: self,
+                                  action: #selector(filesAction))
+        return btn
+    }()
+
+    private lazy var mediaPicker: MediaPicker? = {
+        let mediaPicker = MediaPicker(navigationController: navigationController)
+        mediaPicker.delegate = self
+        return mediaPicker
+    }()
+
+    init(context: DcContext, mediaMessageIds: [Int]) {
         self.dcContext = context
         self.mediaMessageIds = mediaMessageIds
         self.deduplicatedMessageHashes = [:]
@@ -66,6 +88,8 @@ class WebxdcSelector: UIViewController {
         super.viewDidLoad()
         setupSubviews()
         title = String.localized("webxdcs")
+        navigationItem.setLeftBarButton(leftBarBtn, animated: false)
+        navigationItem.setRightBarButton(rightBarBtn, animated: false)
         if mediaMessageIds.isEmpty {
             emptyStateView.isHidden = false
         }
@@ -119,9 +143,12 @@ class WebxdcSelector: UIViewController {
     }
     
     @objc func cancelAction() {
-        logger.debug("cancel Action")
         dismiss(animated: true, completion: nil)
     }
+
+    @objc func filesAction() {
+        mediaPicker?.showDocumentLibrary()
+    }
 }
 
 extension WebxdcSelector: UICollectionViewDataSourcePrefetching {
@@ -212,3 +239,12 @@ private extension WebxdcSelector {
         gridLayout.containerWidth = containerWidth
     }
 }
+
+extension WebxdcSelector: MediaPickerDelegate {
+    func onImageSelected(image: UIImage) {}
+
+    func onDocumentSelected(url: NSURL) {
+        delegate?.onWebxdcFromFilesSelected(url: url)
+        dismiss(animated: true)
+    }
+}