فهرست منبع

add basic share functionality in DocumentGalleryController

cyberta 3 سال پیش
والد
کامیت
f33d9846dc

+ 19 - 1
deltachat-ios/Controller/DocumentGalleryController.swift

@@ -41,9 +41,16 @@ class DocumentGalleryController: UIViewController {
                 self?.redirectToMessage(of: indexPath)
             }
         )
+        let shareItem = ContextMenuProvider.ContextMenuItem(
+            title: String.localized("menu_share"),
+            imageName: "square.and.arrow.up",
+            action: #selector(DocumentGalleryFileCell.share(_:)), onPerform: { [weak self] indexPath in
+                self?.shareAttachment(of: indexPath)
+            }
+        )
 
         let menu = ContextMenuProvider()
-        menu.setMenu([showInChatItem, deleteItem])
+        menu.setMenu([showInChatItem, deleteItem, shareItem])
         return menu
     }()
 
@@ -180,4 +187,15 @@ extension DocumentGalleryController {
             appDelegate.appCoordinator.showChat(chatId: chatId, msgId: msgId, animated: false, clearViewControllerStack: true)
         }
     }
+
+    func shareAttachment(of indexPath: IndexPath) {
+        let msgId = fileMessageIds[indexPath.row]
+        let message = dcContext.getMessage(id: msgId)
+        guard let fileURL = message.fileURL else { return }
+
+        let objectsToShare = [fileURL] as [Any]
+        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
+        activityVC.title = "Hello World!"
+        self.present(activityVC, animated: true, completion: nil)
+    }
 }

+ 5 - 1
deltachat-ios/View/Cell/DocumentGalleryFileCell.swift

@@ -111,7 +111,7 @@ class DocumentGalleryFileCell: UITableViewCell {
         }
     }
 
-    // needed for iOS 12 context men
+    // needed for iOS 12 context menu
     @objc func itemDelete(_ sender: Any) {
         self.performAction(#selector(DocumentGalleryFileCell.itemDelete(_:)), with: sender)
     }
@@ -120,6 +120,10 @@ class DocumentGalleryFileCell: UITableViewCell {
         self.performAction(#selector(DocumentGalleryFileCell.showInChat(_:)), with: sender)
     }
 
+    @objc func share(_ sender: Any) {
+        self.performAction(#selector(DocumentGalleryFileCell.share(_:)), with: sender)
+    }
+
     func performAction(_ action: Selector, with sender: Any?) {
         if let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
             tableView.delegate?.tableView?(