From 0462e57635d095ce3499732b8fd3417f3652f68e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 11 Oct 2018 21:52:11 -0400 Subject: [PATCH] Add 3d touch preview actions --- .../ConversationViewController.swift | 16 ++++++++++++ .../Profile/ProfileTableViewController.swift | 25 ++++++++++++++++--- Tusker/TuskerNavigationDelegate.swift | 4 +-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Conversation/ConversationViewController.swift b/Tusker/Screens/Conversation/ConversationViewController.swift index d841109c..01269cb5 100644 --- a/Tusker/Screens/Conversation/ConversationViewController.swift +++ b/Tusker/Screens/Conversation/ConversationViewController.swift @@ -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] { var statuses = statuses var parents: [Status] = [] diff --git a/Tusker/Screens/Profile/ProfileTableViewController.swift b/Tusker/Screens/Profile/ProfileTableViewController.swift index 1c3364e3..e61df74c 100644 --- a/Tusker/Screens/Profile/ProfileTableViewController.swift +++ b/Tusker/Screens/Profile/ProfileTableViewController.swift @@ -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() { loadingVC?.remove() @@ -226,15 +245,15 @@ extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate { let account = MastodonCache.account(for: accountID)! 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) 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) 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() })) alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index ff89d9d5..afd96d0b 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -136,11 +136,11 @@ 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: "Share", style: .default, handler: { _ in let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil) self.present(vc, animated: true) }))