Create shared AppAsset and start using it.

This commit is contained in:
Brent Simmons
2025-01-26 21:38:40 -08:00
parent 1bfd0ee12c
commit 69ae436ea4
16 changed files with 224 additions and 145 deletions

View File

@@ -12,43 +12,43 @@ import Account
struct AppAssets {
static var accountBazQux: RSImage! = {
return RSImage(named: "accountBazQux")
}()
// static var accountBazQux: RSImage! = {
// return RSImage(named: "accountBazQux")
// }()
static var accountCloudKit: RSImage! = {
return RSImage(named: "accountCloudKit")
}()
// static var accountCloudKit: RSImage! = {
// return RSImage(named: "accountCloudKit")
// }()
//
// static var accountFeedbin: RSImage! = {
// return RSImage(named: "accountFeedbin")
// }()
//
// static var accountFeedly: RSImage! = {
// return RSImage(named: "accountFeedly")
// }()
//
// static var accountFreshRSS: RSImage! = {
// return RSImage(named: "accountFreshRSS")
// }()
//
// static var accountInoreader: RSImage! = {
// return RSImage(named: "accountInoreader")
// }()
//
// static var accountLocal: RSImage! = {
// return RSImage(named: "accountLocal")
// }()
//
// static var accountNewsBlur: RSImage! = {
// return RSImage(named: "accountNewsBlur")
// }()
//
// static var accountTheOldReader: RSImage! = {
// return RSImage(named: "accountTheOldReader")
// }()
static var accountFeedbin: RSImage! = {
return RSImage(named: "accountFeedbin")
}()
static var accountFeedly: RSImage! = {
return RSImage(named: "accountFeedly")
}()
static var accountFreshRSS: RSImage! = {
return RSImage(named: "accountFreshRSS")
}()
static var accountInoreader: RSImage! = {
return RSImage(named: "accountInoreader")
}()
static var accountLocal: RSImage! = {
return RSImage(named: "accountLocal")
}()
static var accountNewsBlur: RSImage! = {
return RSImage(named: "accountNewsBlur")
}()
static var accountTheOldReader: RSImage! = {
return RSImage(named: "accountTheOldReader")
}()
static let nnwFeedIcon = RSImage(named: "nnwFeedIcon")!
// static let nnwFeedIcon = RSImage(named: "nnwFeedIcon")!
@available(macOS 11.0, *)
static var addNewSidebarItemImage: RSImage = {
@@ -259,27 +259,27 @@ struct AppAssets {
return NSColor(named: NSColor.Name("StarColor"))!
}()
static func image(for accountType: AccountType) -> NSImage? {
switch accountType {
case .onMyMac:
return AppAssets.accountLocal
case .cloudKit:
return AppAssets.accountCloudKit
case .bazQux:
return AppAssets.accountBazQux
case .feedbin:
return AppAssets.accountFeedbin
case .feedly:
return AppAssets.accountFeedly
case .freshRSS:
return AppAssets.accountFreshRSS
case .inoreader:
return AppAssets.accountInoreader
case .newsBlur:
return AppAssets.accountNewsBlur
case .theOldReader:
return AppAssets.accountTheOldReader
}
}
// static func image(for accountType: AccountType) -> NSImage? {
// switch accountType {
// case .onMyMac:
// return AppAssets.accountLocal
// case .cloudKit:
// return AppAssets.accountCloudKit
// case .bazQux:
// return AppAsset.accountBazQuxImage
// case .feedbin:
// return AppAssets.accountFeedbin
// case .feedly:
// return AppAssets.accountFeedly
// case .freshRSS:
// return AppAssets.accountFreshRSS
// case .inoreader:
// return AppAssets.accountInoreader
// case .newsBlur:
// return AppAssets.accountNewsBlur
// case .theOldReader:
// return AppAssets.accountTheOldReader
// }
// }
}

View File

@@ -39,23 +39,23 @@ final class AccountsReaderAPIWindowController: NSWindowController {
if let accountType = accountType {
switch accountType {
case .freshRSS:
titleImageView.image = AppAssets.accountFreshRSS
titleImageView.image = AppAsset.image(accountType: .freshRSS)
titleLabel.stringValue = NSLocalizedString("Sign in to your FreshRSS account.", comment: "FreshRSS")
noAccountTextField.stringValue = NSLocalizedString("Dont have a FreshRSS instance?", comment: "No FreshRSS")
createAccountButton.title = NSLocalizedString("Find out more", comment: "No FreshRSS Button")
apiURLTextField.placeholderString = NSLocalizedString("fresh.rss.net/api/greader.php", comment: "FreshRSS API Helper")
case .inoreader:
titleImageView.image = AppAssets.accountInoreader
titleImageView.image = AppAsset.image(accountType: .inoreader)
titleLabel.stringValue = NSLocalizedString("Sign in to your InoReader account.", comment: "InoReader")
gridView.row(at: 2).isHidden = true
noAccountTextField.stringValue = NSLocalizedString("Dont have an InoReader account?", comment: "No InoReader")
case .bazQux:
titleImageView.image = AppAssets.accountBazQux
titleImageView.image = AppAsset.image(accountType: .bazQux)
titleLabel.stringValue = NSLocalizedString("Sign in to your BazQux account.", comment: "BazQux")
gridView.row(at: 2).isHidden = true
noAccountTextField.stringValue = NSLocalizedString("Dont have a BazQux account?", comment: "No BazQux")
case .theOldReader:
titleImageView.image = AppAssets.accountTheOldReader
titleImageView.image = AppAsset.image(accountType: .theOldReader)
titleLabel.stringValue = NSLocalizedString("Sign in to your The Old Reader account.", comment: "The Old Reader")
gridView.row(at: 2).isHidden = true
noAccountTextField.stringValue = NSLocalizedString("Dont have a The Old Reader account?", comment: "No OldReader")
@@ -175,9 +175,7 @@ final class AccountsReaderAPIWindowController: NSWindowController {
case .failure:
self.errorMessageLabel.stringValue = NSLocalizedString("Network error. Try again later.", comment: "Credentials Error")
}
}
}
@IBAction func createAccountWithProvider(_ sender: Any) {

View File

@@ -421,6 +421,7 @@
84C1ECED2CDFE49100C7456A /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
AppAsset.swift,
Defaults/AppDefaults.swift,
Defaults/ArticleTextSize.swift,
Defaults/FontSize.swift,

80
Shared/AppAsset.swift Normal file
View File

@@ -0,0 +1,80 @@
//
// AppAsset.swift
// NetNewsWire
//
// Created by Brent Simmons on 1/26/25.
// Copyright © 2025 Ranchero Software. All rights reserved.
//
#if os(macOS)
import AppKit
#elseif os(iOS)
import UIKit
#endif
import RSCore
import Account
struct AppAsset {
// MARK: - Account images
static func image(accountType: AccountType) -> RSImage? {
switch accountType {
case .onMyMac:
AppAsset.accountLocalImage
case .cloudKit:
AppAsset.accountCloudKitImage
case .feedbin:
AppAsset.accountFeedbinImage
case .feedly:
AppAsset.accountFeedlyImage
case .freshRSS:
AppAsset.accountFreshRSSImage
case .newsBlur:
AppAsset.accountNewsBlurImage
case .inoreader:
AppAsset.accountInoreaderImage
case .bazQux:
AppAsset.accountBazQuxImage
case .theOldReader:
AppAsset.accountTheOldReaderImage
}
}
// MARK: - Misc.
static let nnwFeedIcon = RSImage(named: "nnwFeedIcon")!
}
private extension AppAsset {
static var accountBazQuxImage = RSImage(named: "accountBazQux")!
static var accountCloudKitImage = RSImage(named: "accountCloudKit")!
static var accountFeedbinImage = RSImage(named: "accountFeedbin")!
static var accountFeedlyImage = RSImage(named: "accountFeedly")!
static var accountFreshRSSImage = RSImage(named: "accountFreshRSS")!
static var accountInoreaderImage = RSImage(named: "accountInoreader")!
static var accountNewsBlurImage = RSImage(named: "accountNewsBlur")!
static var accountTheOldReaderImage = RSImage(named: "accountTheOldReader")!
#if os(macOS)
static var accountLocalMacImage = RSImage(named: "accountLocal")!
#elseif os(iOS)
static var accountLocalPadImage = UIImage(named: "accountLocalPad")!
static var accountLocalPhoneImage = UIImage(named: "accountLocalPhone")!
#endif
static var accountLocalImage: RSImage = {
#if os(macOS)
accountLocalMacImage
#elseif os(iOS)
if UIDevice.current.userInterfaceIdiom == .pad {
return accountLocalPadImage
} else {
return accountLocalPhoneImage
}
#endif
}()
}

View File

@@ -34,5 +34,5 @@ extension IconImage {
return nil
}()
static let nnwFeedIcon = IconImage(AppAssets.nnwFeedIcon)
static let nnwFeedIcon = IconImage(AppAsset.nnwFeedIcon)
}

View File

@@ -18,7 +18,7 @@ protocol SmallIconProvider {
extension Account: SmallIconProvider {
var smallIcon: IconImage? {
if let image = AppAssets.image(for: type) {
if let image = AppAsset.image(accountType: type) {
return IconImage(image)
}
return nil

View File

@@ -57,7 +57,7 @@ final class CloudKitAccountViewController: UITableViewController {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: .cloudKit)
headerView.imageView.image = AppAsset.image(accountType: .cloudKit)
return headerView
} else {
return super.tableView(tableView, viewForHeaderInSection: section)

View File

@@ -59,7 +59,7 @@ final class FeedbinAccountViewController: UITableViewController {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: .feedbin)
headerView.imageView.image = AppAsset.image(accountType: .feedbin)
return headerView
} else {
return super.tableView(tableView, viewForHeaderInSection: section)

View File

@@ -46,7 +46,7 @@ final class LocalAccountViewController: UITableViewController {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: .onMyMac)
headerView.imageView.image = AppAsset.image(accountType: .onMyMac)
return headerView
} else {
return super.tableView(tableView, viewForHeaderInSection: section)

View File

@@ -58,7 +58,7 @@ final class NewsBlurAccountViewController: UITableViewController {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: .newsBlur)
headerView.imageView.image = AppAsset.image(accountType: .newsBlur)
return headerView
} else {
return super.tableView(tableView, viewForHeaderInSection: section)

View File

@@ -210,13 +210,13 @@ final class ReaderAPIAccountViewController: UITableViewController {
if let accountType = accountType {
switch accountType {
case .bazQux:
return AppAssets.accountBazQuxImage
return AppAsset.image(accountType: .bazQux)
case .inoreader:
return AppAssets.accountInoreaderImage
return AppAsset.image(accountType: .inoreader)
case .theOldReader:
return AppAssets.accountTheOldReaderImage
return AppAsset.image(accountType: .theOldReader)
case .freshRSS:
return AppAssets.accountFreshRSSImage
return AppAsset.image(accountType: .freshRSS)
default:
return nil
}

View File

@@ -11,47 +11,47 @@ import Account
struct AppAssets {
static var accountBazQuxImage: UIImage = {
return UIImage(named: "accountBazQux")!
}()
// static var accountBazQuxImage: UIImage = {
// return UIImage(named: "accountBazQux")!
// }()
static var accountCloudKitImage: UIImage = {
return UIImage(named: "accountCloudKit")!
}()
// static var accountCloudKitImage: UIImage = {
// return UIImage(named: "accountCloudKit")!
// }()
//
// static var accountFeedbinImage: UIImage = {
// return UIImage(named: "accountFeedbin")!
// }()
//
// static var accountFeedlyImage: UIImage = {
// return UIImage(named: "accountFeedly")!
// }()
//
// static var accountFreshRSSImage: UIImage = {
// return UIImage(named: "accountFreshRSS")!
// }()
//
// static var accountInoreaderImage: UIImage = {
// return UIImage(named: "accountInoreader")!
// }()
//
// static var accountLocalPadImage: UIImage = {
// return UIImage(named: "accountLocalPad")!
// }()
//
// static var accountLocalPhoneImage: UIImage = {
// return UIImage(named: "accountLocalPhone")!
// }()
//
// static var accountNewsBlurImage: UIImage = {
// return UIImage(named: "accountNewsBlur")!
// }()
//
// static var accountTheOldReaderImage: UIImage = {
// return UIImage(named: "accountTheOldReader")!
// }()
static var accountFeedbinImage: UIImage = {
return UIImage(named: "accountFeedbin")!
}()
static var accountFeedlyImage: UIImage = {
return UIImage(named: "accountFeedly")!
}()
static var accountFreshRSSImage: UIImage = {
return UIImage(named: "accountFreshRSS")!
}()
static var accountInoreaderImage: UIImage = {
return UIImage(named: "accountInoreader")!
}()
static var accountLocalPadImage: UIImage = {
return UIImage(named: "accountLocalPad")!
}()
static var accountLocalPhoneImage: UIImage = {
return UIImage(named: "accountLocalPhone")!
}()
static var accountNewsBlurImage: UIImage = {
return UIImage(named: "accountNewsBlur")!
}()
static var accountTheOldReaderImage: UIImage = {
return UIImage(named: "accountTheOldReader")!
}()
static let nnwFeedIcon = RSImage(named: "nnwFeedIcon")!
// static let nnwFeedIcon = RSImage(named: "nnwFeedIcon")!
static var articleExtractorError: UIImage = {
return UIImage(named: "articleExtractorError")!
@@ -251,31 +251,31 @@ struct AppAssets {
return UIColor(named: "controlBackgroundColor")!
}()
static func image(for accountType: AccountType) -> UIImage? {
switch accountType {
case .onMyMac:
if UIDevice.current.userInterfaceIdiom == .pad {
return AppAssets.accountLocalPadImage
} else {
return AppAssets.accountLocalPhoneImage
}
case .cloudKit:
return AppAssets.accountCloudKitImage
case .feedbin:
return AppAssets.accountFeedbinImage
case .feedly:
return AppAssets.accountFeedlyImage
case .freshRSS:
return AppAssets.accountFreshRSSImage
case .newsBlur:
return AppAssets.accountNewsBlurImage
case .inoreader:
return AppAssets.accountInoreaderImage
case .bazQux:
return AppAssets.accountBazQuxImage
case .theOldReader:
return AppAssets.accountTheOldReaderImage
}
}
// static func image(for accountType: AccountType) -> UIImage? {
// switch accountType {
// case .onMyMac:
// if UIDevice.current.userInterfaceIdiom == .pad {
// return AppAssets.accountLocalPadImage
// } else {
// return AppAssets.accountLocalPhoneImage
// }
// case .cloudKit:
// return AppAssets.accountCloudKitImage
// case .feedbin:
// return AppAssets.accountFeedbinImage
// case .feedly:
// return AppAssets.accountFeedlyImage
// case .freshRSS:
// return AppAssets.accountFreshRSSImage
// case .newsBlur:
// return AppAssets.accountNewsBlurImage
// case .inoreader:
// return AppAssets.accountInoreaderImage
// case .bazQux:
// return AppAsset.accountBazQuxImage
// case .theOldReader:
// return AppAssets.accountTheOldReaderImage
// }
// }
}

View File

@@ -169,7 +169,7 @@ extension AccountInspectorViewController {
if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: account.type)
headerView.imageView.image = AppAsset.image(accountType: account.type)
return headerView
} else {
return super.tableView(tableView, viewForHeaderInSection: section)

View File

@@ -127,17 +127,17 @@ final class AddAccountViewController: UITableViewController, AddAccountDismissDe
switch indexPath.section {
case AddAccountSections.local.rawValue:
cell.comboNameLabel?.text = AddAccountSections.local.sectionContent[indexPath.row].localizedAccountName()
cell.comboImage?.image = AppAssets.image(for: .onMyMac)
cell.comboImage?.image = AppAsset.image(accountType: .onMyMac)
case AddAccountSections.icloud.rawValue:
cell.comboNameLabel?.text = AddAccountSections.icloud.sectionContent[indexPath.row].localizedAccountName()
cell.comboImage?.image = AppAssets.image(for: AddAccountSections.icloud.sectionContent[indexPath.row])
cell.comboImage?.image = AppAsset.image(accountType: AddAccountSections.icloud.sectionContent[indexPath.row])
if AppDefaults.isDeveloperBuild || AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) {
cell.isUserInteractionEnabled = false
cell.comboNameLabel?.isEnabled = false
}
case AddAccountSections.web.rawValue:
cell.comboNameLabel?.text = AddAccountSections.web.sectionContent[indexPath.row].localizedAccountName()
cell.comboImage?.image = AppAssets.image(for: AddAccountSections.web.sectionContent[indexPath.row])
cell.comboImage?.image = AppAsset.image(accountType: AddAccountSections.web.sectionContent[indexPath.row])
let type = AddAccountSections.web.sectionContent[indexPath.row]
if (type == .feedly || type == .inoreader) && AppDefaults.isDeveloperBuild {
cell.isUserInteractionEnabled = false
@@ -145,7 +145,7 @@ final class AddAccountViewController: UITableViewController, AddAccountDismissDe
}
case AddAccountSections.selfhosted.rawValue:
cell.comboNameLabel?.text = AddAccountSections.selfhosted.sectionContent[indexPath.row].localizedAccountName()
cell.comboImage?.image = AppAssets.image(for: AddAccountSections.selfhosted.sectionContent[indexPath.row])
cell.comboImage?.image = AppAsset.image(accountType: AddAccountSections.selfhosted.sectionContent[indexPath.row])
default:
return cell

View File

@@ -121,7 +121,7 @@ final class SettingsViewController: UITableViewController {
let acctCell = tableView.dequeueReusableCell(withIdentifier: "SettingsComboTableViewCell", for: indexPath) as! SettingsComboTableViewCell
acctCell.applyThemeProperties()
let account = sortedAccounts[indexPath.row]
acctCell.comboImage?.image = AppAssets.image(for: account.type)
acctCell.comboImage?.image = AppAsset.image(accountType: account.type)
acctCell.comboNameLabel?.text = account.nameForDisplay
cell = acctCell
}

View File

@@ -46,7 +46,7 @@ final class ShareFolderPickerController: UITableViewController {
}()
if let account = container as? ExtensionAccount {
cell.icon.image = AppAssets.image(for: account.type)
cell.icon.image = AppAsset.image(accountType: account.type)
} else {
cell.icon.image = AppAssets.folderImage.image
}