Add 3d touch preview actions

This commit is contained in:
Shadowfacts 2018-10-11 21:52:11 -04:00
parent 0b6459a806
commit 0462e57635
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 40 additions and 5 deletions

View File

@ -66,6 +66,22 @@ class ConversationViewController: UITableViewController {
} }
} }
override var previewActionItems: [UIPreviewActionItem] {
var actions = [UIPreviewActionItem]()
if let status = MastodonCache.status(for: mainStatusID),
let url = status.url {
actions.append(UIPreviewAction(title: "Open in Safari", style: .default, handler: { (_, _) in
let vc = self.viewController(forURL: url)
UIApplication.shared.delegate!.window!!.rootViewController!.present(vc, animated: true)
}))
actions.append(UIPreviewAction(title: "Share", style: .default, handler: { (_, _) in
let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil)
UIApplication.shared.delegate!.window!!.rootViewController!.present(vc, animated: true)
}))
}
return actions
}
func getDirectParents(of status: Status, from statuses: [Status]) -> [Status] { func getDirectParents(of status: Status, from statuses: [Status]) -> [Status] {
var statuses = statuses var statuses = statuses
var parents: [Status] = [] var parents: [Status] = []

View File

@ -99,6 +99,25 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
} }
} }
override var previewActionItems: [UIPreviewActionItem] {
var actions = [UIPreviewActionItem]()
if let account = MastodonCache.account(for: accountID) {
actions.append(UIPreviewAction(title: "Open in Safari", style: .default, handler: { (_, _) in
let vc = self.viewController(forURL: account.url)
UIApplication.shared.delegate!.window!!.rootViewController!.present(vc, animated: true)
}))
actions.append(UIPreviewAction(title: "Share", style: .default, handler: { (_, _) in
let vc = UIActivityViewController(activityItems: [account.url], applicationActivities: nil)
UIApplication.shared.delegate!.window!!.rootViewController!.present(vc, animated: true)
}))
actions.append(UIPreviewAction(title: "Send Message", style: .default, handler: { (_, _) in
let vc = ComposeViewController.create(mentioning: account.acct)
UIApplication.shared.delegate!.window!!.rootViewController!.present(vc, animated: true)
}))
}
return actions
}
func updateAccountUI() { func updateAccountUI() {
loadingVC?.remove() loadingVC?.remove()
@ -226,15 +245,15 @@ extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate {
let account = MastodonCache.account(for: accountID)! let account = MastodonCache.account(for: accountID)!
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
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: account.url) let vc = SFSafariViewController(url: account.url)
self.present(vc, animated: true) self.present(vc, animated: true)
})) }))
alert.addAction(UIAlertAction(title: "Share...", style: .default, handler: { _ in alert.addAction(UIAlertAction(title: "Share", style: .default, handler: { _ in
let vc = UIActivityViewController(activityItems: [account.url], applicationActivities: nil) let vc = UIActivityViewController(activityItems: [account.url], applicationActivities: nil)
self.present(vc, animated: true) self.present(vc, animated: true)
})) }))
alert.addAction(UIAlertAction(title: "Send Message...", style: .default, handler: { _ in alert.addAction(UIAlertAction(title: "Send Message", style: .default, handler: { _ in
self.sendMessageMentioning() self.sendMessageMentioning()
})) }))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

View File

@ -136,11 +136,11 @@ extension TuskerNavigationDelegate where Self: UIViewController {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if let url = status.url { 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) let vc = SFSafariViewController(url: url)
self.present(vc, animated: true) self.present(vc, animated: true)
})) }))
alert.addAction(UIAlertAction(title: "Share...", style: .default, handler: { _ in alert.addAction(UIAlertAction(title: "Share", style: .default, handler: { _ in
let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil) let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil)
self.present(vc, animated: true) self.present(vc, animated: true)
})) }))