Optimize table cell loading so that we are no longer reloading all visible cells when an image is downloaded
This commit is contained in:
parent
af98311c63
commit
c752d0b699
|
@ -33,8 +33,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .FeedIconDidBecomeAvailable, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .FeedIconDidBecomeAvailable, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||||
|
|
||||||
|
@ -250,7 +249,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func statusesDidChange(_ note: Notification) {
|
@objc func statusesDidChange(_ note: Notification) {
|
||||||
|
|
||||||
guard let articles = note.userInfo?[Account.UserInfoKey.articles] as? Set<Article> else {
|
guard let articles = note.userInfo?[Account.UserInfoKey.articles] as? Set<Article> else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -258,55 +256,59 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func feedIconDidBecomeAvailable(_ note: Notification) {
|
@objc func feedIconDidBecomeAvailable(_ note: Notification) {
|
||||||
|
|
||||||
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else {
|
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
performBlockAndRestoreSelection {
|
performBlockAndRestoreSelection {
|
||||||
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
||||||
|
|
||||||
guard let article = coordinator.articles.articleAtRow(indexPath.row) else {
|
guard let article = coordinator.articles.articleAtRow(indexPath.row) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if feed == article.feed {
|
if feed == article.feed {
|
||||||
tableView.reloadRows(at: [indexPath], with: .none)
|
tableView.reloadRows(at: [indexPath], with: .none)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func avatarDidBecomeAvailable(_ note: Notification) {
|
@objc func avatarDidBecomeAvailable(_ note: Notification) {
|
||||||
|
|
||||||
guard coordinator.showAvatars, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
|
guard coordinator.showAvatars, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
performBlockAndRestoreSelection {
|
performBlockAndRestoreSelection {
|
||||||
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
||||||
|
|
||||||
guard let article = coordinator.articles.articleAtRow(indexPath.row), let authors = article.authors, !authors.isEmpty else {
|
guard let article = coordinator.articles.articleAtRow(indexPath.row), let authors = article.authors, !authors.isEmpty else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for author in authors {
|
for author in authors {
|
||||||
if author.avatarURL == avatarURL {
|
if author.avatarURL == avatarURL {
|
||||||
tableView.reloadRows(at: [indexPath], with: .none)
|
tableView.reloadRows(at: [indexPath], with: .none)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func imageDidBecomeAvailable(_ note: Notification) {
|
@objc func faviconDidBecomeAvailable(_ note: Notification) {
|
||||||
if coordinator.showAvatars {
|
guard coordinator.showAvatars, let faviconURL = note.userInfo?["faviconURL"] as? String else {
|
||||||
queueReloadVisableCells()
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
performBlockAndRestoreSelection {
|
||||||
|
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
||||||
|
|
||||||
|
guard let article = coordinator.articles.articleAtRow(indexPath.row), let articleFaviconURL = article.feed?.faviconURL else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if faviconURL == articleFaviconURL {
|
||||||
|
tableView.reloadRows(at: [indexPath], with: .none)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue