forked from shadowfacts/Tusker
parent
9af8c06b1c
commit
489840019e
|
@ -444,6 +444,7 @@ extension AttachmentView: UIContextMenuInteractionDelegate {
|
||||||
}
|
}
|
||||||
} actionProvider: { [unowned self] _ in
|
} actionProvider: { [unowned self] _ in
|
||||||
let itemSource: UIActivityItemSource
|
let itemSource: UIActivityItemSource
|
||||||
|
let itemData: Task<Data?, Never>
|
||||||
if self.attachment.kind == .image,
|
if self.attachment.kind == .image,
|
||||||
let source {
|
let source {
|
||||||
switch source {
|
switch source {
|
||||||
|
@ -457,20 +458,41 @@ extension AttachmentView: UIContextMenuInteractionDelegate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
itemSource = ImageActivityItemSource(data: imageData, url: url, image: image)
|
itemSource = ImageActivityItemSource(data: imageData, url: url, image: image)
|
||||||
|
itemData = Task { imageData }
|
||||||
|
|
||||||
case .gifData(let url, let data, let image):
|
case .gifData(let url, let data, let image):
|
||||||
itemSource = ImageActivityItemSource(data: data, url: url, image: image)
|
itemSource = ImageActivityItemSource(data: data, url: url, image: image)
|
||||||
|
itemData = Task { data }
|
||||||
}
|
}
|
||||||
} else if self.attachment.kind == .gifv {
|
} else if self.attachment.kind == .gifv {
|
||||||
itemSource = GifvActivityItemSource(asset: AVAsset(url: self.attachment.url), attachment: self.attachment)
|
itemSource = GifvActivityItemSource(asset: AVAsset(url: self.attachment.url), attachment: self.attachment)
|
||||||
|
itemData = Task {
|
||||||
|
try? await URLSession.shared.data(from: self.attachment.url).0
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return UIMenu(children: [
|
var actions = [
|
||||||
UIAction(title: "Share…", image: UIImage(systemName: "square.and.arrow.up")) { [unowned self] _ in
|
UIAction(title: "Share…", image: UIImage(systemName: "square.and.arrow.up")) { [unowned self] _ in
|
||||||
let vc = UIActivityViewController(activityItems: [itemSource], applicationActivities: [SaveToPhotosActivity()])
|
let vc = UIActivityViewController(activityItems: [itemSource], applicationActivities: [SaveToPhotosActivity()])
|
||||||
self.delegate?.attachmentViewPresent(vc, animated: true)
|
self.delegate?.attachmentViewPresent(vc, animated: true)
|
||||||
}
|
}
|
||||||
])
|
]
|
||||||
|
let activity = SaveToPhotosActivity()
|
||||||
|
if activity.canPerform(withActivityItems: [self.attachment.url]) {
|
||||||
|
actions.append(UIAction(title: "Save to Photos", image: UIImage(systemName: "square.and.arrow.down"), handler: { _ in
|
||||||
|
Task {
|
||||||
|
guard let itemData = await itemData.value else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent(self.attachment.url.lastPathComponent)
|
||||||
|
try itemData.write(to: tempURL)
|
||||||
|
activity.prepare(withActivityItems: [tempURL])
|
||||||
|
activity.perform()
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
return UIMenu(children: actions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue