diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index afd96d0bf4..d3cb49088b 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -38,6 +38,8 @@ protocol TuskerNavigationDelegate { func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView) func showMoreOptions(forStatus statusID: String) + + func showMoreOptions(forURL url: URL) } extension TuskerNavigationDelegate where Self: UIViewController { @@ -136,11 +138,14 @@ extension TuskerNavigationDelegate where Self: UIViewController { let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) if let url = status.url { - alert.addAction(UIAlertAction(title: "Open in Safari", style: .default, handler: { _ in + alert.addAction(UIAlertAction(title: "Open in Safari", style: .default, handler: { (_) in let vc = SFSafariViewController(url: url) self.present(vc, animated: true) })) - alert.addAction(UIAlertAction(title: "Share", style: .default, handler: { _ in + alert.addAction(UIAlertAction(title: "Copy", style: .default, handler: { (_) in + UIPasteboard.general.url = url + })) + alert.addAction(UIAlertAction(title: "Share...", style: .default, handler: { (_) in let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil) self.present(vc, animated: true) })) @@ -149,4 +154,21 @@ extension TuskerNavigationDelegate where Self: UIViewController { present(alert, animated: true) } + func showMoreOptions(forURL url: URL) { + let alert = UIAlertController(title: nil, message: url.absoluteString, preferredStyle: .actionSheet) + alert.addAction(UIAlertAction(title: "Open in Safari", style: .default, handler: { (_) in + let vc = SFSafariViewController(url: url) + self.present(vc, animated: true) + })) + alert.addAction(UIAlertAction(title: "Copy", style: .default, handler: { (_) in + UIPasteboard.general.url = url + })) + alert.addAction(UIAlertAction(title: "Share...", style: .default, handler: { (_) in + let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil) + self.present(vc, animated: true) + })) + alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) + present(alert, animated: true) + } + } diff --git a/Tusker/Views/ContentLabel.swift b/Tusker/Views/ContentLabel.swift index 5b9a439210..74c301cd54 100644 --- a/Tusker/Views/ContentLabel.swift +++ b/Tusker/Views/ContentLabel.swift @@ -117,7 +117,10 @@ class ContentLabel: TTTAttributedLabel { } func linkLongPressed(_ label: TTTAttributedLabel!, _ link: TTTAttributedLabelLink!) { - // todo: long press options + guard let url = link.result.url else { + return + } + navigationDelegate?.showMoreOptions(forURL: url) } // MARK: - Navigation