diff --git a/iOS/AppCoordinator.swift b/iOS/AppCoordinator.swift index 91689b2b3..5ecc5c90b 100644 --- a/iOS/AppCoordinator.swift +++ b/iOS/AppCoordinator.swift @@ -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 diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index b84431c61..7ff2f371f 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -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 @@ -608,5 +616,28 @@ 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 + } }