mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Create and use TimelineFeedIconsDisplay.
This commit is contained in:
1 parent
9655f1660c
commit
0611366ad2
5 files changed
+106
-6
No files matched your search
@@ -24,6 +24,7 @@ enum AppDefaults {
|
||||
static let articleContentJavascriptEnabled = "articleContentJavascriptEnabled"
|
||||
static let unreadCountDisplay = "unreadCountDisplay"
|
||||
static let timelineThumbnailsDisplay = "timelineThumbnailsDisplay"
|
||||
static let timelineFeedIconsDisplay = "timelineFeedIconsDisplay"
|
||||
}
|
||||
|
||||
/// Registered by both platforms. Each platform’s registerDefaults adds its own.
|
||||
@@ -33,7 +34,8 @@ enum AppDefaults {
|
||||
Key.timelineGroupByFeed: false,
|
||||
Key.currentThemeName: defaultThemeName,
|
||||
Key.articleContentJavascriptEnabled: true,
|
||||
Key.timelineThumbnailsDisplay: TimelineThumbnailsDisplay.small.rawValue
|
||||
Key.timelineThumbnailsDisplay: TimelineThumbnailsDisplay.small.rawValue,
|
||||
Key.timelineFeedIconsDisplay: TimelineFeedIconsDisplay.automatic.rawValue
|
||||
]
|
||||
}
|
||||
|
||||
@@ -125,6 +127,16 @@ enum AppDefaults {
|
||||
NotificationCenter.default.post(name: .timelineThumbnailsDisplayDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
static var timelineFeedIconsDisplay: TimelineFeedIconsDisplay {
|
||||
get {
|
||||
TimelineFeedIconsDisplay(rawValue: UserDefaults.standard.integer(forKey: Key.timelineFeedIconsDisplay)) ?? .automatic
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.timelineFeedIconsDisplay)
|
||||
NotificationCenter.default.post(name: .timelineFeedIconsDisplayDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
@@ -184,6 +184,9 @@
|
||||
"Already added" : {
|
||||
"comment" : "Feed finder"
|
||||
},
|
||||
"Always" : {
|
||||
"comment" : "Always"
|
||||
},
|
||||
"Always Use Reader View" : {
|
||||
"comment" : "Always Use Reader View"
|
||||
},
|
||||
@@ -612,6 +615,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"Feed Icons" : {
|
||||
"comment" : "Feed Icons"
|
||||
},
|
||||
"Feed Inspector" : {
|
||||
"comment" : "Feed Inspector window title"
|
||||
},
|
||||
@@ -924,6 +930,9 @@
|
||||
"Network error. Try again later." : {
|
||||
"comment" : "Credentials Error"
|
||||
},
|
||||
"Never" : {
|
||||
"comment" : "Never"
|
||||
},
|
||||
"New Article Notifications" : {
|
||||
"comment" : "New Article Notifications"
|
||||
},
|
||||
@@ -1408,8 +1417,8 @@
|
||||
"This will delete:" : {
|
||||
"comment" : "Clean up confirmation prefix"
|
||||
},
|
||||
"Thumbnails" : {
|
||||
"comment" : "Thumbnails"
|
||||
"Thumbnail Size" : {
|
||||
"comment" : "Thumbnail Size"
|
||||
},
|
||||
"Timeline" : {
|
||||
"comment" : "Timeline"
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// TimelineFeedIconsDisplay.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Brent Simmons on 10/26/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Notification.Name {
|
||||
static let timelineFeedIconsDisplayDidChange = Notification.Name("TimelineFeedIconsDisplayDidChangeNotification")
|
||||
}
|
||||
|
||||
/// When the timeline shows feed icons.
|
||||
enum TimelineFeedIconsDisplay: Int, CaseIterable, CustomStringConvertible {
|
||||
case automatic = 0 // Folders, smart feeds, and single feeds whose articles have author avatars
|
||||
case always = 1
|
||||
case never = 2
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .automatic:
|
||||
NSLocalizedString("Automatic", comment: "Automatic")
|
||||
case .always:
|
||||
NSLocalizedString("Always", comment: "Always")
|
||||
case .never:
|
||||
NSLocalizedString("Never", comment: "Never")
|
||||
}
|
||||
}
|
||||
|
||||
/// Explains a choice whose description doesn’t say what it does.
|
||||
var subtitle: String? {
|
||||
switch self {
|
||||
case .automatic:
|
||||
NSLocalizedString("Folders, smart feeds, and authors with avatars", comment: "Feed Icons setting: explains when Automatic shows feed icons")
|
||||
case .always, .never:
|
||||
nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,6 +400,7 @@ struct SidebarItemNode: Hashable, Sendable {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(themeDownloadDidFail(_:)), name: .didFailToImportThemeWithError, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(updateNavigationBarSubtitles(_:)), name: .progressInfoDidChange, object: CombinedRefreshProgress.shared)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFeedIconsDisplayDidChange(_:)), name: .timelineFeedIconsDisplayDidChange, object: nil)
|
||||
|
||||
NotificationCenter.default.addObserver(forName: UserDefaults.didChangeNotification, object: nil, queue: .main) { [weak self] _ in
|
||||
Task { @MainActor in
|
||||
@@ -711,6 +712,11 @@ struct SidebarItemNode: Hashable, Sendable {
|
||||
updateNavigationBarSubtitles(nil)
|
||||
}
|
||||
|
||||
@objc func handleTimelineFeedIconsDisplayDidChange(_ notification: Notification) {
|
||||
updateShowNamesAndIcons()
|
||||
mainTimelineViewController?.queueReloadAvailableCells()
|
||||
}
|
||||
|
||||
/// Updates navigation bar subtitles in response to feed selection, unread count changes,
|
||||
/// `progressInfoDidChange` notifications, and a timed refresh every
|
||||
/// 60s.
|
||||
@@ -2141,6 +2147,17 @@ private extension SceneCoordinator {
|
||||
showFeedNames = .feed
|
||||
}
|
||||
|
||||
switch AppDefaults.timelineFeedIconsDisplay {
|
||||
case .always:
|
||||
self.showIcons = true
|
||||
return
|
||||
case .never:
|
||||
self.showIcons = false
|
||||
return
|
||||
case .automatic:
|
||||
break
|
||||
}
|
||||
|
||||
if showFeedNames == .feed {
|
||||
self.showIcons = true
|
||||
return
|
||||
|
||||
@@ -21,6 +21,7 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController {
|
||||
}
|
||||
|
||||
private enum OptionsRow: Int, CaseIterable {
|
||||
case feedIcons
|
||||
case thumbnails
|
||||
}
|
||||
|
||||
@@ -80,6 +81,7 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFeedIconsDisplayDidChange(_:)), name: .timelineFeedIconsDisplayDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineThumbnailsDisplayDidChange(_:)), name: .timelineThumbnailsDisplayDidChange, object: nil)
|
||||
|
||||
configureCollectionView()
|
||||
@@ -128,7 +130,7 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController {
|
||||
cell.sliderConfiguration = .numberOfLines
|
||||
return cell
|
||||
case .options:
|
||||
let optionsRow = OptionsRow(rawValue: indexPath.item) ?? .thumbnails
|
||||
let optionsRow = OptionsRow(rawValue: indexPath.item) ?? .feedIcons
|
||||
return collectionView.dequeueConfiguredReusableCell(using: optionsCellRegistration, for: indexPath, item: optionsRow)
|
||||
case .noIconPreview:
|
||||
return previewCell(showIcon: false, indexPath: indexPath)
|
||||
@@ -189,6 +191,10 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController {
|
||||
collectionView.reloadSections([Section.noIconPreview.rawValue, Section.iconPreview.rawValue])
|
||||
}
|
||||
|
||||
@objc func handleTimelineFeedIconsDisplayDidChange(_ notification: Notification) {
|
||||
reconfigureOptionsRows()
|
||||
}
|
||||
|
||||
@objc func handleTimelineThumbnailsDisplayDidChange(_ notification: Notification) {
|
||||
reconfigureOptionsRows()
|
||||
}
|
||||
@@ -213,10 +219,16 @@ private extension TimelineCustomizerCollectionViewController {
|
||||
}
|
||||
|
||||
static private func configureOptionsCell(_ cell: UICollectionViewListCell, optionsRow: OptionsRow) {
|
||||
var content = cell.defaultContentConfiguration()
|
||||
// The pop-up menu accessory shows only a chevron, so the value cell’s secondary text shows the current choice.
|
||||
var content = UIListContentConfiguration.valueCell()
|
||||
switch optionsRow {
|
||||
case .feedIcons:
|
||||
content.text = NSLocalizedString("Feed Icons", comment: "Feed Icons")
|
||||
content.secondaryText = AppDefaults.timelineFeedIconsDisplay.description
|
||||
cell.accessories = [.popUpMenu(timelineFeedIconsDisplayMenu())]
|
||||
case .thumbnails:
|
||||
content.text = NSLocalizedString("Thumbnails", comment: "Thumbnails")
|
||||
content.text = NSLocalizedString("Thumbnail Size", comment: "Thumbnail Size")
|
||||
content.secondaryText = AppDefaults.timelineThumbnailsDisplay.description
|
||||
cell.accessories = [.popUpMenu(timelineThumbnailsDisplayMenu())]
|
||||
}
|
||||
cell.contentConfiguration = content
|
||||
@@ -230,6 +242,16 @@ private extension TimelineCustomizerCollectionViewController {
|
||||
}
|
||||
}
|
||||
|
||||
static func timelineFeedIconsDisplayMenu() -> UIMenu {
|
||||
let currentFeedIconsDisplay = AppDefaults.timelineFeedIconsDisplay
|
||||
let actions = TimelineFeedIconsDisplay.allCases.map { feedIconsDisplay in
|
||||
UIAction(title: String(describing: feedIconsDisplay), subtitle: feedIconsDisplay.subtitle, state: feedIconsDisplay == currentFeedIconsDisplay ? .on : .off) { _ in
|
||||
AppDefaults.timelineFeedIconsDisplay = feedIconsDisplay
|
||||
}
|
||||
}
|
||||
return UIMenu(options: .singleSelection, children: actions)
|
||||
}
|
||||
|
||||
static func timelineThumbnailsDisplayMenu() -> UIMenu {
|
||||
let currentThumbnailsDisplay = AppDefaults.timelineThumbnailsDisplay
|
||||
let actions = TimelineThumbnailsDisplay.allCases.map { thumbnailsDisplay in
|
||||
|
||||
Reference in new issue
Block a user