mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 02:22:25 +00:00
Create Themes and Behavior sections for Articles settings. Put the smart feed rows in the Sidebar screen into a Smart Feeds section.
This commit is contained in:
1 parent
bd290f2dc0
commit
2a3243f49b
8 files changed
+275
-230
No files matched your search
@@ -221,7 +221,7 @@
|
||||
"Are you sure you want to delete the feed ”%@”?" : {
|
||||
"comment" : "Delete feed confirmation text."
|
||||
},
|
||||
"Are you sure you want to delete the theme “%@”?." : {
|
||||
"Are you sure you want to delete the theme “%@”?" : {
|
||||
"comment" : "Delete Theme Message"
|
||||
},
|
||||
"Are you sure you want to remove this account? NetNewsWire will no longer be able to access articles and feeds unless the account is added again." : {
|
||||
@@ -265,6 +265,9 @@
|
||||
"Automatic" : {
|
||||
"comment" : "Automatic"
|
||||
},
|
||||
"Behavior" : {
|
||||
"comment" : "Behavior"
|
||||
},
|
||||
"Can’t add a feed because no feed was found." : {
|
||||
"comment" : "Feed finder"
|
||||
},
|
||||
@@ -484,6 +487,9 @@
|
||||
"Delete Theme?" : {
|
||||
"comment" : "Delete Theme"
|
||||
},
|
||||
"Delete Theme…" : {
|
||||
"comment" : "Delete Theme…"
|
||||
},
|
||||
"Deleting read content records…" : {
|
||||
"comment" : "Cleanup phase text"
|
||||
},
|
||||
@@ -783,8 +789,8 @@
|
||||
"Import Failed" : {
|
||||
"comment" : "Import Failed"
|
||||
},
|
||||
"Import Theme" : {
|
||||
"comment" : "Import Theme"
|
||||
"Import Theme…" : {
|
||||
"comment" : "Import Theme…"
|
||||
},
|
||||
"Inspector" : {
|
||||
"comment" : "Inspector window title"
|
||||
@@ -1466,6 +1472,9 @@
|
||||
"Theme installed" : {
|
||||
"comment" : "Theme installed"
|
||||
},
|
||||
"Themes" : {
|
||||
"comment" : "Themes"
|
||||
},
|
||||
"There are no accounts to add the feed to." : {
|
||||
"comment" : "Error message when the user has no accounts to add a feed to.",
|
||||
"isCommentAutoGenerated" : true
|
||||
|
||||
@@ -7,8 +7,13 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import UniformTypeIdentifiers
|
||||
import RSWeb
|
||||
|
||||
extension UTType {
|
||||
static var netNewsWireTheme: UTType { UTType(importedAs: "com.ranchero.netnewswire.theme") }
|
||||
}
|
||||
|
||||
@MainActor struct ArticleThemeImporter {
|
||||
|
||||
static func importTheme(controller: UIViewController, url: URL) throws {
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
//
|
||||
// ArticleThemesTableViewController.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Maurice Parker on 9/12/21.
|
||||
// Copyright © 2021 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UniformTypeIdentifiers
|
||||
import UIKit
|
||||
|
||||
extension UTType {
|
||||
static var netNewsWireTheme: UTType { UTType(importedAs: "com.ranchero.netnewswire.theme") }
|
||||
}
|
||||
|
||||
final class ArticleThemesTableViewController: UITableViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
let importBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(importTheme(_:)))
|
||||
importBarButtonItem.title = NSLocalizedString("Import Theme", comment: "Import Theme")
|
||||
navigationItem.rightBarButtonItem = importBarButtonItem
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(articleThemeNamesDidChangeNotification(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc func articleThemeNamesDidChangeNotification(_ note: Notification) {
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
@objc func importTheme(_ sender: Any?) {
|
||||
let docPicker = UIDocumentPickerViewController(forOpeningContentTypes: [UTType.netNewsWireTheme])
|
||||
docPicker.delegate = self
|
||||
docPicker.modalPresentationStyle = .formSheet
|
||||
self.present(docPicker, animated: true)
|
||||
}
|
||||
|
||||
// MARK: - Table view data source
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return ArticleThemesManager.shared.themeNames.count + 1
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
||||
|
||||
let themeName: String
|
||||
if indexPath.row == 0 {
|
||||
themeName = ArticleTheme.defaultTheme.name
|
||||
} else {
|
||||
themeName = ArticleThemesManager.shared.themeNames[indexPath.row - 1]
|
||||
}
|
||||
|
||||
cell.textLabel?.text = themeName
|
||||
if themeName == ArticleThemesManager.shared.currentTheme.name {
|
||||
cell.accessoryType = .checkmark
|
||||
} else {
|
||||
cell.accessoryType = .none
|
||||
}
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
guard let cell = tableView.cellForRow(at: indexPath), let themeName = cell.textLabel?.text else { return }
|
||||
ArticleThemesManager.shared.currentThemeName = themeName
|
||||
navigationController?.popViewController(animated: true)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||
guard let cell = tableView.cellForRow(at: indexPath),
|
||||
let themeName = cell.textLabel?.text,
|
||||
let theme = ArticleThemesManager.shared.articleThemeWithThemeName(themeName),
|
||||
!theme.isAppTheme else { return nil }
|
||||
|
||||
let deleteTitle = NSLocalizedString("Delete", comment: "Delete button")
|
||||
let deleteAction = UIContextualAction(style: .normal, title: deleteTitle) { [weak self] (_, _, completion) in
|
||||
let title = NSLocalizedString("Delete Theme?", comment: "Delete Theme")
|
||||
|
||||
let localizedMessageText = NSLocalizedString("Are you sure you want to delete the theme “%@”?.", comment: "Delete Theme Message")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, themeName) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
|
||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel button")
|
||||
let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel) { _ in
|
||||
completion(true)
|
||||
}
|
||||
alertController.addAction(cancelAction)
|
||||
|
||||
let deleteTitle = NSLocalizedString("Delete", comment: "Delete button")
|
||||
let deleteAction = UIAlertAction(title: deleteTitle, style: .destructive) { _ in
|
||||
ArticleThemesManager.shared.deleteTheme(themeName: themeName)
|
||||
completion(true)
|
||||
}
|
||||
alertController.addAction(deleteAction)
|
||||
|
||||
self?.present(alertController, animated: true)
|
||||
}
|
||||
|
||||
deleteAction.image = Assets.Images.trash
|
||||
deleteAction.backgroundColor = UIColor.systemRed
|
||||
|
||||
return UISwipeActionsConfiguration(actions: [deleteAction])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: UIDocumentPickerDelegate
|
||||
|
||||
extension ArticleThemesTableViewController: UIDocumentPickerDelegate {
|
||||
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
guard let url = urls.first else { return }
|
||||
|
||||
if url.startAccessingSecurityScopedResource() {
|
||||
|
||||
defer {
|
||||
url.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
|
||||
do {
|
||||
try ArticleThemeImporter.importTheme(controller: self, url: url)
|
||||
} catch {
|
||||
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error": error])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,19 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
final class ArticlesSettingsViewController: UITableViewController {
|
||||
|
||||
private enum Row: Int, CaseIterable {
|
||||
private enum Section: Int, CaseIterable {
|
||||
case themes
|
||||
case behavior
|
||||
}
|
||||
|
||||
fileprivate enum Row {
|
||||
case theme
|
||||
case importTheme
|
||||
case deleteTheme
|
||||
case openLinksInNetNewsWire
|
||||
case enableJavaScript
|
||||
case swipeToNextPreviousArticle
|
||||
@@ -23,9 +31,12 @@ final class ArticlesSettingsViewController: UITableViewController {
|
||||
private let swipeToNextPreviousArticleSwitch = UISwitch()
|
||||
private let enableFullScreenArticlesSwitch = UISwitch()
|
||||
|
||||
private let themeCell = VibrantTableViewCell(style: .value1, reuseIdentifier: nil)
|
||||
private let themeCell = VibrantTableViewCell(style: .default, reuseIdentifier: nil)
|
||||
private let themePopUpButton = UIButton.makeSettingsPopUpButton()
|
||||
private let importThemeCell = UITableViewCell(style: .default, reuseIdentifier: nil)
|
||||
private let deleteThemeCell = UITableViewCell(style: .default, reuseIdentifier: nil)
|
||||
|
||||
private var rows = [Row]()
|
||||
private var rows = [Section: [Row]]()
|
||||
private var cells = [Row: UITableViewCell]()
|
||||
|
||||
init() {
|
||||
@@ -40,15 +51,29 @@ final class ArticlesSettingsViewController: UITableViewController {
|
||||
super.viewDidLoad()
|
||||
title = NSLocalizedString("Articles", comment: "Articles")
|
||||
|
||||
rows[.themes] = [.theme, .importTheme, .deleteTheme]
|
||||
// The Full Screen Articles row is iPhone-only.
|
||||
rows = Row.allCases.filter { $0 != .enableFullScreenArticles || traitCollection.userInterfaceIdiom == .phone }
|
||||
rows[.behavior] = [.openLinksInNetNewsWire, .enableJavaScript, .swipeToNextPreviousArticle, .enableFullScreenArticles].filter { $0 != .enableFullScreenArticles || traitCollection.userInterfaceIdiom == .phone }
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleCurrentArticleThemeDidChange(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleArticleThemeNamesDidChange(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
|
||||
|
||||
themeCell.selectionStyle = .none
|
||||
themeCell.textLabel?.text = NSLocalizedString("Theme", comment: "Theme")
|
||||
themeCell.textLabel?.numberOfLines = 0
|
||||
themeCell.textLabel?.adjustsFontForContentSizeCategory = true
|
||||
themeCell.detailTextLabel?.adjustsFontForContentSizeCategory = true
|
||||
themeCell.accessoryType = .disclosureIndicator
|
||||
themeCell.addSettingsPopUpButton(themePopUpButton, accessibilityLabel: NSLocalizedString("Theme", comment: "Theme"))
|
||||
updateThemePopUpButton()
|
||||
|
||||
configureButtonCell(importThemeCell, title: NSLocalizedString("Import Theme…", comment: "Import Theme…"))
|
||||
importThemeCell.textLabel?.textColor = Assets.Colors.primaryAccent
|
||||
|
||||
configureButtonCell(deleteThemeCell, title: NSLocalizedString("Delete Theme…", comment: "Delete Theme…"))
|
||||
updateDeleteThemeCell()
|
||||
|
||||
cells[.theme] = themeCell
|
||||
cells[.importTheme] = importThemeCell
|
||||
cells[.deleteTheme] = deleteThemeCell
|
||||
cells[.openLinksInNetNewsWire] = makeCell(switch: openLinksInNetNewsWireSwitch,
|
||||
title: NSLocalizedString("Open Links in NetNewsWire", comment: "Open Links in NetNewsWire"),
|
||||
footnote: nil,
|
||||
@@ -69,7 +94,6 @@ final class ArticlesSettingsViewController: UITableViewController {
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
themeCell.detailTextLabel?.text = ArticleThemesManager.shared.currentTheme.name
|
||||
openLinksInNetNewsWireSwitch.isOn = !AppDefaults.useSystemBrowser
|
||||
enableJavaScriptSwitch.isOn = AppDefaults.isArticleContentJavascriptEnabled
|
||||
swipeToNextPreviousArticleSwitch.isOn = AppDefaults.articleSwipeNavigationEnabled
|
||||
@@ -83,23 +107,41 @@ final class ArticlesSettingsViewController: UITableViewController {
|
||||
|
||||
// MARK: - UITableViewDataSource
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
Section.allCases.count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
switch Section(rawValue: section) {
|
||||
case .themes:
|
||||
NSLocalizedString("Themes", comment: "Themes")
|
||||
case .behavior:
|
||||
NSLocalizedString("Behavior", comment: "Behavior")
|
||||
case nil:
|
||||
nil
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return rows.count
|
||||
rowsInSection(section).count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
return cells[rows[indexPath.row]] ?? UITableViewCell()
|
||||
cells[rowsInSection(indexPath.section)[indexPath.row]] ?? UITableViewCell()
|
||||
}
|
||||
|
||||
// MARK: - UITableViewDelegate
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
switch rows[indexPath.row] {
|
||||
case .theme:
|
||||
let articleThemes = UIStoryboard.settings.instantiateController(ofType: ArticleThemesTableViewController.self)
|
||||
navigationController?.pushViewController(articleThemes, animated: true)
|
||||
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
||||
|
||||
switch rowsInSection(indexPath.section)[indexPath.row] {
|
||||
case .importTheme:
|
||||
presentImportThemePicker()
|
||||
case .deleteTheme:
|
||||
presentDeleteThemeChoices()
|
||||
default:
|
||||
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,12 +162,139 @@ final class ArticlesSettingsViewController: UITableViewController {
|
||||
@objc func switchEnableFullScreenArticles(_ sender: UISwitch) {
|
||||
AppDefaults.articleFullscreenAvailable = sender.isOn
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@objc func handleCurrentArticleThemeDidChange(_ notification: Notification) {
|
||||
updateThemePopUpButton()
|
||||
}
|
||||
|
||||
@objc func handleArticleThemeNamesDidChange(_ notification: Notification) {
|
||||
updateThemePopUpButton()
|
||||
updateDeleteThemeCell()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIDocumentPickerDelegate
|
||||
|
||||
extension ArticlesSettingsViewController: UIDocumentPickerDelegate {
|
||||
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
guard let url = urls.first else {
|
||||
return
|
||||
}
|
||||
guard url.startAccessingSecurityScopedResource() else {
|
||||
return
|
||||
}
|
||||
defer {
|
||||
url.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
|
||||
do {
|
||||
try ArticleThemeImporter.importTheme(controller: self, url: url)
|
||||
} catch {
|
||||
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error": error])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private extension ArticlesSettingsViewController {
|
||||
|
||||
func rowsInSection(_ section: Int) -> [Row] {
|
||||
guard let section = Section(rawValue: section) else {
|
||||
return []
|
||||
}
|
||||
return rows[section] ?? []
|
||||
}
|
||||
|
||||
func updateThemePopUpButton() {
|
||||
let defaultThemeName = ArticleTheme.defaultTheme.name
|
||||
let installedThemeNames = ArticleThemesManager.shared.themeNames.filter { $0 != defaultThemeName }
|
||||
var currentThemeName = ArticleThemesManager.shared.currentThemeName
|
||||
if !installedThemeNames.contains(currentThemeName) {
|
||||
currentThemeName = defaultThemeName
|
||||
}
|
||||
|
||||
func themeAction(_ themeName: String) -> UIAction {
|
||||
UIAction(title: themeName, state: themeName == currentThemeName ? .on : .off) { _ in
|
||||
ArticleThemesManager.shared.currentThemeName = themeName
|
||||
}
|
||||
}
|
||||
|
||||
let defaultThemeMenu = UIMenu(options: .displayInline, children: [themeAction(defaultThemeName)])
|
||||
let installedThemesMenu = UIMenu(options: .displayInline, children: installedThemeNames.map { themeAction($0) })
|
||||
themePopUpButton.menu = UIMenu(children: [defaultThemeMenu, installedThemesMenu])
|
||||
themePopUpButton.accessibilityValue = currentThemeName
|
||||
}
|
||||
|
||||
/// Themes that came with the app can’t be deleted.
|
||||
var deletableThemeNames: [String] {
|
||||
ArticleThemesManager.shared.themeNames.filter { themeName in
|
||||
guard let theme = ArticleThemesManager.shared.articleThemeWithThemeName(themeName) else {
|
||||
return false
|
||||
}
|
||||
return !theme.isAppTheme
|
||||
}
|
||||
}
|
||||
|
||||
func updateDeleteThemeCell() {
|
||||
let isEnabled = !deletableThemeNames.isEmpty
|
||||
deleteThemeCell.isUserInteractionEnabled = isEnabled
|
||||
deleteThemeCell.textLabel?.isEnabled = isEnabled
|
||||
deleteThemeCell.textLabel?.textColor = isEnabled ? .systemRed : .tertiaryLabel
|
||||
deleteThemeCell.accessibilityTraits = isEnabled ? .button : [.button, .notEnabled]
|
||||
}
|
||||
|
||||
func presentImportThemePicker() {
|
||||
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.netNewsWireTheme])
|
||||
documentPicker.delegate = self
|
||||
documentPicker.modalPresentationStyle = .formSheet
|
||||
present(documentPicker, animated: true)
|
||||
}
|
||||
|
||||
func presentDeleteThemeChoices() {
|
||||
let themeNames = deletableThemeNames
|
||||
guard !themeNames.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
for themeName in themeNames {
|
||||
alertController.addAction(UIAlertAction(title: themeName, style: .destructive) { [weak self] _ in
|
||||
self?.confirmDeleteTheme(themeName)
|
||||
})
|
||||
}
|
||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Cancel button"), style: .cancel))
|
||||
|
||||
if let popoverController = alertController.popoverPresentationController {
|
||||
popoverController.sourceView = deleteThemeCell
|
||||
popoverController.sourceRect = deleteThemeCell.bounds
|
||||
}
|
||||
present(alertController, animated: true)
|
||||
}
|
||||
|
||||
func confirmDeleteTheme(_ themeName: String) {
|
||||
let title = NSLocalizedString("Delete Theme?", comment: "Delete Theme")
|
||||
let localizedMessageText = NSLocalizedString("Are you sure you want to delete the theme “%@”?", comment: "Delete Theme Message")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, themeName) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Cancel button"), style: .cancel))
|
||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Delete", comment: "Delete button"), style: .destructive) { _ in
|
||||
ArticleThemesManager.shared.deleteTheme(themeName: themeName)
|
||||
})
|
||||
present(alertController, animated: true)
|
||||
}
|
||||
|
||||
func configureButtonCell(_ cell: UITableViewCell, title: String) {
|
||||
cell.textLabel?.text = title
|
||||
cell.textLabel?.numberOfLines = 0
|
||||
cell.textLabel?.adjustsFontForContentSizeCategory = true
|
||||
cell.accessibilityTraits = .button
|
||||
}
|
||||
|
||||
/// A plain cell, rather than a vibrant one, so the footnote keeps its secondary color.
|
||||
func makeCell(switch toggle: UISwitch, title: String, footnote: String?, action: Selector) -> UITableViewCell {
|
||||
let cell = UITableViewCell(style: footnote == nil ? .default : .subtitle, reuseIdentifier: nil)
|
||||
|
||||
@@ -20,8 +20,8 @@ final class GeneralSettingsViewController: UITableViewController {
|
||||
private let unreadCountDisplayCell = VibrantTableViewCell(style: .default, reuseIdentifier: nil)
|
||||
private let grayscaleIconsCell = VibrantTableViewCell(style: .default, reuseIdentifier: nil)
|
||||
|
||||
private lazy var colorPalettePopUpButton = Self.makePopUpButton()
|
||||
private lazy var unreadCountDisplayPopUpButton = Self.makePopUpButton()
|
||||
private let colorPalettePopUpButton = UIButton.makeSettingsPopUpButton()
|
||||
private let unreadCountDisplayPopUpButton = UIButton.makeSettingsPopUpButton()
|
||||
private let grayscaleIconsSwitch = UISwitch()
|
||||
|
||||
init() {
|
||||
@@ -44,8 +44,8 @@ final class GeneralSettingsViewController: UITableViewController {
|
||||
configureLabeledCell(unreadCountDisplayCell, title: NSLocalizedString("Unread Counts", comment: "Unread Counts"))
|
||||
configureLabeledCell(grayscaleIconsCell, title: NSLocalizedString("Grayscale Feed Icons", comment: "Grayscale Feed Icons"))
|
||||
|
||||
addPopUpButton(colorPalettePopUpButton, to: colorPaletteCell, accessibilityLabel: NSLocalizedString("Color Palette", comment: "Color Palette"))
|
||||
addPopUpButton(unreadCountDisplayPopUpButton, to: unreadCountDisplayCell, accessibilityLabel: NSLocalizedString("Unread Counts", comment: "Unread Counts"))
|
||||
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)
|
||||
@@ -98,15 +98,6 @@ final class GeneralSettingsViewController: UITableViewController {
|
||||
|
||||
private extension GeneralSettingsViewController {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func configureLabeledCell(_ cell: UITableViewCell, title: String) {
|
||||
cell.selectionStyle = .none
|
||||
cell.textLabel?.text = title
|
||||
@@ -114,19 +105,6 @@ private extension GeneralSettingsViewController {
|
||||
cell.textLabel?.adjustsFontForContentSizeCategory = true
|
||||
}
|
||||
|
||||
/// Auto Layout lets the button resize itself when choosing an item changes its title.
|
||||
/// The accessibility label names the setting, since the button’s title is only the current choice.
|
||||
func addPopUpButton(_ button: UIButton, to cell: UITableViewCell, accessibilityLabel: String) {
|
||||
button.accessibilityLabel = accessibilityLabel
|
||||
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
|
||||
|
||||
@@ -401,45 +401,6 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-454" y="152"/>
|
||||
</scene>
|
||||
<!--Theme-->
|
||||
<scene sceneID="1mT-fg-ezs">
|
||||
<objects>
|
||||
<tableViewController storyboardIdentifier="ArticleThemesTableViewController" title="Theme" id="fO4-og-e41" customClass="ArticleThemesTableViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="insetGrouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="I8p-P9-C8h">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="746"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" systemColor="groupTableViewBackgroundColor"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" textLabel="6tf-Xb-7b8" style="IBUITableViewCellStyleDefault" id="BIC-Zk-QMD" customClass="VibrantTableViewCell" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<rect key="frame" x="20" y="55.5" width="374" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="BIC-Zk-QMD" id="7xj-8Y-ejz">
|
||||
<rect key="frame" x="0.0" y="0.0" width="374" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="6tf-Xb-7b8">
|
||||
<rect key="frame" x="20" y="0.0" width="334" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
<sections/>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="fO4-og-e41" id="155-KJ-Ps6"/>
|
||||
<outlet property="delegate" destination="fO4-og-e41" id="zBh-hF-yaJ"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" translucent="NO" prompted="NO"/>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="ODK-C8-FL4" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="3743" y="151"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<namedColor name="primaryAccentColor">
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// SettingsPopUpButton.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Brent Simmons on 11/14/26.
|
||||
// Copyright © 2026 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIButton {
|
||||
|
||||
/// A pop-up button for a Settings row. Its title is the current choice.
|
||||
static func makeSettingsPopUpButton() -> UIButton {
|
||||
var configuration = UIButton.Configuration.plain()
|
||||
configuration.baseForegroundColor = .secondaryLabel
|
||||
let button = UIButton(configuration: configuration)
|
||||
button.showsMenuAsPrimaryAction = true
|
||||
button.changesSelectionAsPrimaryAction = true
|
||||
return button
|
||||
}
|
||||
}
|
||||
|
||||
extension UITableViewCell {
|
||||
|
||||
/// Auto Layout lets the button resize itself when choosing an item changes its title.
|
||||
/// The accessibility label names the setting, since the button’s title is only the current choice.
|
||||
func addSettingsPopUpButton(_ button: UIButton, accessibilityLabel: String) {
|
||||
button.accessibilityLabel = accessibilityLabel
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
contentView.addSubview(button)
|
||||
NSLayoutConstraint.activate([
|
||||
button.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
|
||||
button.centerYAnchor.constraint(equalTo: contentView.centerYAnchor)
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,9 @@ import UIKit
|
||||
|
||||
final class SidebarSettingsViewController: UITableViewController {
|
||||
|
||||
private enum Row: Int, CaseIterable {
|
||||
case showFeedIcons
|
||||
case showToday
|
||||
case showAllUnread
|
||||
case showStarred
|
||||
private enum Section: Int, CaseIterable {
|
||||
case feedIcons
|
||||
case smartFeeds
|
||||
}
|
||||
|
||||
private let showFeedIconsSwitch = UISwitch()
|
||||
@@ -22,7 +20,7 @@ final class SidebarSettingsViewController: UITableViewController {
|
||||
private let showAllUnreadSwitch = UISwitch()
|
||||
private let showStarredSwitch = UISwitch()
|
||||
|
||||
private var cells = [UITableViewCell]()
|
||||
private var cells = [Section: [UITableViewCell]]()
|
||||
|
||||
init() {
|
||||
super.init(style: .insetGrouped)
|
||||
@@ -39,13 +37,14 @@ final class SidebarSettingsViewController: UITableViewController {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleSidebarShowsIconsDidChange(_:)), name: .sidebarShowsIconsDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleSidebarSmartFeedsVisibilityDidChange(_:)), name: .sidebarSmartFeedsVisibilityDidChange, object: nil)
|
||||
|
||||
let switchesAndTitles: [(UISwitch, String, Selector)] = [
|
||||
(showFeedIconsSwitch, NSLocalizedString("Show Feed Icons", comment: "Show Feed Icons"), #selector(switchShowFeedIcons(_:))),
|
||||
(showTodaySwitch, NSLocalizedString("Show Today", comment: "Show Today"), #selector(switchShowToday(_:))),
|
||||
(showAllUnreadSwitch, NSLocalizedString("Show All Unread", comment: "Show All Unread"), #selector(switchShowAllUnread(_:))),
|
||||
(showStarredSwitch, NSLocalizedString("Show Starred", comment: "Show Starred"), #selector(switchShowStarred(_:)))
|
||||
cells[.feedIcons] = [
|
||||
makeCell(switch: showFeedIconsSwitch, title: NSLocalizedString("Show Feed Icons", comment: "Show Feed Icons"), action: #selector(switchShowFeedIcons(_:)))
|
||||
]
|
||||
cells[.smartFeeds] = [
|
||||
makeCell(switch: showTodaySwitch, title: NSLocalizedString("Show Today", comment: "Show Today"), action: #selector(switchShowToday(_:))),
|
||||
makeCell(switch: showAllUnreadSwitch, title: NSLocalizedString("Show All Unread", comment: "Show All Unread"), action: #selector(switchShowAllUnread(_:))),
|
||||
makeCell(switch: showStarredSwitch, title: NSLocalizedString("Show Starred", comment: "Show Starred"), action: #selector(switchShowStarred(_:)))
|
||||
]
|
||||
cells = switchesAndTitles.map { makeCell(switch: $0.0, title: $0.1, action: $0.2) }
|
||||
|
||||
updateShowFeedIconsSwitch()
|
||||
updateSmartFeedsSwitches()
|
||||
@@ -53,12 +52,25 @@ final class SidebarSettingsViewController: UITableViewController {
|
||||
|
||||
// MARK: - UITableViewDataSource
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
Section.allCases.count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
switch Section(rawValue: section) {
|
||||
case .smartFeeds:
|
||||
NSLocalizedString("Smart Feeds", comment: "Smart Feeds group title")
|
||||
case .feedIcons, nil:
|
||||
nil
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return cells.count
|
||||
cellsInSection(section).count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
return cells[indexPath.row]
|
||||
cellsInSection(indexPath.section)[indexPath.row]
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
@@ -94,6 +106,13 @@ final class SidebarSettingsViewController: UITableViewController {
|
||||
|
||||
private extension SidebarSettingsViewController {
|
||||
|
||||
func cellsInSection(_ section: Int) -> [UITableViewCell] {
|
||||
guard let section = Section(rawValue: section) else {
|
||||
return []
|
||||
}
|
||||
return cells[section] ?? []
|
||||
}
|
||||
|
||||
func makeCell(switch toggle: UISwitch, title: String, action: Selector) -> UITableViewCell {
|
||||
let cell = VibrantTableViewCell(style: .default, reuseIdentifier: nil)
|
||||
cell.selectionStyle = .none
|
||||
|
||||
Reference in new issue
Block a user