diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 067abcde0..95bbd8e55 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -118,6 +118,7 @@ let appName = "NetNewsWire" AccountManager.shared.start() NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: AccountManager.shared) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(inspectableObjectsDidChange(_:)), name: .InspectableObjectsDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(importDownloadedTheme(_:)), name: .didEndDownloadingTheme, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(themeImportError(_:)), name: .didFailToImportThemeWithError, object: nil) @@ -372,6 +373,10 @@ let appName = "NetNewsWire" unreadCount = AccountManager.shared.unreadCount } + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + updateDockBadge() + } + @objc func feedSettingDidChange(_ note: Notification) { MainActor.assumeIsolated { guard let feed = note.object as? Feed, let key = note.userInfo?[Feed.SettingUserInfoKey] as? Feed.SettingKey else { @@ -558,8 +563,7 @@ let appName = "NetNewsWire" // MARK: - Dock Badge @objc func updateDockBadge() { Task { @MainActor in - let label = unreadCount > 0 ? "\(unreadCount)" : "" - NSApplication.shared.dockTile.badgeLabel = label + NSApplication.shared.dockTile.badgeLabel = AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) ?? "" } } diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 4fff3f21d..bd40b2600 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -111,6 +111,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .progressInfoDidChange, object: CombinedRefreshProgress.shared) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(articleThemeNamesDidChangeNotification(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil) @@ -198,6 +199,10 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations CoalescingQueue.standard.add(self, #selector(coalescedUpdateWindowTitle)) } + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + updateWindowTitle() + } + @objc func coalescedUpdateWindowTitle() { updateWindowTitle() } @@ -1657,6 +1662,10 @@ private extension MainWindowController { } func setSubtitle(_ count: Int) { + guard AppDefaults.shared.unreadCountDisplay == .count else { + window?.subtitle = "" + return + } let localizedLabel = NSLocalizedString("%d unread", comment: "Unread") let formattedLabel = NSString.localizedStringWithFormat(localizedLabel as NSString, count) window?.subtitle = formattedLabel as String diff --git a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift index 42aea739b..17a65c168 100644 --- a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift +++ b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift @@ -44,8 +44,7 @@ final class SidebarCell: NSTableCellView { set { if unreadCountView.unreadCount != newValue { unreadCountView.unreadCount = newValue - unreadCountView.isHidden = (newValue < 1) - needsLayout = true + updateUnreadCountView() } } } @@ -112,8 +111,15 @@ final class SidebarCell: NSTableCellView { layoutWith(layout) } + func updateUnreadCountView() { + unreadCountView.invalidateIntrinsicContentSize() + unreadCountView.needsDisplay = true + unreadCountView.isHidden = unreadCountView.unreadCountText == nil + needsLayout = true + } + override func accessibilityLabel() -> String? { - if unreadCount > 0 { + if unreadCount > 0 && AppDefaults.shared.unreadCountDisplay == .count { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessibility") return "\(name) \(unreadCount) \(unreadLabel)" } else { diff --git a/Mac/MainWindow/Sidebar/Cell/SidebarCellLayout.swift b/Mac/MainWindow/Sidebar/Cell/SidebarCellLayout.swift index 9dbf1e9c1..0b539b48b 100644 --- a/Mac/MainWindow/Sidebar/Cell/SidebarCellLayout.swift +++ b/Mac/MainWindow/Sidebar/Cell/SidebarCellLayout.swift @@ -36,7 +36,7 @@ import RSCore rTextField = rTextField.centeredVertically(in: bounds) let unreadCountSize = unreadCountView.intrinsicContentSize - let unreadCountIsHidden = unreadCountView.unreadCount < 1 + let unreadCountIsHidden = unreadCountView.unreadCountText == nil var rUnread = NSRect.zero if !unreadCountIsHidden { diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index b86ddc251..e9da14699 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -93,6 +93,7 @@ extension Notification.Name { NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .UserDidAddAccount, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .UserDidDeleteAccount, object: nil) @@ -226,6 +227,12 @@ extension Notification.Name { } } + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + applyToAvailableCells { cell, _ in + cell.updateUnreadCountView() + } + } + @objc func containerChildrenDidChange(_ note: Notification) { rebuildTreeAndRestoreSelection() } @@ -844,6 +851,7 @@ private extension SidebarViewController { cell.cellAppearance = SidebarCellAppearance(rowSizeStyle: outlineView.effectiveRowSizeStyle) cell.name = nameFor(node) configureUnreadCount(cell, node) + cell.updateUnreadCountView() // A reused cell may predate a display setting change configureFavicon(cell, node) cell.shouldShowImage = node.representedObject is SmallIconProvider } diff --git a/Mac/MainWindow/Sidebar/UnreadCountView.swift b/Mac/MainWindow/Sidebar/UnreadCountView.swift index 82b09e586..9e19f30b4 100644 --- a/Mac/MainWindow/Sidebar/UnreadCountView.swift +++ b/Mac/MainWindow/Sidebar/UnreadCountView.swift @@ -52,8 +52,13 @@ final class UnreadCountView: NSView { needsDisplay = true } } - var unreadCountString: String { - return unreadCount < 1 ? "" : "\(unreadCount.formatted())" + /// Text for the unread count, or nil when nothing should be drawn. + var unreadCountText: String? { + AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) + } + + private var showsDot: Bool { + AppDefaults.shared.unreadCountDisplay.showsDot(for: unreadCount) } var isSelected: Bool = false { @@ -83,8 +88,12 @@ final class UnreadCountView: NSView { override var intrinsicContentSize: NSSize { if !intrinsicContentSizeIsValid { var size = NSSize.zero - if unreadCount > 0 { - size = textSize() + if showsDot { + // Same height as a count, so the row lays out the same either way. + size.width = UnreadIndicatorView.unreadCircleDimension + Appearance.padding.left + Appearance.padding.right + size.height = textSize(Self.digitForHeight).height + Appearance.padding.top + Appearance.padding.bottom + } else if let unreadCountText { + size = textSize(unreadCountText) size.width += (Appearance.padding.left + Appearance.padding.right) size.height += (Appearance.padding.top + Appearance.padding.bottom) } @@ -102,27 +111,23 @@ final class UnreadCountView: NSView { intrinsicContentSizeIsValid = false } - private static var textSizeCache = [Int: NSSize]() + private static var textSizeCache = [String: NSSize]() - private func textSize() -> NSSize { - if unreadCount < 1 { - return NSSize.zero - } - - if let cachedSize = UnreadCountView.textSizeCache[unreadCount] { + private func textSize(_ text: String) -> NSSize { + if let cachedSize = UnreadCountView.textSizeCache[text] { return cachedSize } - var size = unreadCountString.size(withAttributes: textAttributes) + var size = text.size(withAttributes: textAttributes) size.height = ceil(size.height) size.width = ceil(size.width) - UnreadCountView.textSizeCache[unreadCount] = size + UnreadCountView.textSizeCache[text] = size return size } - private func textRect() -> NSRect { - let size = textSize() + private func textRect(_ text: String) -> NSRect { + let size = textSize(text) var r = NSRect.zero r.size = size r.origin.x = (bounds.maxX - Appearance.padding.right) - r.size.width @@ -130,13 +135,29 @@ final class UnreadCountView: NSView { return r } + private static let digitForHeight = "0" + + /// Drawn without the pill. + private func drawDot() { + let dimension = UnreadIndicatorView.unreadCircleDimension + let r = NSRect(x: (bounds.maxX - Appearance.padding.right) - dimension, y: bounds.midY - (dimension / 2.0), width: dimension, height: dimension) + let color = isSelected ? NSColor.white : NSColor.secondaryLabelColor + color.setFill() + NSBezierPath(ovalIn: r).fill() + } + override func draw(_ dirtyRect: NSRect) { + if showsDot { + drawDot() + return + } + let path = NSBezierPath(roundedRect: bounds, xRadius: Appearance.cornerRadius, yRadius: Appearance.cornerRadius) Appearance.backgroundColor.setFill() path.fill() - if unreadCount > 0 { - unreadCountString.draw(at: textRect().origin, withAttributes: textAttributes) + if let unreadCountText { + unreadCountText.draw(at: textRect(unreadCountText).origin, withAttributes: textAttributes) } } } diff --git a/Mac/Preferences/General/Base.lproj/GeneralPreferencesView.xib b/Mac/Preferences/General/Base.lproj/GeneralPreferencesView.xib index 0b5280046..696a2e177 100644 --- a/Mac/Preferences/General/Base.lproj/GeneralPreferencesView.xib +++ b/Mac/Preferences/General/Base.lproj/GeneralPreferencesView.xib @@ -11,18 +11,62 @@ + + + - + - + + + + + + + + + + + + + + + @@ -270,7 +314,6 @@ - @@ -289,6 +332,7 @@ + @@ -319,6 +363,21 @@ + + + + + + + + + + + + + + + @@ -331,6 +390,7 @@ + diff --git a/Mac/Preferences/General/GeneralPrefencesViewController.swift b/Mac/Preferences/General/GeneralPrefencesViewController.swift index 9e1ac9a27..8446f3b6a 100644 --- a/Mac/Preferences/General/GeneralPrefencesViewController.swift +++ b/Mac/Preferences/General/GeneralPrefencesViewController.swift @@ -17,6 +17,9 @@ final class GeneralPreferencesViewController: NSViewController { @IBOutlet var articleTextSizePopup: NSPopUpButton! @IBOutlet var articleThemePopup: NSPopUpButton! @IBOutlet var defaultBrowserPopup: NSPopUpButton! + @IBOutlet var showUnreadCountsButton: NSButton? + @IBOutlet var showUnreadCountDotButton: NSButton? + @IBOutlet var hideUnreadCountsButton: NSButton? convenience init() { self.init(nibName: "GeneralPreferencesView", bundle: nil) @@ -49,6 +52,10 @@ final class GeneralPreferencesViewController: NSViewController { updateArticleThemePopup() } + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + updateUnreadCountDisplayButtons() + } + // MARK: - Actions @IBAction func showThemesFolder(_ sender: Any) { @@ -64,6 +71,13 @@ final class GeneralPreferencesViewController: NSViewController { updateArticleThemePopup() } + @IBAction func unreadCountDisplaySettingDidChange(_ sender: NSButton) { + guard let unreadCountDisplay = UnreadCountDisplay(rawValue: sender.tag) else { + return + } + AppDefaults.shared.unreadCountDisplay = unreadCountDisplay + } + @IBAction func browserPopUpDidChangeValue(_ sender: Any?) { guard let menuItem = defaultBrowserPopup.selectedItem else { return @@ -114,11 +128,20 @@ private extension GeneralPreferencesViewController { func commonInit() { NotificationCenter.default.addObserver(self, selector: #selector(applicationWillBecomeActive(_:)), name: NSApplication.willBecomeActiveNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(articleThemeNamesDidChangeNotification(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) } func updateUI() { updateArticleThemePopup() updateBrowserPopup() + updateUnreadCountDisplayButtons() + } + + func updateUnreadCountDisplayButtons() { + let selectedTag = AppDefaults.shared.unreadCountDisplay.rawValue + for case let button? in [showUnreadCountsButton, showUnreadCountDotButton, hideUnreadCountsButton] { + button.state = button.tag == selectedTag ? .on : .off + } } func updateArticleThemePopup() { diff --git a/Mac/Preferences/General/mul.lproj/GeneralPreferencesView.xcstrings b/Mac/Preferences/General/mul.lproj/GeneralPreferencesView.xcstrings index 4d0136eab..caaa490fe 100644 --- a/Mac/Preferences/General/mul.lproj/GeneralPreferencesView.xcstrings +++ b/Mac/Preferences/General/mul.lproj/GeneralPreferencesView.xcstrings @@ -403,6 +403,42 @@ } } }, + "uC1-cL-sHw.title" : { + "comment" : "Class = \"NSButtonCell\"; title = \"Show\"; ObjectID = \"uC1-cL-sHw\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Show" + } + } + } + }, + "uC2-cL-dSh.title" : { + "comment" : "Class = \"NSButtonCell\"; title = \"Show dot\"; ObjectID = \"uC2-cL-dSh\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Show dot" + } + } + } + }, + "uC3-cL-hDn.title" : { + "comment" : "Class = \"NSButtonCell\"; title = \"Hide\"; ObjectID = \"uC3-cL-hDn\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Hide" + } + } + } + }, "uvx-O8-HvU.title" : { "comment" : "Class = \"NSButtonCell\"; title = \"Open feeds in NetNewsWire\"; ObjectID = \"uvx-O8-HvU\";", "extractionState" : "extracted_with_value", @@ -421,6 +457,18 @@ } } }, + "wAn-gW-UJc.title" : { + "comment" : "Class = \"NSTextFieldCell\"; title = \"Unread Counts:\"; ObjectID = \"wAn-gW-UJc\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Unread Counts:" + } + } + } + }, "xQu-QV-91i.title" : { "comment" : "Class = \"NSTextFieldCell\"; title = \"Article Text Size:\"; ObjectID = \"xQu-QV-91i\";", "extractionState" : "extracted_with_value", @@ -459,4 +507,4 @@ } }, "version" : "1.2" -} +} \ No newline at end of file diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 73bfb787c..ce6b8cc53 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -429,6 +429,7 @@ 84D35E0E2DB9F32D004AA60E /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = { isa = PBXFileSystemSynchronizedBuildFileExceptionSet; membershipExceptions = ( + UnreadCountDisplay.swift, Widget/WidgetData.swift, Widget/WidgetDataDecoder.swift, Widget/WidgetDeepLinks.swift, diff --git a/Shared/AppDefaults+Shared.swift b/Shared/AppDefaults+Shared.swift new file mode 100644 index 000000000..e4823790d --- /dev/null +++ b/Shared/AppDefaults+Shared.swift @@ -0,0 +1,25 @@ +// +// AppDefaults+Shared.swift +// NetNewsWire +// +// Created by Brent Simmons on 10/6/26. +// + +import Foundation + +private extension AppDefaults.Key { + static let unreadCountDisplay = "unreadCountDisplay" +} + +extension AppDefaults { + + var unreadCountDisplay: UnreadCountDisplay { + get { + UnreadCountDisplay(rawValue: UserDefaults.standard.integer(forKey: Key.unreadCountDisplay)) ?? .count + } + set { + UserDefaults.standard.set(newValue.rawValue, forKey: Key.unreadCountDisplay) + NotificationCenter.default.post(name: .unreadCountDisplaySettingDidChange, object: self) + } + } +} diff --git a/Shared/Localizable.xcstrings b/Shared/Localizable.xcstrings index 6ce652623..fb0474fb5 100644 --- a/Shared/Localizable.xcstrings +++ b/Shared/Localizable.xcstrings @@ -531,7 +531,7 @@ "comment" : "Here" }, "Hide" : { - "comment" : "Hide password button" + "comment" : "Hide" }, "Hide Read Articles" : { "comment" : "Command" @@ -943,7 +943,10 @@ "comment" : "Share…" }, "Show" : { - "comment" : "Show password button" + "comment" : "Show" + }, + "Show dot" : { + "comment" : "Unread Counts setting: show a dot instead of the number of unread articles" }, "Show Feed Article" : { "comment" : "Show Feed Article" diff --git a/Shared/UnreadCountDisplay.swift b/Shared/UnreadCountDisplay.swift new file mode 100644 index 000000000..a77a6ad2b --- /dev/null +++ b/Shared/UnreadCountDisplay.swift @@ -0,0 +1,38 @@ +// +// UnreadCountDisplay.swift +// NetNewsWire +// +// Created by Brent Simmons on 10/6/26. +// + +import Foundation + +extension Notification.Name { + static let unreadCountDisplaySettingDidChange = Notification.Name("UnreadCountDisplaySettingDidChangeNotification") +} + +/// How unread counts are shown. +enum UnreadCountDisplay: Int, CaseIterable, Codable { + case count = 0 + case dot = 1 + case hidden = 2 + + /// Text to show for an unread count, or nil when nothing should appear. + func text(for unreadCount: Int) -> String? { + guard unreadCount > 0 else { + return nil + } + switch self { + case .count: + return unreadCount.formatted() + case .dot: + return "•" + case .hidden: + return nil + } + } + + func showsDot(for unreadCount: Int) -> Bool { + self == .dot && unreadCount > 0 + } +} diff --git a/Shared/Widget/WidgetData.swift b/Shared/Widget/WidgetData.swift index d2e8ac0e3..5599a9b40 100644 --- a/Shared/Widget/WidgetData.swift +++ b/Shared/Widget/WidgetData.swift @@ -17,6 +17,12 @@ struct WidgetData: Codable { let starredArticles: [LatestArticle] let todayArticles: [LatestArticle] let lastUpdateTime: Date + let unreadCountDisplay: UnreadCountDisplay? + + /// Data written before this setting existed has no value, which means `.count`. + var effectiveUnreadCountDisplay: UnreadCountDisplay { + unreadCountDisplay ?? .count + } } struct LatestArticle: Codable, Identifiable, Hashable { diff --git a/Shared/Widget/WidgetDataDecoder.swift b/Shared/Widget/WidgetDataDecoder.swift index 249d1123b..d4b198d74 100644 --- a/Shared/Widget/WidgetDataDecoder.swift +++ b/Shared/Widget/WidgetDataDecoder.swift @@ -18,7 +18,7 @@ struct WidgetDataDecoder { let decodedWidgetData = try JSONDecoder().decode(WidgetData.self, from: Data(contentsOf: dataURL!)) return decodedWidgetData } else { - return WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date()) + return WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date(), unreadCountDisplay: nil) } } @@ -29,7 +29,7 @@ struct WidgetDataDecoder { let decoded = try JSONDecoder().decode(WidgetData.self, from: data) return decoded } catch { - return WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date()) + return WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date(), unreadCountDisplay: nil) } } diff --git a/Shared/Widget/WidgetDataEncoder.swift b/Shared/Widget/WidgetDataEncoder.swift index 4ce6e1324..f48ae575d 100644 --- a/Shared/Widget/WidgetDataEncoder.swift +++ b/Shared/Widget/WidgetDataEncoder.swift @@ -44,6 +44,12 @@ import Account Self.logger.error("WidgetDataEncoder: unable to create folder for images") return nil } + + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) + } + + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + encode() } /// Fire-and-forget. Sets `isRunning` synchronously so the background-task wait loop @@ -96,6 +102,12 @@ import Account func reloadTimelines(newData: WidgetData, existingData: WidgetData?) { if let existingData = existingData { + if existingData.effectiveUnreadCountDisplay != newData.effectiveUnreadCountDisplay { + WidgetCenter.shared.reloadAllTimelines() + Self.logger.debug("WidgetDataEncoder: Reloading all widgets because unread count display changed") + return + } + var shouldRefreshSummary = false if existingData.unreadArticles != newData.unreadArticles { @@ -148,7 +160,8 @@ import Account unreadArticles: unreadArticles, starredArticles: starredArticles, todayArticles: todayArticles, - lastUpdateTime: Date.now) + lastUpdateTime: Date.now, + unreadCountDisplay: AppDefaults.shared.unreadCountDisplay) return latestData } diff --git a/Widget/TimelineProvider.swift b/Widget/TimelineProvider.swift index 97d9e66ff..d499aefb2 100644 --- a/Widget/TimelineProvider.swift +++ b/Widget/TimelineProvider.swift @@ -51,7 +51,7 @@ struct Provider: TimelineProvider { let widgetData = try WidgetDataDecoder.decodeWidgetData() entry = WidgetTimelineEntry(date: date, widgetData: widgetData) } catch { - entry = WidgetTimelineEntry(date: date, widgetData: WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date.now)) + entry = WidgetTimelineEntry(date: date, widgetData: WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date.now, unreadCountDisplay: nil)) } let fallback = Calendar.current.date(byAdding: .minute, value: 30, to: Date.now)! diff --git a/Widget/Widget Views/LockScreenSummaryWidget.swift b/Widget/Widget Views/LockScreenSummaryWidget.swift index 70519b713..829a6e886 100644 --- a/Widget/Widget Views/LockScreenSummaryWidget.swift +++ b/Widget/Widget Views/LockScreenSummaryWidget.swift @@ -19,7 +19,7 @@ struct LockScreenSummaryWidgetView: View { unreadImage Text("label.text.unread", comment: "Unread") Spacer() - Text(verbatim: entry.widgetData.totalUnreadCount.formatted()) + Text(verbatim: unreadCountText) .frame(maxWidth: .infinity, alignment: .trailing) } HStack(alignment: .center) { @@ -40,6 +40,15 @@ struct LockScreenSummaryWidgetView: View { .font(.subheadline) } + /// Shows 0 when counts are showing, so the row doesn’t look broken. + var unreadCountText: String { + let widgetData = entry.widgetData + guard widgetData.effectiveUnreadCountDisplay == .count else { + return widgetData.effectiveUnreadCountDisplay.text(for: widgetData.totalUnreadCount) ?? "" + } + return widgetData.totalUnreadCount.formatted() + } + var starredImage: some View { Image(systemName: "star.fill") .resizable() diff --git a/Widget/Widget Views/TodayWidget.swift b/Widget/Widget Views/TodayWidget.swift index 5e6d24559..cecb297bb 100644 --- a/Widget/Widget Views/TodayWidget.swift +++ b/Widget/Widget Views/TodayWidget.swift @@ -35,7 +35,7 @@ struct TodayWidgetView: View { Spacer() .layoutPriority(0) if entry.widgetData.totalTodayCount > 0 { - Text(verbatim: entry.widgetData.totalTodayUnreadCount > 0 ? "\(entry.widgetData.totalTodayCount.formatted()), \(entry.widgetData.totalTodayUnreadCount.formatted()) unread" : entry.widgetData.totalTodayCount.formatted()) + Text(verbatim: countText) .font(.caption2) .bold() .foregroundColor(.secondary) @@ -56,6 +56,15 @@ struct TodayWidgetView: View { } } + /// The unread part is omitted unless unread counts are set to show — “3, • unread” would say nothing. + var countText: String { + let widgetData = entry.widgetData + guard widgetData.totalTodayUnreadCount > 0, widgetData.effectiveUnreadCountDisplay == .count else { + return widgetData.totalTodayCount.formatted() + } + return "\(widgetData.totalTodayCount.formatted()), \(widgetData.totalTodayUnreadCount.formatted()) unread" + } + var todayImage: some View { Image(systemName: "sun.max.fill") .resizable() diff --git a/Widget/Widget Views/UnreadWidget.swift b/Widget/Widget Views/UnreadWidget.swift index 380f93883..8a4941818 100644 --- a/Widget/Widget Views/UnreadWidget.swift +++ b/Widget/Widget Views/UnreadWidget.swift @@ -33,8 +33,8 @@ struct UnreadWidgetView: View { .layoutPriority(1) Spacer() .layoutPriority(0) - if entry.widgetData.totalUnreadCount - maxCount() > 0 { - Text(verbatim: entry.widgetData.totalUnreadCount.formatted()) + if entry.widgetData.totalUnreadCount - maxCount() > 0, let unreadCountText = entry.widgetData.effectiveUnreadCountDisplay.text(for: entry.widgetData.totalUnreadCount) { + Text(verbatim: unreadCountText) .font(.caption2) .bold() .foregroundColor(.secondary) diff --git a/iOS/Account/CredentialsAccountView.swift b/iOS/Account/CredentialsAccountView.swift index 1f6dffe27..514259d8c 100644 --- a/iOS/Account/CredentialsAccountView.swift +++ b/iOS/Account/CredentialsAccountView.swift @@ -107,7 +107,7 @@ struct CredentialsAccountView: View { SecureField(Self.passwordPlaceholder, text: $password) .textContentType(.password) } - Button(isPasswordVisible ? NSLocalizedString("Hide", comment: "Hide password button") : NSLocalizedString("Show", comment: "Show password button")) { + Button(isPasswordVisible ? NSLocalizedString("Hide", comment: "Hide") : NSLocalizedString("Show", comment: "Show")) { isPasswordVisible.toggle() } .buttonStyle(.borderless) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 6268b1368..fa916f45b 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -55,6 +55,7 @@ import Images NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountRefreshDidFinish(_:)), name: .AccountRefreshDidFinish, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -134,7 +135,8 @@ import Images private func updateBadge() { assert(unreadCount == AccountManager.shared.unreadCount) - UNUserNotificationCenter.current().setBadgeCount(unreadCount) + let badgeCount = AppDefaults.shared.unreadCountDisplay == .count ? unreadCount : 0 + UNUserNotificationCenter.current().setBadgeCount(badgeCount) } // MARK: Notifications @@ -149,6 +151,10 @@ import Images AppDefaults.shared.lastRefresh = Date() } + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + updateBadge() + } + // MARK: - API func manualRefresh(errorHandler: @escaping @Sendable (Error) -> Void) { diff --git a/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift b/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift index 5dca59df8..7901b4923 100644 --- a/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift +++ b/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift @@ -28,7 +28,7 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView { override var accessibilityLabel: String? { get { - if unreadCount > 0 { + if unreadCount > 0 && AppDefaults.shared.unreadCountDisplay == .count { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessibility") return "\(headerTitle.text ?? "") \(unreadCount) \(unreadLabel) \(expandedStateMessage) " } else { @@ -54,10 +54,14 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView { set { _unreadCount = newValue updateUnreadCount() - unreadCountLabel.text = newValue.formatted() + unreadCountLabel.setUnreadCount(newValue) } } + private var unreadCountText: String? { + AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) + } + // Mutate via setDisclosure(isExpanded:animated:) — the supplementary provider // sets this on every dequeue and must not animate. private(set) var disclosureExpanded = true @@ -125,7 +129,7 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView { } func updateUnreadCount(animated: Bool = true) { - let alpha: CGFloat = (!disclosureExpanded && unreadCount > 0) ? 1 : 0 + let alpha: CGFloat = (!disclosureExpanded && unreadCountText != nil) ? 1 : 0 if animated { UIView.animate(withDuration: 0.3) { self.unreadCountLabel.alpha = alpha diff --git a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift index 921fac1bc..18982ecf6 100644 --- a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift +++ b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewCell.swift @@ -33,12 +33,9 @@ final class MainFeedCollectionViewCell: UICollectionViewCell { } set { _unreadCount = newValue - if newValue == 0 { - unreadCountLabel.isHidden = true - } else { - unreadCountLabel.isHidden = false - } - unreadCountLabel.text = newValue.formatted() + unreadCountLabel.isHidden = AppDefaults.shared.unreadCountDisplay.text(for: newValue) == nil + unreadCountLabel.setUnreadCount(newValue) + setNeedsUpdateConfiguration() } } @@ -60,7 +57,7 @@ final class MainFeedCollectionViewCell: UICollectionViewCell { override var accessibilityLabel: String? { get { let name = feedTitle.text ?? "" - if unreadCount > 0 { + if unreadCount > 0 && AppDefaults.shared.unreadCountDisplay == .count { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessibility") return "\(name) \(unreadCount) \(unreadLabel)" } else { diff --git a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift index 1bc966b32..d804db36b 100644 --- a/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift +++ b/iOS/MainFeed/Collection View Cells/MainFeedCollectionViewFolderCell.swift @@ -29,16 +29,20 @@ class MainFeedCollectionViewFolderCell: UICollectionViewCell { } set { _unreadCount = newValue - if newValue == 0 { - unreadCountLabel.isHidden = true - } else { - unreadCountLabel.isHidden = false + let unreadCountText = unreadCountText + unreadCountLabel.isHidden = unreadCountText == nil + if unreadCountText != nil { updateUnreadCountVisibility() } - unreadCountLabel.text = newValue.formatted() + unreadCountLabel.setUnreadCount(newValue) + setNeedsUpdateConfiguration() } } + private var unreadCountText: String? { + AppDefaults.shared.unreadCountDisplay.text(for: unreadCount) + } + var iconImage: IconImage? { didSet { faviconView.iconImage = iconImage @@ -76,7 +80,7 @@ class MainFeedCollectionViewFolderCell: UICollectionViewCell { } func updateUnreadCountVisibility(animated: Bool = true) { - let alpha: CGFloat = (!disclosureExpanded && unreadCount > 0) ? 1 : 0 + let alpha: CGFloat = (!disclosureExpanded && unreadCountText != nil) ? 1 : 0 if animated { UIView.animate { self.unreadCountLabel.alpha = alpha @@ -101,7 +105,7 @@ class MainFeedCollectionViewFolderCell: UICollectionViewCell { override var accessibilityLabel: String? { get { let name = folderTitle.text ?? "" - if unreadCount > 0 { + if unreadCount > 0 && AppDefaults.shared.unreadCountDisplay == .count { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessibility") return "\(name) \(unreadCount) \(unreadLabel) \(expandedStateMessage)" } else { diff --git a/iOS/MainFeed/Collection View Cells/UILabel+UnreadCount.swift b/iOS/MainFeed/Collection View Cells/UILabel+UnreadCount.swift new file mode 100644 index 000000000..9fc1b8566 --- /dev/null +++ b/iOS/MainFeed/Collection View Cells/UILabel+UnreadCount.swift @@ -0,0 +1,33 @@ +// +// UILabel+UnreadCount.swift +// NetNewsWire +// +// Created by Brent Simmons on 10/6/26. +// + +import UIKit + +extension UILabel { + + /// Shows `unreadCount` per the Unread Counts setting: the number, a dot, or nothing. + /// The dot is drawn in the label’s text color. + func setUnreadCount(_ unreadCount: Int) { + let unreadCountDisplay = AppDefaults.shared.unreadCountDisplay + if unreadCountDisplay.showsDot(for: unreadCount) { + attributedText = NSAttributedString(attachment: unreadDotAttachment()) + } else { + text = unreadCountDisplay.text(for: unreadCount) + } + } +} + +private extension UILabel { + + func unreadDotAttachment() -> NSTextAttachment { + let dimension = MainTimelineDefaultCellLayout.unreadCircleDimension + let image = Assets.Images.unreadCellIndicator.image.withRenderingMode(.alwaysTemplate) + let attachment = NSTextAttachment(image: image) + attachment.bounds = CGRect(x: 0, y: (font.capHeight - dimension) / 2, width: dimension, height: dimension) + return attachment + } +} diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 9480b8219..48e69d3f5 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -198,6 +198,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .htmlMetadataAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .feedSettingDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) registerForTraitChanges([UITraitPreferredContentSizeCategory.self], target: self, action: #selector(preferredContentSizeCategoryDidChange)) } @@ -913,6 +914,17 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab reconfigureItems(nodesToReconfigure) } + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + for account in AccountManager.shared.activeAccounts { + if let headerView = findHeaderViewForAccount(account) { + headerView.unreadCount = account.unreadCount + } + } + + // Only realized cells are reconfigured. Others pick up the setting when dequeued. + reconfigureItems(dataSource.snapshot().itemIdentifiers) + } + @objc func feedSettingDidChange(_ note: Notification) { guard let feed = note.object as? Feed, let key = note.userInfo?[Feed.SettingUserInfoKey] as? Feed.SettingKey else { return diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 02c9b280a..971d357ff 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -316,6 +316,10 @@ struct SidebarItemNode: Hashable, Sendable { } } + private var isTimelineUnreadCountSubtitleShown: Bool { + timelineFeed != nil && timelineUnreadCount > 0 && AppDefaults.shared.unreadCountDisplay == .count + } + private static let minimumTimelineWidth: CGFloat = 280 private static let maximumTimelineWidth: CGFloat = 440 @@ -395,6 +399,7 @@ struct SidebarItemNode: Hashable, Sendable { NotificationCenter.default.addObserver(self, selector: #selector(importDownloadedTheme(_:)), name: .didEndDownloadingTheme, object: nil) 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(forName: UserDefaults.didChangeNotification, object: nil, queue: .main) { [weak self] _ in Task { @MainActor in @@ -702,6 +707,10 @@ struct SidebarItemNode: Hashable, Sendable { } } + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + updateNavigationBarSubtitles(nil) + } + /// Updates navigation bar subtitles in response to feed selection, unread count changes, /// `progressInfoDidChange` notifications, and a timed refresh every /// 60s. @@ -713,7 +722,7 @@ struct SidebarItemNode: Hashable, Sendable { /// - When refreshed: Feeds will display "Updated <#relative_time#>" on both iPhone and iPad. /// /// `MainTimelineViewController` - /// - Where the unread count for the timeline is > 0, this is displayed on both iPhone and iPad. + /// - Where the unread count for the timeline is > 0 and the Unread Counts setting is Show, this is displayed on both iPhone and iPad. /// - If the timeline count is 0, the iPhone follows the same logic as `MainFeedViewController` /// - Specific to iPad, if the unread count is 0, the iPad will not display a subtitle. The refresh text /// will generally be visible in the sidebar and there’s no need to display it twice. @@ -737,7 +746,7 @@ struct SidebarItemNode: Hashable, Sendable { } // If unread count > 0, add unread string to timeline - if timelineFeed != nil, timelineUnreadCount > 0 { + if isTimelineUnreadCountSubtitleShown { let localizedUnreadCount = NSLocalizedString("%i Unread", comment: "14 Unread") let unreadCount = NSString.localizedStringWithFormat(localizedUnreadCount as NSString, timelineUnreadCount) as String self.mainTimelineViewController?.updateNavigationBarSubtitle(unreadCount) @@ -756,7 +765,7 @@ struct SidebarItemNode: Hashable, Sendable { } // If unread count > 0, add unread string to timeline - if timelineFeed != nil, timelineUnreadCount > 0 { + if isTimelineUnreadCountSubtitleShown { let localizedUnreadCount = NSLocalizedString("%i Unread", comment: "14 Unread") let refreshTextWithUnreadCount = NSString.localizedStringWithFormat(localizedUnreadCount as NSString, timelineUnreadCount) as String self.mainTimelineViewController?.updateNavigationBarSubtitle(refreshTextWithUnreadCount) @@ -774,7 +783,7 @@ struct SidebarItemNode: Hashable, Sendable { self.mainFeedCollectionViewController?.navigationItem.subtitle = "" } // If unread count > 0, add unread string to timeline - if timelineFeed != nil, timelineUnreadCount > 0 { + if isTimelineUnreadCountSubtitleShown { let localizedUnreadCount = NSLocalizedString("%i Unread", comment: "14 Unread") let refreshTextWithUnreadCount = NSString.localizedStringWithFormat(localizedUnreadCount as NSString, timelineUnreadCount) as String self.mainTimelineViewController?.updateNavigationBarSubtitle(refreshTextWithUnreadCount) diff --git a/iOS/Settings/ColorPaletteTableViewController.swift b/iOS/Settings/ColorPaletteTableViewController.swift deleted file mode 100644 index dfd2f5da7..000000000 --- a/iOS/Settings/ColorPaletteTableViewController.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// ColorPaletteTableViewController.swift -// NetNewsWire-iOS -// -// Created by Maurice Parker on 3/15/20. -// Copyright © 2020 Ranchero Software. All rights reserved. -// - -import UIKit - -final class ColorPaletteTableViewController: UITableViewController { - - // MARK: - Table view data source - - override func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return UserInterfaceColorPalette.allCases.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) - let rowColorPalette = UserInterfaceColorPalette.allCases[indexPath.row] - cell.textLabel?.text = String(describing: rowColorPalette) - if rowColorPalette == AppDefaults.userInterfaceColorPalette { - cell.accessoryType = .checkmark - } else { - cell.accessoryType = .none - } - return cell - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - if let colorPalette = UserInterfaceColorPalette(rawValue: indexPath.row) { - AppDefaults.userInterfaceColorPalette = colorPalette - } - navigationController?.popViewController(animated: true) - } - -} diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 6febf340f..d0feb4dee 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -428,7 +428,7 @@ - + @@ -441,24 +441,37 @@ - + + + + + + + + + + + + - - - - - + + - - + @@ -656,7 +669,7 @@ - + @@ -664,6 +677,7 @@ + @@ -805,45 +819,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index 35cc6bff7..95b4fb24a 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -73,13 +73,17 @@ final class SettingsViewController: UITableViewController { @IBOutlet var articleThemeDetailLabel: UILabel! @IBOutlet var confirmMarkAllAsReadSwitch: UISwitch! @IBOutlet var showFullscreenArticlesSwitch: UISwitch! - @IBOutlet var colorPaletteDetailLabel: UILabel! + @IBOutlet var colorPaletteCell: UITableViewCell? + @IBOutlet var unreadCountDisplayCell: UITableViewCell? @IBOutlet var openLinksInNetNewsWire: UISwitch! @IBOutlet var enableJavaScriptSwitch: UISwitch! var scrollToArticlesSection = false weak var presentingParentController: UIViewController? + private lazy var colorPalettePopUpButton = Self.makePopUpButton() + private lazy var unreadCountDisplayPopUpButton = Self.makePopUpButton() + override func viewDidLoad() { // This hack mostly works around a bug in static tables with dynamic type. See: https://spin.atomicobject.com/2018/10/15/dynamic-type-static-uitableview/ NotificationCenter.default.removeObserver(tableView!, name: UIContentSizeCategory.didChangeNotification, object: nil) @@ -88,12 +92,19 @@ final class SettingsViewController: UITableViewController { NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange), name: .UserDidAddAccount, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange), name: .UserDidDeleteAccount, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange), name: .DisplayNameDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUserInterfaceColorPaletteDidUpdate(_:)), name: .userInterfaceColorPaletteDidUpdate, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) tableView.register(UINib(nibName: "SettingsComboTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsComboTableViewCell") tableView.register(UINib(nibName: "SettingsTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsTableViewCell") tableView.rowHeight = UITableView.automaticDimension tableView.estimatedRowHeight = 44 + + addPopUpButton(colorPalettePopUpButton, to: colorPaletteCell) + addPopUpButton(unreadCountDisplayPopUpButton, to: unreadCountDisplayCell) + updateColorPalettePopUpButton() + updateUnreadCountDisplayPopUpButton() } override func viewWillAppear(_ animated: Bool) { @@ -137,8 +148,6 @@ final class SettingsViewController: UITableViewController { enableJavaScriptSwitch.isOn = false } - colorPaletteDetailLabel.text = String(describing: AppDefaults.userInterfaceColorPalette) - openLinksInNetNewsWire.isOn = !AppDefaults.shared.useSystemBrowser let buildLabel = NonIntrinsicLabel(frame: CGRect(x: 32.0, y: 0.0, width: 0.0, height: 0.0)) @@ -273,9 +282,6 @@ final class SettingsViewController: UITableViewController { default: break } - case .appearance: - let colorPalette = UIStoryboard.settings.instantiateController(ofType: ColorPaletteTableViewController.self) - self.navigationController?.pushViewController(colorPalette, animated: true) case .troubleshooting: let viewController: UIViewController? = { switch TroubleshootingRow(rawValue: indexPath.row) { @@ -426,6 +432,14 @@ final class SettingsViewController: UITableViewController { tableView.reloadData() } + @objc func handleUserInterfaceColorPaletteDidUpdate(_ notification: Notification) { + updateColorPalettePopUpButton() + } + + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + updateUnreadCountDisplayPopUpButton() + } + } // MARK: - OPML Document Picker @@ -453,6 +467,49 @@ extension SettingsViewController: UIDocumentPickerDelegate { private extension SettingsViewController { + static func makePopUpButton() -> UIButton { + var configuration = UIButton.Configuration.plain() + configuration.baseForegroundColor = .secondaryLabel + let button = UIButton(configuration: configuration) + button.showsMenuAsPrimaryAction = true + button.changesSelectionAsPrimaryAction = true + return button + } + + /// Auto Layout lets the button resize itself when choosing an item changes its title. + func addPopUpButton(_ button: UIButton, to cell: UITableViewCell?) { + guard let cell else { + return + } + button.translatesAutoresizingMaskIntoConstraints = false + button.setContentCompressionResistancePriority(.required, for: .horizontal) + cell.contentView.addSubview(button) + NSLayoutConstraint.activate([ + button.trailingAnchor.constraint(equalTo: cell.contentView.layoutMarginsGuide.trailingAnchor), + button.centerYAnchor.constraint(equalTo: cell.contentView.centerYAnchor) + ]) + } + + func updateColorPalettePopUpButton() { + let currentColorPalette = AppDefaults.userInterfaceColorPalette + let actions = UserInterfaceColorPalette.allCases.map { colorPalette in + UIAction(title: String(describing: colorPalette), state: colorPalette == currentColorPalette ? .on : .off) { _ in + AppDefaults.userInterfaceColorPalette = colorPalette + } + } + colorPalettePopUpButton.menu = UIMenu(children: actions) + } + + func updateUnreadCountDisplayPopUpButton() { + let currentUnreadCountDisplay = AppDefaults.shared.unreadCountDisplay + let actions = UnreadCountDisplay.allCases.map { unreadCountDisplay in + UIAction(title: String(describing: unreadCountDisplay), state: unreadCountDisplay == currentUnreadCountDisplay ? .on : .off) { _ in + AppDefaults.shared.unreadCountDisplay = unreadCountDisplay + } + } + unreadCountDisplayPopUpButton.menu = UIMenu(children: actions) + } + func addFeed() { self.dismiss(animated: true) diff --git a/iOS/Settings/UnreadCountDisplay+Description.swift b/iOS/Settings/UnreadCountDisplay+Description.swift new file mode 100644 index 000000000..d328c0d64 --- /dev/null +++ b/iOS/Settings/UnreadCountDisplay+Description.swift @@ -0,0 +1,22 @@ +// +// UnreadCountDisplay+Description.swift +// NetNewsWire +// +// Created by Brent Simmons on 10/6/26. +// + +import Foundation + +extension UnreadCountDisplay: CustomStringConvertible { + + var description: String { + switch self { + case .count: + NSLocalizedString("Show", comment: "Show") + case .dot: + NSLocalizedString("Show dot", comment: "Unread Counts setting: show a dot instead of the number of unread articles") + case .hidden: + NSLocalizedString("Hide", comment: "Hide") + } + } +}