diff --git a/iOS/Settings/GeneralSettingsView.swift b/iOS/Settings/GeneralSettingsView.swift new file mode 100644 index 000000000..d75851e2b --- /dev/null +++ b/iOS/Settings/GeneralSettingsView.swift @@ -0,0 +1,60 @@ +// +// GeneralSettingsView.swift +// NetNewsWire-iOS +// +// Created by Brent Simmons on 11/14/26. +// Copyright © 2026 Ranchero Software. All rights reserved. +// + +import SwiftUI + +struct GeneralSettingsView: View { + + @State private var model = GeneralSettingsModel() + + var body: some View { + List { + Picker(String(localized: "Color Palette", comment: "Color Palette"), selection: Binding(get: { model.colorPalette }, set: { AppDefaults.userInterfaceColorPalette = $0 })) { + ForEach(UserInterfaceColorPalette.allCases, id: \.self) { colorPalette in + Text(String(describing: colorPalette)) + } + } + .settingsMenuPickerStyle() + Picker(String(localized: "Unread Counts", comment: "Unread Counts"), selection: Binding(get: { model.unreadCountDisplay }, set: { AppDefaults.unreadCountDisplay = $0 })) { + ForEach(UnreadCountDisplay.allCases, id: \.self) { unreadCountDisplay in + Text(String(describing: unreadCountDisplay)) + } + } + .settingsMenuPickerStyle() + Toggle(String(localized: "Grayscale Feed Icons", comment: "Grayscale Feed Icons"), isOn: Binding(get: { model.grayscaleIcons }, set: { AppDefaults.grayscaleIcons = $0 })) + .settingsToggleTint() + } + .navigationTitle(String(localized: "General", comment: "Preferences")) + } +} + +/// Tracks the General settings in AppDefaults, updating when they change. +@MainActor @Observable final class GeneralSettingsModel { + + private(set) var colorPalette = AppDefaults.userInterfaceColorPalette + private(set) var unreadCountDisplay = AppDefaults.unreadCountDisplay + private(set) var grayscaleIcons = AppDefaults.grayscaleIcons + + init() { + NotificationCenter.default.addObserver(self, selector: #selector(handleUserInterfaceColorPaletteDidUpdate(_:)), name: .userInterfaceColorPaletteDidUpdate, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleGrayscaleIconsDidChange(_:)), name: .grayscaleIconsDidChange, object: nil) + } + + @objc func handleUserInterfaceColorPaletteDidUpdate(_ notification: Notification) { + colorPalette = AppDefaults.userInterfaceColorPalette + } + + @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { + unreadCountDisplay = AppDefaults.unreadCountDisplay + } + + @objc func handleGrayscaleIconsDidChange(_ notification: Notification) { + grayscaleIcons = AppDefaults.grayscaleIcons + } +} diff --git a/iOS/Settings/GeneralSettingsViewController.swift b/iOS/Settings/GeneralSettingsViewController.swift deleted file mode 100644 index f0ad04ccd..000000000 --- a/iOS/Settings/GeneralSettingsViewController.swift +++ /dev/null @@ -1,133 +0,0 @@ -// -// GeneralSettingsViewController.swift -// NetNewsWire-iOS -// -// Created by Brent Simmons on 11/14/26. -// Copyright © 2026 Ranchero Software. All rights reserved. -// - -import UIKit - -final class GeneralSettingsViewController: UITableViewController { - - private enum Row: Int, CaseIterable { - case colorPalette - case unreadCounts - case grayscaleIcons - } - - private let colorPaletteCell = VibrantTableViewCell(style: .default, reuseIdentifier: nil) - private let unreadCountDisplayCell = VibrantTableViewCell(style: .default, reuseIdentifier: nil) - private let grayscaleIconsCell = VibrantTableViewCell(style: .default, reuseIdentifier: nil) - - private let colorPalettePopUpButton = UIButton.makeSettingsPopUpButton() - private let unreadCountDisplayPopUpButton = UIButton.makeSettingsPopUpButton() - private let grayscaleIconsSwitch = UISwitch() - - init() { - super.init(style: .insetGrouped) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func viewDidLoad() { - super.viewDidLoad() - title = NSLocalizedString("General", comment: "Preferences") - - NotificationCenter.default.addObserver(self, selector: #selector(handleUserInterfaceColorPaletteDidUpdate(_:)), name: .userInterfaceColorPaletteDidUpdate, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(handleGrayscaleIconsDidChange(_:)), name: .grayscaleIconsDidChange, object: nil) - - configureLabeledCell(colorPaletteCell, title: NSLocalizedString("Color Palette", comment: "Color Palette")) - configureLabeledCell(unreadCountDisplayCell, title: NSLocalizedString("Unread Counts", comment: "Unread Counts")) - configureLabeledCell(grayscaleIconsCell, title: NSLocalizedString("Grayscale Feed Icons", comment: "Grayscale Feed Icons")) - - colorPaletteCell.addSettingsPopUpButton(colorPalettePopUpButton, accessibilityLabel: NSLocalizedString("Color Palette", comment: "Color Palette")) - unreadCountDisplayCell.addSettingsPopUpButton(unreadCountDisplayPopUpButton, accessibilityLabel: NSLocalizedString("Unread Counts", comment: "Unread Counts")) - - grayscaleIconsSwitch.onTintColor = Assets.Colors.primaryAccent - grayscaleIconsSwitch.addTarget(self, action: #selector(switchGrayscaleIcons(_:)), for: .valueChanged) - grayscaleIconsCell.accessoryView = grayscaleIconsSwitch - - updateColorPalettePopUpButton() - updateUnreadCountDisplayPopUpButton() - updateGrayscaleIconsSwitch() - } - - // MARK: - UITableViewDataSource - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return Row.allCases.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - switch Row.allCases[indexPath.row] { - case .colorPalette: - return colorPaletteCell - case .unreadCounts: - return unreadCountDisplayCell - case .grayscaleIcons: - return grayscaleIconsCell - } - } - - // MARK: - Actions - - @objc func switchGrayscaleIcons(_ sender: UISwitch) { - AppDefaults.grayscaleIcons = sender.isOn - } - - // MARK: - Notifications - - @objc func handleUserInterfaceColorPaletteDidUpdate(_ notification: Notification) { - updateColorPalettePopUpButton() - } - - @objc func handleUnreadCountDisplaySettingDidChange(_ notification: Notification) { - updateUnreadCountDisplayPopUpButton() - } - - @objc func handleGrayscaleIconsDidChange(_ notification: Notification) { - updateGrayscaleIconsSwitch() - } -} - -// MARK: - Private - -private extension GeneralSettingsViewController { - - func configureLabeledCell(_ cell: UITableViewCell, title: String) { - cell.selectionStyle = .none - cell.textLabel?.text = title - cell.textLabel?.numberOfLines = 0 - cell.textLabel?.adjustsFontForContentSizeCategory = true - } - - 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) - colorPalettePopUpButton.accessibilityValue = String(describing: currentColorPalette) - } - - func updateUnreadCountDisplayPopUpButton() { - let currentUnreadCountDisplay = AppDefaults.unreadCountDisplay - let actions = UnreadCountDisplay.allCases.map { unreadCountDisplay in - UIAction(title: String(describing: unreadCountDisplay), state: unreadCountDisplay == currentUnreadCountDisplay ? .on : .off) { _ in - AppDefaults.unreadCountDisplay = unreadCountDisplay - } - } - unreadCountDisplayPopUpButton.menu = UIMenu(children: actions) - unreadCountDisplayPopUpButton.accessibilityValue = String(describing: currentUnreadCountDisplay) - } - - func updateGrayscaleIconsSwitch() { - grayscaleIconsSwitch.isOn = AppDefaults.grayscaleIcons - } -} diff --git a/iOS/Settings/SettingsToggleTint.swift b/iOS/Settings/SettingsToggleTint.swift deleted file mode 100644 index 2cdefaceb..000000000 --- a/iOS/Settings/SettingsToggleTint.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// SettingsToggleTint.swift -// NetNewsWire-iOS -// -// Created by Brent Simmons on 11/14/26. -// Copyright © 2026 Ranchero Software. All rights reserved. -// - -import SwiftUI - -extension View { - - /// Gives Settings switches the app’s accent color, matching the rest of the app’s switches. - func settingsToggleTint() -> some View { - tint(Color(uiColor: Assets.Colors.primaryAccent)) - } -} diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index c16774612..49c50fdd7 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -279,7 +279,7 @@ final class SettingsViewController: UITableViewController { case .addNetNewsWireNewsFeed: addFeed() case .general: - navigationController?.pushViewController(GeneralSettingsViewController(), animated: true) + navigationController?.pushViewController(UIHostingController(rootView: GeneralSettingsView()), animated: true) case .sidebar: navigationController?.pushViewController(UIHostingController(rootView: SidebarSettingsView()), animated: true) case .timeline: diff --git a/iOS/SwiftUI Extensions/View+Extras.swift b/iOS/SwiftUI Extensions/View+Extras.swift index cd472daa5..e9a4d3e51 100644 --- a/iOS/SwiftUI Extensions/View+Extras.swift +++ b/iOS/SwiftUI Extensions/View+Extras.swift @@ -27,4 +27,15 @@ extension View { Text(verbatim: message.wrappedValue ?? "") } } + + /// Gives Settings switches the app’s accent color, matching the rest of the app’s switches. + func settingsToggleTint() -> some View { + tint(Color(uiColor: Assets.Colors.primaryAccent)) + } + + /// A pop-up menu showing the current choice in secondary text, rather than in the accent color. + func settingsMenuPickerStyle() -> some View { + pickerStyle(.menu) + .tint(Color(uiColor: .secondaryLabel)) + } }