Implement default timeline avatar. Issue #641

This commit is contained in:
Maurice Parker 2019-05-21 05:42:40 -05:00
parent 139518530e
commit 3207ebf6a5
16 changed files with 55 additions and 70 deletions

View File

@ -1,5 +1,5 @@
//
// AppImages.swift
// AppAssets.swift
// NetNewsWire
//
// Created by Brent Simmons on 2/17/18.
@ -14,7 +14,7 @@ extension NSImage.Name {
static let timelineStar = NSImage.Name("timelineStar")
}
struct AppImages {
struct AppAssets {
static var genericFeedImage: RSImage? = {
let path = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns"
@ -34,4 +34,8 @@ struct AppImages {
return RSImage(named: "accountFeedbin")
}()
static var faviconTemplateImage: RSImage = {
return RSImage(named: "faviconTemplateImage")!
}()
}

View File

@ -110,7 +110,7 @@ private extension FeedInspectorViewController {
return
}
imageView?.image = AppImages.genericFeedImage
imageView?.image = AppAssets.genericFeedImage
}
func updateName() {

View File

@ -42,7 +42,7 @@ import RSCore
return nil
}
let image = sendToCommand.image ?? AppImages.genericFeedImage ?? NSImage()
let image = sendToCommand.image ?? AppAssets.genericFeedImage ?? NSImage()
return NSSharingService(title: sendToCommand.title, image: image, alternateImage: nil) {
sendToCommand.sendObject(object, selectedText: nil)
}

View File

@ -81,7 +81,7 @@ class SidebarCell : NSTableCellView {
}()
private let faviconImageView: NSImageView = {
let image = AppImages.genericFeedImage
let image = AppAssets.genericFeedImage
let imageView = image != nil ? NSImageView(image: image!) : NSImageView(frame: NSRect.zero)
imageView.animates = false
imageView.imageAlignment = .alignCenter

View File

@ -19,14 +19,14 @@ class TimelineTableCellView: NSTableCellView {
private let feedNameView = TimelineTableCellView.singleLineTextField()
private lazy var avatarImageView: NSImageView = {
let imageView = TimelineTableCellView.imageView(with: AppImages.genericFeedImage, scaling: .scaleNone)
let imageView = TimelineTableCellView.imageView(with: AppAssets.genericFeedImage, scaling: .scaleNone)
imageView.imageAlignment = .alignTop
imageView.imageScaling = .scaleProportionallyDown
imageView.wantsLayer = true
return imageView
}()
private let starView = TimelineTableCellView.imageView(with: AppImages.timelineStar, scaling: .scaleNone)
private let starView = TimelineTableCellView.imageView(with: AppAssets.timelineStar, scaling: .scaleNone)
private lazy var textFields = {
return [self.dateView, self.feedNameView, self.titleView, self.summaryView, self.textView]

View File

@ -702,10 +702,7 @@ extension TimelineViewController: NSTableViewDelegate {
private func configureTimelineCell(_ cell: TimelineTableCellView, article: Article) {
cell.objectValue = 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)
cell.cellData = TimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, avatar: avatar, showAvatar: showAvatars, featuredImage: featuredImage)
@ -715,6 +712,7 @@ extension TimelineViewController: NSTableViewDelegate {
if !showAvatars {
return nil
}
if let authors = article.authors {
for author in authors {
if let image = avatarForAuthor(author) {
@ -727,7 +725,15 @@ extension TimelineViewController: NSTableViewDelegate {
return nil
}
return appDelegate.feedIconDownloader.icon(for: feed)
if let feedIcon = appDelegate.feedIconDownloader.icon(for: feed) {
return feedIcon
}
if let favicon = appDelegate.faviconDownloader.favicon(for: feed) {
return favicon
}
return FaviconGenerator.favicon(feed)
}
private func avatarForAuthor(_ author: Author) -> NSImage? {

View File

@ -59,10 +59,10 @@ extension AccountsAddViewController: NSTableViewDelegate {
switch row {
case 0:
cell.accountNameLabel?.stringValue = Account.defaultLocalAccountName
cell.accountImageView?.image = AppImages.accountLocal
cell.accountImageView?.image = AppAssets.accountLocal
case 1:
cell.accountNameLabel?.stringValue = NSLocalizedString("Feedbin", comment: "Feedbin")
cell.accountImageView?.image = AppImages.accountFeedbin
cell.accountImageView?.image = AppAssets.accountFeedbin
default:
break
}

View File

@ -100,7 +100,7 @@ extension AccountsPreferencesViewController: NSTableViewDelegate {
cell.textField?.stringValue = account.nameForDisplay
switch account.type {
case .onMyMac:
cell.imageView?.image = AppImages.accountLocal
cell.imageView?.image = AppAssets.accountLocal
case .feedbin:
cell.imageView?.image = NSImage(named: "accountFeedbin")
default:

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "faviconTemplateImage.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}

View File

@ -29,6 +29,7 @@
51543685228F6753005E1CDF /* DetailAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51543684228F6753005E1CDF /* DetailAccountViewController.swift */; };
515436882291D75D005E1CDF /* AddLocalAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515436872291D75D005E1CDF /* AddLocalAccountViewController.swift */; };
5154368A2291FED9005E1CDF /* FeedbinAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515436892291FED9005E1CDF /* FeedbinAccountViewController.swift */; };
5154368B229404D1005E1CDF /* FaviconGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF0F76227716200050506E /* FaviconGenerator.swift */; };
51554C24228B71910055115A /* SyncDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51554C01228B6EB50055115A /* SyncDatabase.framework */; };
51554C25228B71910055115A /* SyncDatabase.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 51554C01228B6EB50055115A /* SyncDatabase.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
51554C30228B71A10055115A /* SyncDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51554C01228B6EB50055115A /* SyncDatabase.framework */; };
@ -70,7 +71,6 @@
51C45258226508CF00C03939 /* AppAssets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45254226507D200C03939 /* AppAssets.swift */; };
51C45259226508D300C03939 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45255226507D200C03939 /* AppDefaults.swift */; };
51C4525A226508D600C03939 /* UIStoryboard-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C4524E226506F400C03939 /* UIStoryboard-Extensions.swift */; };
51C4525B226508DA00C03939 /* UIImage-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C4524F226506F400C03939 /* UIImage-Extensions.swift */; };
51C4525C226508DF00C03939 /* String-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45250226506F400C03939 /* String-Extensions.swift */; };
51C45268226508F600C03939 /* MasterFeedUnreadCountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45261226508F600C03939 /* MasterFeedUnreadCountView.swift */; };
51C45269226508F600C03939 /* MasterFeedTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45262226508F600C03939 /* MasterFeedTableViewCell.swift */; };
@ -224,7 +224,7 @@
849A979F1ED9F130007D329B /* SidebarCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A979E1ED9F130007D329B /* SidebarCell.swift */; };
849A97A31ED9F180007D329B /* FolderTreeControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97A11ED9F180007D329B /* FolderTreeControllerDelegate.swift */; };
849C64681ED37A5D003D8FC0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 849C64671ED37A5D003D8FC0 /* Assets.xcassets */; };
849EE70F203919360082A1EA /* AppImages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849EE70E203919360082A1EA /* AppImages.swift */; };
849EE70F203919360082A1EA /* AppAssets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849EE70E203919360082A1EA /* AppAssets.swift */; };
849EE72120391F560082A1EA /* SharingServicePickerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849EE72020391F560082A1EA /* SharingServicePickerDelegate.swift */; };
84A14FF320048CA70046AD9A /* SendToMicroBlogCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A14FF220048CA70046AD9A /* SendToMicroBlogCommand.swift */; };
84A1500520048DDF0046AD9A /* SendToMarsEditCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A1500420048DDF0046AD9A /* SendToMarsEditCommand.swift */; };
@ -691,7 +691,6 @@
5183CCEE227125970010922C /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
519B8D322143397200FA689C /* SharingServiceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingServiceDelegate.swift; sourceTree = "<group>"; };
51C4524E226506F400C03939 /* UIStoryboard-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboard-Extensions.swift"; sourceTree = "<group>"; };
51C4524F226506F400C03939 /* UIImage-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage-Extensions.swift"; sourceTree = "<group>"; };
51C45250226506F400C03939 /* String-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String-Extensions.swift"; sourceTree = "<group>"; };
51C45254226507D200C03939 /* AppAssets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppAssets.swift; sourceTree = "<group>"; };
51C45255226507D200C03939 /* AppDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDefaults.swift; sourceTree = "<group>"; };
@ -830,7 +829,7 @@
849C64601ED37A5D003D8FC0 /* NetNewsWire.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetNewsWire.app; sourceTree = BUILT_PRODUCTS_DIR; };
849C64671ED37A5D003D8FC0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
849C64711ED37A5D003D8FC0 /* NetNewsWireTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NetNewsWireTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
849EE70E203919360082A1EA /* AppImages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppImages.swift; sourceTree = "<group>"; };
849EE70E203919360082A1EA /* AppAssets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppAssets.swift; sourceTree = "<group>"; };
849EE72020391F560082A1EA /* SharingServicePickerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingServicePickerDelegate.swift; sourceTree = "<group>"; };
84A14FF220048CA70046AD9A /* SendToMicroBlogCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendToMicroBlogCommand.swift; sourceTree = "<group>"; };
84A1500420048DDF0046AD9A /* SendToMarsEditCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendToMarsEditCommand.swift; sourceTree = "<group>"; };
@ -1064,7 +1063,6 @@
51C45250226506F400C03939 /* String-Extensions.swift */,
51F85BF82274AA7B00C787DC /* UIBarButtonItem-Extensions.swift */,
51F85BF622749FA100C787DC /* UIFont-Extensions.swift */,
51C4524F226506F400C03939 /* UIImage-Extensions.swift */,
51C4524E226506F400C03939 /* UIStoryboard-Extensions.swift */,
512E092B2268B25500BDCFDD /* UISplitViewController-Extensions.swift */,
);
@ -1550,7 +1548,7 @@
848363062262A3DD00DA1D35 /* Main.storyboard */,
84C9FC6622629B3900D921D6 /* AppDelegate.swift */,
84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */,
849EE70E203919360082A1EA /* AppImages.swift */,
849EE70E203919360082A1EA /* AppAssets.swift */,
842E45DC1ED8C54B000A8B52 /* Browser.swift */,
842E45E11ED8C681000A8B52 /* MainWindow */,
84BBB12A20142A4700F054F5 /* Inspector */,
@ -2317,7 +2315,6 @@
51C4527B2265091600C03939 /* MasterUnreadIndicatorView.swift in Sources */,
51F85BF92274AA7B00C787DC /* UIBarButtonItem-Extensions.swift in Sources */,
51C45296226509D300C03939 /* OPMLExporter.swift in Sources */,
51C4525B226508DA00C03939 /* UIImage-Extensions.swift in Sources */,
51C45291226509C800C03939 /* SmartFeed.swift in Sources */,
51C452A722650A3D00C03939 /* RSImage-Extensions.swift in Sources */,
51C45269226508F600C03939 /* MasterFeedTableViewCell.swift in Sources */,
@ -2472,7 +2469,7 @@
84C9FC7722629E1200D921D6 /* AdvancedPreferencesViewController.swift in Sources */,
849EE72120391F560082A1EA /* SharingServicePickerDelegate.swift in Sources */,
849A97981ED9EFAA007D329B /* Node-Extensions.swift in Sources */,
849EE70F203919360082A1EA /* AppImages.swift in Sources */,
849EE70F203919360082A1EA /* AppAssets.swift in Sources */,
849A97531ED9EAC0007D329B /* AddFeedController.swift in Sources */,
5183CCE8226F68D90010922C /* AccountRefreshTimer.swift in Sources */,
849A97831ED9EC63007D329B /* SidebarStatusBarView.swift in Sources */,
@ -2490,6 +2487,7 @@
84C9FC7A22629E1200D921D6 /* AccountsTableViewBackgroundView.swift in Sources */,
8426119E1FCB6ED40086A189 /* HTMLMetadataDownloader.swift in Sources */,
849A976E1ED9EBC8007D329B /* TimelineViewController.swift in Sources */,
5154368B229404D1005E1CDF /* FaviconGenerator.swift in Sources */,
5183CCE6226F4E110010922C /* RefreshInterval.swift in Sources */,
849A97771ED9EC04007D329B /* TimelineCellData.swift in Sources */,
841ABA6020145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift in Sources */,

