Add open in browser context menu item
This commit is contained in:
parent
de7970314d
commit
badc2d3e25
|
@ -615,6 +615,13 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
masterFeedViewController.present(addViewController, animated: true)
|
||||
}
|
||||
|
||||
func showBrowser(for indexPath: IndexPath) {
|
||||
guard let preferredLink = articles[indexPath.row].preferredLink, let url = URL(string: preferredLink) else {
|
||||
return
|
||||
}
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
}
|
||||
|
||||
func showBrowserForCurrentArticle() {
|
||||
guard let preferredLink = currentArticle?.preferredLink, let url = URL(string: preferredLink) else {
|
||||
return
|
||||
|
|
|
@ -172,6 +172,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
|||
alert.addAction(action)
|
||||
}
|
||||
|
||||
if let action = self.openInBrowserAlertAction(indexPath: indexPath, completionHandler: completionHandler) {
|
||||
alert.addAction(action)
|
||||
}
|
||||
|
||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
||||
alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in
|
||||
completionHandler(true)
|
||||
|
@ -210,6 +214,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
|||
actions.append(action)
|
||||
}
|
||||
|
||||
if let action = self.openInBrowserAction(indexPath: indexPath) {
|
||||
actions.append(action)
|
||||
}
|
||||
|
||||
return UIMenu(title: "", children: actions)
|
||||
|
||||
})
|
||||
|
@ -599,7 +607,7 @@ private extension MasterTimelineViewController {
|
|||
return nil
|
||||
}
|
||||
|
||||
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
|
||||
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Mark All as Read in Feed")
|
||||
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
|
||||
|
||||
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
|
||||
|
@ -609,4 +617,27 @@ private extension MasterTimelineViewController {
|
|||
return action
|
||||
}
|
||||
|
||||
func openInBrowserAction(indexPath: IndexPath) -> UIAction? {
|
||||
guard let preferredLink = coordinator.articles[indexPath.row].preferredLink, let _ = URL(string: preferredLink) else {
|
||||
return nil
|
||||
}
|
||||
let title = NSLocalizedString("Open in Browser", comment: "Open in Browser")
|
||||
let action = UIAction(title: title, image: AppAssets.safariImage) { [weak self] action in
|
||||
self?.coordinator.showBrowser(for: indexPath)
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
func openInBrowserAlertAction(indexPath: IndexPath, completionHandler: @escaping (Bool) -> Void) -> UIAlertAction? {
|
||||
guard let preferredLink = coordinator.articles[indexPath.row].preferredLink, let _ = URL(string: preferredLink) else {
|
||||
return nil
|
||||
}
|
||||
let title = NSLocalizedString("Open in Browser", comment: "Open in Browser")
|
||||
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
|
||||
self?.coordinator.showBrowser(for: indexPath)
|
||||
completionHandler(true)
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue