Add link long press actions

This commit is contained in:
Shadowfacts 2018-10-11 22:04:32 -04:00
parent 0462e57635
commit 6fbd826371
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 28 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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