View File

@ -23,7 +23,7 @@ extension Feed: SmallIconProvider {
return image
}
#if os(macOS)
return AppImages.genericFeedImage
return AppAssets.genericFeedImage
#else
return FaviconGenerator.favicon(self)
#endif

View File

@ -21,7 +21,7 @@ final class FaviconGenerator {
}
let colorHash = ColorHash(feed.url)
if let favicon = AppAssets.faviconTemplateImage.maskWithColor(color: colorHash.color) {
if let favicon = AppAssets.faviconTemplateImage.maskWithColor(color: colorHash.color.cgColor) {
FaviconGenerator.faviconGeneratorCache[feed.url] = favicon
return favicon
} else {

View File

@ -24,12 +24,12 @@ struct AppAssets {
static var chevronDownImage: RSImage = {
let image = RSImage(named: "chevronDownImage")!
return image.maskWithColor(color: AppAssets.chevronDisclosureColor)!
return image.maskWithColor(color: AppAssets.chevronDisclosureColor.cgColor)!
}()
static var chevronRightImage: RSImage = {
let image = RSImage(named: "chevronRightImage")!
return image.maskWithColor(color: AppAssets.chevronDisclosureColor)!
return image.maskWithColor(color: AppAssets.chevronDisclosureColor.cgColor)!
}()
static var faviconTemplateImage: RSImage = {
@ -42,7 +42,7 @@ struct AppAssets {
static var feedImage: RSImage = {
let image = RSImage(named: "feedImage")!
return image.maskWithColor(color: AppAssets.feedColor)!
return image.maskWithColor(color: AppAssets.feedColor.cgColor)!
}()
static var masterFolderColor: UIColor = {
@ -51,7 +51,7 @@ struct AppAssets {
static var masterFolderImage: RSImage = {
let image = RSImage(named: "folderImage")!
return image.maskWithColor(color: AppAssets.masterFolderColor)!
return image.maskWithColor(color: AppAssets.masterFolderColor.cgColor)!
}()
static var selectionBackgroundColor: UIColor = {
@ -64,7 +64,7 @@ struct AppAssets {
static var smartFeedImage: RSImage = {
let image = RSImage(named: "smartFeedImage")!
return image.maskWithColor(color: AppAssets.smartFeedColor)!
return image.maskWithColor(color: AppAssets.smartFeedColor.cgColor)!
}()
static var starColor: UIColor = {
@ -81,7 +81,7 @@ struct AppAssets {
static var timelineStarImage: RSImage = {
let image = RSImage(named: "starClosedImage")!
return image.maskWithColor(color: AppAssets.starColor)!
return image.maskWithColor(color: AppAssets.starColor.cgColor)!
}()
static var timelineTextPrimaryColor: UIColor = {

View File

@ -1,38 +0,0 @@
//
// UIImage-Extensions.swift
// NetNewsWire
//
// Created by Maurice Parker on 4/18/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
extension UIImage {
func maskWithColor(color: UIColor) -> UIImage? {
let maskImage = cgImage!
let width = size.width
let height = size.height
let bounds = CGRect(x: 0, y: 0, width: width, height: height)
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
let context = CGContext(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)!
context.clip(to: bounds, mask: maskImage)
context.setFillColor(color.cgColor)
context.fill(bounds)
if let cgImage = context.makeImage() {
let coloredImage = UIImage(cgImage: cgImage)
return coloredImage
} else {
return nil
}
}
}

@ -1 +1 @@
Subproject commit 44f046dca9901e50bc7132fb8d296d38b69673d9
Subproject commit b65da2c5286c6bc342064c738dd351750ea6fe12