diff --git a/Shared/Localizable.xcstrings b/Shared/Localizable.xcstrings
index 11aa385fe..bba1b0f88 100644
--- a/Shared/Localizable.xcstrings
+++ b/Shared/Localizable.xcstrings
@@ -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
diff --git a/iOS/Settings/ArticleThemeImporter.swift b/iOS/Settings/ArticleThemeImporter.swift
index 9757cfefd..3fe523495 100644
--- a/iOS/Settings/ArticleThemeImporter.swift
+++ b/iOS/Settings/ArticleThemeImporter.swift
@@ -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 {
diff --git a/iOS/Settings/ArticleThemesTableViewController.swift b/iOS/Settings/ArticleThemesTableViewController.swift
deleted file mode 100644
index 9c81b663d..000000000
--- a/iOS/Settings/ArticleThemesTableViewController.swift
+++ /dev/null
@@ -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])
- }
- }
- }
-}
diff --git a/iOS/Settings/ArticlesSettingsViewController.swift b/iOS/Settings/ArticlesSettingsViewController.swift
index 1b6cf1614..93f24c0cd 100644
--- a/iOS/Settings/ArticlesSettingsViewController.swift
+++ b/iOS/Settings/ArticlesSettingsViewController.swift
@@ -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)
diff --git a/iOS/Settings/GeneralSettingsViewController.swift b/iOS/Settings/GeneralSettingsViewController.swift
index c5fc001f0..f0ad04ccd 100644
--- a/iOS/Settings/GeneralSettingsViewController.swift
+++ b/iOS/Settings/GeneralSettingsViewController.swift
@@ -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
diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard
index 093877240..6a8af2116 100644
--- a/iOS/Settings/Settings.storyboard
+++ b/iOS/Settings/Settings.storyboard
@@ -401,45 +401,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/iOS/Settings/SettingsPopUpButton.swift b/iOS/Settings/SettingsPopUpButton.swift
new file mode 100644
index 000000000..ca4340d6a
--- /dev/null
+++ b/iOS/Settings/SettingsPopUpButton.swift
@@ -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)
+ ])
+ }
+}
diff --git a/iOS/Settings/SidebarSettingsViewController.swift b/iOS/Settings/SidebarSettingsViewController.swift
index 9e1873bb9..c25df69b7 100644
--- a/iOS/Settings/SidebarSettingsViewController.swift
+++ b/iOS/Settings/SidebarSettingsViewController.swift
@@ -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