Preserve article selection when articles are downloaded (for iPad only)

This commit is contained in:
Maurice Parker 2019-08-30 02:39:54 -05:00
parent 86a302f787
commit 3ab1412dc6
2 changed files with 10 additions and 8 deletions

View File

@ -883,7 +883,11 @@ private extension AppCoordinator {
func replaceArticles(with unsortedArticles: Set<Article>) { func replaceArticles(with unsortedArticles: Set<Article>) {
let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection) let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection)
if articles != sortedArticles { if articles != sortedArticles {
let article = currentArticle
articles = sortedArticles articles = sortedArticles
if let articleID = article?.articleID, let index = row(for: articleID) {
currentArticleIndexPath = IndexPath(row: index, section: 0)
}
} }
} }

View File

@ -475,15 +475,13 @@ private extension MasterTimelineViewController {
} }
func performBlockAndRestoreSelection(_ block: (() -> Void)) { func performBlockAndRestoreSelection(_ block: (() -> Void)) {
let articleID: String? = { guard traitCollection.userInterfaceIdiom == .pad else {
if let indexPath = tableView.indexPathForSelectedRow, indexPath.row < coordinator.articles.count { block()
return coordinator.articles[indexPath.row].articleID return
} }
return nil
}()
let articleID = coordinator.currentArticle?.articleID
block() block()
if let articleID = articleID, let index = coordinator.indexesForArticleIDs(Set([articleID])).first { if let articleID = articleID, let index = coordinator.indexesForArticleIDs(Set([articleID])).first {
let indexPath = IndexPath(row: index, section: 0) let indexPath = IndexPath(row: index, section: 0)
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none) tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)