Use share sheet instead of alert controller for status options

This commit is contained in:
Shadowfacts 2019-09-05 13:40:10 -04:00
parent b60688f4b8
commit f4b0b9b70a
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 12 additions and 17 deletions

View File

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

View File

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