|
@@ -3,6 +3,7 @@ import MobileCoreServices
|
|
import DcCore
|
|
import DcCore
|
|
import UIKit
|
|
import UIKit
|
|
import QuickLookThumbnailing
|
|
import QuickLookThumbnailing
|
|
|
|
+import SDWebImage
|
|
|
|
|
|
protocol ShareAttachmentDelegate: class {
|
|
protocol ShareAttachmentDelegate: class {
|
|
func onAttachmentChanged()
|
|
func onAttachmentChanged()
|
|
@@ -49,7 +50,9 @@ class ShareAttachment {
|
|
|
|
|
|
func createMessageFromDataRepresentaion(_ attachments: [NSItemProvider]) {
|
|
func createMessageFromDataRepresentaion(_ attachments: [NSItemProvider]) {
|
|
for attachment in attachments {
|
|
for attachment in attachments {
|
|
- if attachment.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
|
|
|
|
|
|
+ if attachment.hasItemConformingToTypeIdentifier(kUTTypeGIF as String) {
|
|
|
|
+ createAnimatedImageMsg(attachment)
|
|
|
|
+ } else if attachment.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
|
|
createImageMsg(attachment)
|
|
createImageMsg(attachment)
|
|
} else if attachment.hasItemConformingToTypeIdentifier(kUTTypeMovie as String) {
|
|
} else if attachment.hasItemConformingToTypeIdentifier(kUTTypeMovie as String) {
|
|
createMovieMsg(attachment)
|
|
createMovieMsg(attachment)
|
|
@@ -63,6 +66,37 @@ class ShareAttachment {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // for now we only support GIF
|
|
|
|
+ func createAnimatedImageMsg(_ item: NSItemProvider) {
|
|
|
|
+ item.loadItem(forTypeIdentifier: kUTTypeGIF as String, options: nil) { data, error in
|
|
|
|
+ var result: SDAnimatedImage?
|
|
|
|
+ switch data {
|
|
|
|
+ case let animatedImageData as Data:
|
|
|
|
+ result = SDAnimatedImage(data: animatedImageData)
|
|
|
|
+ case let url as URL:
|
|
|
|
+ result = SDAnimatedImage(contentsOfFile: url.path)
|
|
|
|
+ default:
|
|
|
|
+ self.dcContext.logger?.debug("Unexpected data: \(type(of: data))")
|
|
|
|
+ }
|
|
|
|
+ if let result = result, let animatedImageData = result.animatedImageData {
|
|
|
|
+ let path = DcUtils.saveAnimatedImage(data: animatedImageData, suffix: "gif")
|
|
|
|
+ let msg = DcMsg(viewType: DC_MSG_GIF)
|
|
|
|
+ msg.setFile(filepath: path, mimeType: "image/gif")
|
|
|
|
+ let pixelSize = result.imageSizeInPixel()
|
|
|
|
+ msg.setDimension(width: pixelSize.width, height: pixelSize.height)
|
|
|
|
+ self.messages.append(msg)
|
|
|
|
+ self.delegate?.onAttachmentChanged()
|
|
|
|
+ if self.imageThumbnail == nil {
|
|
|
|
+ self.imageThumbnail = result.scaleDownImage(toMax: self.thumbnailSize)
|
|
|
|
+ self.delegate?.onThumbnailChanged()
|
|
|
|
+ }
|
|
|
|
+ if error != nil {
|
|
|
|
+ self.dcContext.logger?.error(error?.localizedDescription ?? "Could not load share item as image")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
func createImageMsg(_ item: NSItemProvider) {
|
|
func createImageMsg(_ item: NSItemProvider) {
|
|
item.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil) { data, error in
|
|
item.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil) { data, error in
|
|
let result: UIImage?
|
|
let result: UIImage?
|