Refactor mark as read for articles to be in the SceneCoordinator instead of in the DetailViewController

This commit is contained in:
Maurice Parker 2019-09-01 12:52:06 -05:00
parent 858bdb7f21
commit a5298f0381
2 changed files with 11 additions and 19 deletions

View File

@ -50,9 +50,7 @@ class DetailViewController: UIViewController {
NSLayoutConstraint.activate(constraints) NSLayoutConstraint.activate(constraints)
markAsRead() updateArticleSelection()
updateUI()
reloadHTML()
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
@ -65,12 +63,6 @@ class DetailViewController: UIViewController {
updateProgressIndicatorIfNeeded() updateProgressIndicatorIfNeeded()
} }
func markAsRead() {
if let article = coordinator.currentArticle {
markArticles(Set([article]), statusKey: .read, flag: true)
}
}
func updateUI() { func updateUI() {
guard let article = coordinator.currentArticle else { guard let article = coordinator.currentArticle else {
@ -174,7 +166,6 @@ class DetailViewController: UIViewController {
// MARK: API // MARK: API
func updateArticleSelection() { func updateArticleSelection() {
markAsRead()
updateUI() updateUI()
reloadHTML() reloadHTML()
} }

View File

@ -120,7 +120,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
var timelineFetcher: ArticleFetcher? { var timelineFetcher: ArticleFetcher? {
didSet { didSet {
currentArticleIndexPath = nil selectArticle(nil)
if timelineFetcher is Feed { if timelineFetcher is Feed {
showFeedNames = false showFeedNames = false
} else { } else {
@ -186,14 +186,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
return nil return nil
} }
private(set) var currentArticleIndexPath: IndexPath? { private(set) var currentArticleIndexPath: IndexPath?
didSet {
if currentArticleIndexPath != oldValue {
masterTimelineViewController?.updateArticleSelection(animate: true)
detailViewController?.updateArticleSelection()
}
}
}
private(set) var articles = ArticleArray() { private(set) var articles = ArticleArray() {
didSet { didSet {
@ -506,6 +499,10 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
currentArticleIndexPath = indexPath currentArticleIndexPath = indexPath
activityManager.reading(currentArticle) activityManager.reading(currentArticle)
if let article = currentArticle {
markArticles(Set([article]), statusKey: .read, flag: true)
}
if indexPath == nil { if indexPath == nil {
if !rootSplitViewController.isCollapsed { if !rootSplitViewController.isCollapsed {
let systemMessageViewController = UIStoryboard.main.instantiateController(ofType: SystemMessageViewController.self) let systemMessageViewController = UIStoryboard.main.instantiateController(ofType: SystemMessageViewController.self)
@ -527,6 +524,10 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
rootSplitViewController.preferredDisplayMode = .automatic rootSplitViewController.preferredDisplayMode = .automatic
} }
masterTimelineViewController?.updateArticleSelection(animate: true)
detailViewController?.updateArticleSelection()
} }
func searchArticles(_ searchString: String, _ searchScope: SearchScope) { func searchArticles(_ searchString: String, _ searchScope: SearchScope) {