Convert the timeline to use diffable datasources

This commit is contained in:
Maurice Parker
2019-08-30 14:17:05 -05:00
parent 3baca1d7c0
commit 07ca61f7cf
4 changed files with 109 additions and 83 deletions

View File

@@ -468,11 +468,17 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
animatingChanges = false
}
func indexForArticleID(_ articleID: String?) -> Int? {
guard let articleID = articleID else { return nil }
updateArticleRowMapIfNeeded()
return articleRowMap[articleID]
}
func indexesForArticleIDs(_ articleIDs: Set<String>) -> IndexSet {
var indexes = IndexSet()
articleIDs.forEach { (articleID) in
guard let oneIndex = row(for: articleID) else {
guard let oneIndex = indexForArticleID(articleID) else {
return
}
if oneIndex != NSNotFound {
@@ -482,7 +488,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
return indexes
}
func selectFeed(_ indexPath: IndexPath) {
if navControllerForTimeline().viewControllers.filter({ $0 is MasterTimelineViewController }).count > 0 {
currentMasterIndexPath = indexPath
@@ -885,17 +891,12 @@ private extension AppCoordinator {
if articles != sortedArticles {
let article = currentArticle
articles = sortedArticles
if let articleID = article?.articleID, let index = row(for: articleID) {
if let articleID = article?.articleID, let index = indexForArticleID(articleID) {
currentArticleIndexPath = IndexPath(row: index, section: 0)
}
}
}
func row(for articleID: String) -> Int? {
updateArticleRowMapIfNeeded()
return articleRowMap[articleID]
}
func updateArticleRowMap() {
var rowMap = [String: Int]()
var index = 0