Merge pull request #1540 from myurieff/previewing-articles

Previewing articles
This commit is contained in:
Maurice Parker 2020-01-07 16:24:38 -07:00 committed by GitHub
commit 7edaf87733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 34 deletions

View File

@ -18,6 +18,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
private lazy var feedTapGestureRecognizer = UITapGestureRecognizer(target: self, action:#selector(showFeedInspector(_:)))
private var refreshProgressView: RefreshProgressView?
private var currentlyPreviewedArticle: Article?
@IBOutlet weak var filterButton: UIBarButtonItem!
@IBOutlet weak var markAllAsReadButton: UIBarButtonItem!
@ -306,41 +307,36 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil }
return UIContextMenuConfiguration(identifier: indexPath.row as NSCopying, previewProvider: nil, actionProvider: { [weak self] suggestedActions in
currentlyPreviewedArticle = article
guard let self = self else { return nil }
return UIContextMenuConfiguration(
identifier: indexPath.row as NSCopying,
previewProvider: { [weak self] in
var actions = [UIAction]()
actions.append(self.toggleArticleReadStatusAction(article))
actions.append(self.toggleArticleStarStatusAction(article))
guard let self = self else { return nil }
let articleViewController = UIStoryboard.main.instantiateController(ofType: ArticleViewController.self)
articleViewController.coordinator = self.coordinator
articleViewController.article = article
return articleViewController
}, actionProvider: { [weak self] suggestedActions in
guard let self = self else { return nil }
return UIMenu(title: "", children: [
self.toggleArticleReadStatusAction(article),
self.toggleArticleStarStatusAction(article),
self.markAboveAsReadAction(article),
self.markBelowAsReadAction(article),
self.discloseFeedAction(article),
self.markAllInFeedAsReadAction(article),
self.openInBrowserAction(article),
self.shareAction(article, indexPath: indexPath)
].compactMap { $0 })
if let action = self.markAboveAsReadAction(article) {
actions.append(action)
}
if let action = self.markBelowAsReadAction(article) {
actions.append(action)
}
if let action = self.discloseFeedAction(article) {
actions.append(action)
}
if let action = self.markAllInFeedAsReadAction(article) {
actions.append(action)
}
if let action = self.openInBrowserAction(article) {
actions.append(action)
}
if let action = self.shareAction(article, indexPath: indexPath) {
actions.append(action)
}
return UIMenu(title: "", children: actions)
})
)
}
@ -353,6 +349,13 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
return UITargetedPreview(view: cell, parameters: CroppingPreviewParameters(view: cell))
}
override func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
if let article = currentlyPreviewedArticle {
coordinator.selectArticle(article)
currentlyPreviewedArticle = nil
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
becomeFirstResponder()
let article = dataSource.itemIdentifier(for: indexPath)