Add avatar and featuredImage to TimelineCellData.

This commit is contained in:
Brent Simmons 2017-11-25 21:27:35 -08:00
parent b9c562b77a
commit 4052f85e10
3 changed files with 65 additions and 5 deletions

View File

@ -654,10 +654,10 @@
children = (
849A97621ED9EB96007D329B /* SidebarViewController.swift */,
849A97601ED9EB96007D329B /* SidebarOutlineView.swift */,
845A29251FC928C7007B49E3 /* Cell */,
849A97611ED9EB96007D329B /* SidebarTreeControllerDelegate.swift */,
849A97631ED9EB96007D329B /* UnreadCountView.swift */,
845F52EC1FB2B9FC00C10BF0 /* FeedPasteboardWriter.swift */,
845A29251FC928C7007B49E3 /* Cell */,
);
path = Sidebar;
sourceTree = "<group>";

View File

@ -24,9 +24,11 @@ struct TimelineCellData {
let attributedFeedName: NSAttributedString
let showFeedName: Bool
let favicon: NSImage?
let avatar: NSImage? // feed or user avatar
let featuredImage: NSImage? // image from within the article
let read: Bool
init(article: Article, appearance: TimelineCellAppearance, showFeedName: Bool) {
init(article: Article, appearance: TimelineCellAppearance, showFeedName: Bool, favicon: NSImage?, avatar: NSImage?, featuredImage: NSImage?) {
self.title = timelineTruncatedTitle(article)
self.text = timelineTruncatedSummary(article)
@ -65,7 +67,10 @@ struct TimelineCellData {
self.showFeedName = showFeedName
self.favicon = nil
self.favicon = favicon
self.avatar = avatar
self.featuredImage = featuredImage
self.read = article.status.read
}
@ -80,6 +85,8 @@ struct TimelineCellData {
self.attributedFeedName = NSAttributedString(string: "")
self.showFeedName = false
self.favicon = nil
self.avatar = nil
self.featuredImage = nil
self.read = true
}

View File

@ -319,7 +319,7 @@ class TimelineViewController: NSViewController, KeyboardDelegate, UndoableComman
let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, userDeleted: false, dateArrived: Date())
let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, bannerImageURL: nil, datePublished: nil, dateModified: nil, authors: nil, tags: nil, attachments: nil, status: status)
let prototypeCellData = TimelineCellData(article: prototypeArticle, appearance: cellAppearance, showFeedName: false)
let prototypeCellData = TimelineCellData(article: prototypeArticle, appearance: cellAppearance, showFeedName: false, favicon: nil, avatar: nil, featuredImage: nil)
let height = timelineCellHeight(100, cellData: prototypeCellData, appearance: cellAppearance)
return height
}
@ -410,7 +410,60 @@ extension TimelineViewController: NSTableViewDelegate {
private func configureTimelineCell(_ cell: TimelineTableCellView, article: Article) {
cell.objectValue = article
cell.cellData = TimelineCellData(article: article, appearance: cellAppearance, showFeedName: showFeedNames)
let favicon = faviconFor(article)
let avatar = avatarFor(article)
let featuredImage = featuredImageFor(article)
cell.cellData = TimelineCellData(article: article, appearance: cellAppearance, showFeedName: showFeedNames, favicon: favicon, avatar: avatar, featuredImage: featuredImage)
}
private func faviconFor(_ article: Article) -> NSImage? {
guard let feed = article.feed else {
return nil
}
return appDelegate.faviconDownloader.favicon(for: feed)
}
private func avatarFor(_ article: Article) -> NSImage? {
if let authors = article.authors {
for author in authors {
if let image = avatarForAuthor(author) {
return image
}
}
}
guard let feed = article.feed else {
return nil
}
// TODO: make Feed know about its authors.
// https://github.com/brentsimmons/Evergreen/issues/212
if let iconURL = feed.iconURL {
return appDelegate.imageDownloader.image(for: iconURL)
}
return nil
}
private func avatarForAuthor(_ author: Author) -> NSImage? {
if let url = author.avatarURL {
return appDelegate.imageDownloader.image(for: url)
}
return nil
}
private func featuredImageFor(_ article: Article) -> NSImage? {
if let url = article.imageURL {
return appDelegate.imageDownloader.image(for: url)
}
return nil
}
private func makeTimelineCellEmpty(_ cell: TimelineTableCellView) {