From 640faaa1144afefb6f71c2a49643be47182a7677 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 3 Sep 2019 16:07:02 -0500 Subject: [PATCH] Simplify the article replacement logic --- .../MasterTimelineViewController.swift | 4 --- iOS/SceneCoordinator.swift | 25 +++++++------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 475568a77..1738dafc6 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -132,10 +132,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner resetUI() } - func updateArticles() { - reloadAllVisibleCells() - } - func reloadArticles(animate: Bool) { applyChanges(animate: animate) { [weak self] in self?.updateArticleSelection(animate: animate) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index feaa5bb6f..ab6af96be 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -176,22 +176,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { private(set) var currentArticleIndexPath: IndexPath? - private(set) var articles = ArticleArray() { - didSet { - if articles == oldValue { - return - } - if articles.representSameArticlesInSameOrder(as: oldValue) { - articleRowMap = [String: Int]() - masterTimelineViewController?.updateArticles() - updateUnreadCount() - return - } - updateShowAvatars() - articleRowMap = [String: Int]() - updateUnreadCount() - } - } + private(set) var articles = ArticleArray() var isTimelineUnreadAvailable: Bool { if let unreadProvider = timelineFetcher as? UnreadCountProvider { @@ -1000,13 +985,21 @@ private extension SceneCoordinator { func replaceArticles(with unsortedArticles: Set
, animate: Bool) { let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection) + if articles != sortedArticles { + let article = currentArticle articles = sortedArticles + + updateShowAvatars() + articleRowMap = [String: Int]() + updateUnreadCount() + masterTimelineViewController?.reloadArticles(animate: animate) if let articleID = article?.articleID, let index = indexForArticleID(articleID) { currentArticleIndexPath = IndexPath(row: index, section: 0) } + } }