aboutsummaryrefslogtreecommitdiff
path: root/foray/Coordinators
diff options
context:
space:
mode:
Diffstat (limited to 'foray/Coordinators')
-rw-r--r--foray/Coordinators/ForayCoordinator.swift32
1 files changed, 32 insertions, 0 deletions
diff --git a/foray/Coordinators/ForayCoordinator.swift b/foray/Coordinators/ForayCoordinator.swift
index 874f486..972bfb8 100644
--- a/foray/Coordinators/ForayCoordinator.swift
+++ b/foray/Coordinators/ForayCoordinator.swift
@@ -7,6 +7,7 @@
import Foundation
import UIKit
+import LinkPresentation
class ForayCoordinator: Coordinator {
var childCoordinators = [Coordinator]()
@@ -36,4 +37,35 @@ class ForayCoordinator: Coordinator {
func hideLoading() {
loadingOverlay.hide()
}
+
+ func share(item: PenguinItemViewModel) {
+ let itemSource = ForayLinkPresentationSource(title: "\(item.name) (#\(item.id))", shareURL: URL(string: "https://nick.tay.blue/")!)
+ let activity = UIActivityViewController(activityItems: [itemSource], applicationActivities: nil)
+ navigationController.present(activity, animated: true)
+ }
+}
+
+class ForayLinkPresentationSource: NSObject, UIActivityItemSource {
+ private let metadata: LPLinkMetadata
+
+ func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
+ return metadata
+ }
+
+ func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
+ guard let url = metadata.originalURL else { return "" }
+ return url.absoluteURL
+ }
+
+ func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
+ return metadata.originalURL
+ }
+
+ init(title: String, shareURL: URL) {
+ metadata = LPLinkMetadata()
+ metadata.iconProvider = NSItemProvider(contentsOf: Bundle.main.url(forResource: "spy", withExtension: "png"))
+ metadata.originalURL = shareURL
+ metadata.url = shareURL
+ metadata.title = title
+ }
}