From f4b0b9b70ace19a47bacbbe53a243287be482ed5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 5 Sep 2019 13:40:10 -0400 Subject: [PATCH] Use share sheet instead of alert controller for status options --- Tusker/Activities/UIActivity+Types.swift | 4 ++++ Tusker/TuskerNavigationDelegate.swift | 25 ++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Tusker/Activities/UIActivity+Types.swift b/Tusker/Activities/UIActivity+Types.swift index 1f5d9a18..4fc0de39 100644 --- a/Tusker/Activities/UIActivity+Types.swift +++ b/Tusker/Activities/UIActivity+Types.swift @@ -11,8 +11,12 @@ import UIKit extension UIActivity.ActivityType { static let openInSafari = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).open_in_safari") + + // Account static let sendMessageMentioningAccount = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).send_message_mentioning_account") static let followAccount = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).follow_account") static let unfollowAccount = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unfollow_account") + // Status + } diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 7f51b8e4..a6ae82b2 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -146,25 +146,16 @@ extension TuskerNavigationDelegate where Self: UIViewController { present(gallery(attachments: attachments, sourceViews: sourceViews, startIndex: startIndex), animated: true) } - private func moreOptions(forURL url: URL) -> UIAlertController { - let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - alert.title = url.absoluteString - 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)) - return alert + private func moreOptions(forURL url: URL) -> UIViewController { + let customActivites: [UIActivity] = [ + OpenInSafariActivity() + ] + let activityController = UIActivityViewController(activityItems: [url], applicationActivities: customActivites) + activityController.completionWithItemsHandler = OpenInSafariActivity.completionHandler(viewController: self, url: url) + return activityController } - private func moreOptions(forStatus statusID: String) -> UIAlertController { + private func moreOptions(forStatus statusID: String) -> UIViewController { guard let status = MastodonCache.status(for: statusID) else { fatalError("Missing cached status \(statusID)") } guard let url = status.url else { fatalError("Missing url for status \(statusID)") } return moreOptions(forURL: url)