mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 09:50:16 +00:00
Set only the image on the cell so each download doesn’t rebuild the whole cell.
This commit is contained in:
1 parent
210474f6ac
commit
f41d3d2ac7
5 files changed
+27
-11
No files matched your search
@@ -23,7 +23,7 @@ import Images
|
||||
let showFeedName: TimelineShowFeedName
|
||||
let iconImage: IconImage? // feed icon, user avatar, or favicon
|
||||
let showIcon: Bool // Make space even when icon is nil
|
||||
var thumbnail: NSImage?
|
||||
let thumbnail: NSImage?
|
||||
let showThumbnail: Bool // Make space even when thumbnail is nil
|
||||
let read: Bool
|
||||
let starred: Bool
|
||||
|
||||
@@ -45,6 +45,16 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
}
|
||||
}
|
||||
|
||||
/// The image shown now, which can be newer than `cellData.thumbnail`. Setting this leaves the rest of the cell as it is.
|
||||
var thumbnail: NSImage? {
|
||||
get {
|
||||
thumbnailView.image
|
||||
}
|
||||
set {
|
||||
thumbnailView.image = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var isEmphasized: Bool = false {
|
||||
didSet {
|
||||
unreadIndicatorView.isEmphasized = isEmphasized
|
||||
|
||||
@@ -775,12 +775,12 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
guard let thumbnailMode, let url = notification.userInfo?[ArticleThumbnailFinder.urlKey] as? String else {
|
||||
return
|
||||
}
|
||||
// The row already has room for the thumbnail, so the rest of the cell’s data stays as it is.
|
||||
// The row already has room for the thumbnail, so only the image changes.
|
||||
tableView.enumerateAvailableRowViews { rowView, row in
|
||||
guard let article = articles.articleAtRow(row), ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) == url, let cell = cellForRowView(rowView) as? TimelineTableCellView, let thumbnail = ArticleThumbnailFinder.shared.thumbnail(url: url, mode: thumbnailMode, articleTitle: article.title) else {
|
||||
return
|
||||
}
|
||||
cell.cellData?.thumbnail = thumbnail
|
||||
cell.thumbnail = thumbnail
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,16 @@ final class MainTimelineCell: UICollectionViewCell {
|
||||
}
|
||||
}
|
||||
|
||||
/// The image shown now, which can be newer than `cellData.thumbnail`. Setting this leaves the rest of the cell as it is.
|
||||
var thumbnail: UIImage? {
|
||||
get {
|
||||
thumbnailView.image
|
||||
}
|
||||
set {
|
||||
thumbnailView.image = newValue
|
||||
}
|
||||
}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
commonInit()
|
||||
@@ -126,10 +136,6 @@ final class MainTimelineCell: UICollectionViewCell {
|
||||
updateColors(active: showsAccentSelection)
|
||||
updateIndicatorView(active: showsAccentSelection)
|
||||
}
|
||||
|
||||
func setIconImage(_ image: IconImage) {
|
||||
iconView.iconImage = image
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -609,10 +609,10 @@ extension MainTimelineViewController: UICollectionViewDelegate {
|
||||
reloadCells([article])
|
||||
return
|
||||
}
|
||||
guard let thumbnailURL, let thumbnail = ArticleThumbnailFinder.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title), thumbnail !== cellData.thumbnail else {
|
||||
guard let thumbnailURL, let thumbnail = ArticleThumbnailFinder.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title), thumbnail !== cell.thumbnail else {
|
||||
return
|
||||
}
|
||||
cell.cellData = configure(article: article)
|
||||
cell.thumbnail = thumbnail
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
@@ -1249,10 +1249,10 @@ private extension MainTimelineViewController {
|
||||
}
|
||||
// The row’s height already allows for the thumbnail, so only the cell’s contents change.
|
||||
for indexPath in collectionView.indexPathsForVisibleItems {
|
||||
guard let article = dataSource.itemIdentifier(for: indexPath), ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) == url, let cell = collectionView.cellForItem(at: indexPath) as? MainTimelineCell else {
|
||||
guard let article = dataSource.itemIdentifier(for: indexPath), ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) == url, let cell = collectionView.cellForItem(at: indexPath) as? MainTimelineCell, let thumbnail = ArticleThumbnailFinder.shared.thumbnail(url: url, mode: thumbnailMode, articleTitle: article.title) else {
|
||||
continue
|
||||
}
|
||||
cell.cellData = configure(article: article)
|
||||
cell.thumbnail = thumbnail
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user