浏览代码

drag and drop videos to message input bar

cyberta 2 年之前
父节点
当前提交
97c970a840
共有 2 个文件被更改,包括 25 次插入5 次删除
  1. 5 1
      deltachat-ios/Chat/ChatViewController.swift
  2. 20 4
      deltachat-ios/Chat/Views/ChatInputTextView.swift

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

@@ -1265,7 +1265,7 @@ class ChatViewController: UITableViewController {
         messageInputBar.inputTextView.scrollIndicatorInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
         configureInputBarItems()
         messageInputBar.inputTextView.delegate = self
-        messageInputBar.inputTextView.imagePasteDelegate = self
+        messageInputBar.inputTextView.textViewPasteDelegate = self
         messageInputBar.onScrollDownButtonPressed = scrollToBottom
     }
 
@@ -2412,6 +2412,10 @@ extension ChatViewController: ChatInputTextViewPasteDelegate {
     func onImageDragAndDropped(image: UIImage) {
         stageImage(image)
     }
+
+    func onVideoDragAndDropped(url: URL) {
+        stageVideo(url: url as NSURL)
+    }
 }
 
 

+ 20 - 4
deltachat-ios/Chat/Views/ChatInputTextView.swift

@@ -4,7 +4,7 @@ import MobileCoreServices
 
 public class ChatInputTextView: InputTextView {
 
-    public weak var imagePasteDelegate: ChatInputTextViewPasteDelegate?
+    public weak var textViewPasteDelegate: ChatInputTextViewPasteDelegate?
 
     // MARK: - Image Paste Support
     open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
@@ -18,13 +18,13 @@ public class ChatInputTextView: InputTextView {
         guard let image = UIPasteboard.general.image else {
             return super.paste(sender)
         }
-        imagePasteDelegate?.onImagePasted(image: image)
+        textViewPasteDelegate?.onImagePasted(image: image)
     }
 }
 
 extension ChatInputTextView: UIDropInteractionDelegate {
     public func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool {
-        return  session.items.count == 1 && session.hasItemsConforming(toTypeIdentifiers: [kUTTypeImage as String, kUTTypeText as String])
+        return  session.items.count == 1 && session.hasItemsConforming(toTypeIdentifiers: [kUTTypeImage as String, kUTTypeText as String, kUTTypeMovie as String, kUTTypeVideo as String])
     }
 
     public func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {
@@ -35,7 +35,22 @@ extension ChatInputTextView: UIDropInteractionDelegate {
         if session.hasItemsConforming(toTypeIdentifiers: [kUTTypeImage as String]) {
             session.loadObjects(ofClass: UIImage.self) { [weak self] imageItems in
                 if let images = imageItems as? [UIImage] {
-                    self?.imagePasteDelegate?.onImageDragAndDropped(image: images[0])
+                    self?.textViewPasteDelegate?.onImageDragAndDropped(image: images[0])
+                }
+            }
+        } else if session.hasItemsConforming(toTypeIdentifiers: [kUTTypeMovie as String, kUTTypeVideo as String]) {
+            session.loadObjects(ofClass: NSData.self) { [weak self] videoItems in
+                if let videos = videoItems as? [NSData] {
+                    let video = videos[0] as Data
+                    if let mimeType = Swime.mimeType(data: video) {
+                        DispatchQueue.global().async { [weak self] in
+                            if let fileName = FileHelper.saveData(data: video, name: "tmp_dragAndDrop", suffix: mimeType.ext, directory: .cachesDirectory) {
+                                DispatchQueue.main.async {
+                                    self?.textViewPasteDelegate?.onVideoDragAndDropped(url: URL(fileURLWithPath: fileName))
+                                }
+                            }
+                        }
+                    }
                 }
             }
         } else if session.hasItemsConforming(toTypeIdentifiers: [kUTTypeText as String]) {
@@ -55,4 +70,5 @@ extension ChatInputTextView: UIDropInteractionDelegate {
 public protocol ChatInputTextViewPasteDelegate: class {
     func onImagePasted(image: UIImage)
     func onImageDragAndDropped(image: UIImage)
+    func onVideoDragAndDropped(url: URL)
 }