diff --git a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift index 956d20e4b..86852a17d 100644 --- a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift +++ b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift @@ -191,9 +191,7 @@ private extension MasterTimelineTableViewCell { func updateAvatar() { - // The avatar should be bigger than a favicon. They’re too small; they look weird. - let minDimension = 22.0 * RSScreen.mainScreenScale - guard let image = cellData.avatar, cellData.showAvatar, image.size.height >= minDimension, image.size.width >= minDimension else { + guard let image = cellData.avatar, cellData.showAvatar else { makeAvatarEmpty() return } @@ -202,7 +200,7 @@ private extension MasterTimelineTableViewCell { avatarImageView.layer.cornerRadius = MasterTimelineCellLayout.avatarCornerRadius avatarImageView.clipsToBounds = true - if avatarImageView.image !== image { + if avatarImageView.image !== cellData.avatar { avatarImageView.image = image setNeedsLayout() } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index b831b5c63..8b69139db 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -13,6 +13,7 @@ import Articles class MasterTimelineViewController: ProgressTableViewController, UndoableCommandRunner { + private static var minAvatarDimension: CGFloat = 20.0 private var rowHeightWithFeedName: CGFloat = 0.0 private var rowHeightWithoutFeedName: CGFloat = 0.0 @@ -365,15 +366,12 @@ private extension MasterTimelineViewController { func configureTimelineCell(_ cell: MasterTimelineTableViewCell, article: Article) { - var avatar = avatarFor(article) - if avatar == nil, let feed = article.feed { - avatar = appDelegate.faviconDownloader.favicon(for: feed) - } + let avatar = avatarFor(article) let featuredImage = featuredImageFor(article) let showFeedNames = navState?.showFeedNames ?? false - let showAvatars = navState?.showAvatars ?? false - cell.cellData = MasterTimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, avatar: avatar, showAvatar: showAvatars, featuredImage: featuredImage) + let showAvatar = navState?.showAvatars ?? false && avatar != nil + cell.cellData = MasterTimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, avatar: avatar, showAvatar: showAvatar, featuredImage: featuredImage) } @@ -385,7 +383,7 @@ private extension MasterTimelineViewController { if let authors = article.authors { for author in authors { - if let image = avatarForAuthor(author) { + if let image = avatarForAuthor(author), imagePassesQualityAssurance(image) { return image } } @@ -395,8 +393,27 @@ private extension MasterTimelineViewController { return nil } - return appDelegate.feedIconDownloader.icon(for: feed) + let feedIconImage = appDelegate.feedIconDownloader.icon(for: feed) + if imagePassesQualityAssurance(feedIconImage) { + return feedIconImage + } + if let feed = article.feed, let faviconImage = appDelegate.faviconDownloader.favicon(for: feed) { + if imagePassesQualityAssurance(faviconImage) { + return faviconImage + } + } + + return nil + + } + + func imagePassesQualityAssurance(_ image: UIImage?) -> Bool { + let minDimension = MasterTimelineViewController.minAvatarDimension * RSScreen.mainScreenScale + if let image = image, image.size.height >= minDimension, image.size.width >= minDimension { + return true + } + return false } func avatarForAuthor(_ author: Author) -> UIImage? {