mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 10:47:21 +00:00
Convert Sidebar settings on iOS to SwiftUI.
This commit is contained in:
1 parent
7be0246e54
commit
d44a52487c
4 files changed
+71
-138
No files matched your search
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// 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))
|
||||
}
|
||||
}
|
||||
@@ -281,7 +281,7 @@ final class SettingsViewController: UITableViewController {
|
||||
case .general:
|
||||
navigationController?.pushViewController(GeneralSettingsViewController(), animated: true)
|
||||
case .sidebar:
|
||||
navigationController?.pushViewController(SidebarSettingsViewController(), animated: true)
|
||||
navigationController?.pushViewController(UIHostingController(rootView: SidebarSettingsView()), animated: true)
|
||||
case .timeline:
|
||||
navigationController?.pushViewController(TimelineSettingsViewController(), animated: true)
|
||||
case .articles:
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// SidebarSettingsView.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Brent Simmons on 11/14/26.
|
||||
// Copyright © 2026 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SidebarSettingsView: View {
|
||||
|
||||
@State private var model = SidebarSettingsModel()
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Section {
|
||||
Toggle(String(localized: "Show Feed Icons", comment: "Show Feed Icons"), isOn: Binding(get: { model.showFeedIcons }, set: { AppDefaults.sidebarShowsIcons = $0 }))
|
||||
}
|
||||
Section(String(localized: "Smart Feeds", comment: "Smart Feeds group title")) {
|
||||
Toggle(String(localized: "Show Today", comment: "Show Today"), isOn: Binding(get: { model.showToday }, set: { AppDefaults.showTodayFeed = $0 }))
|
||||
Toggle(String(localized: "Show All Unread", comment: "Show All Unread"), isOn: Binding(get: { model.showAllUnread }, set: { AppDefaults.showUnreadFeed = $0 }))
|
||||
Toggle(String(localized: "Show Starred", comment: "Show Starred"), isOn: Binding(get: { model.showStarred }, set: { AppDefaults.showStarredFeed = $0 }))
|
||||
}
|
||||
}
|
||||
.settingsToggleTint()
|
||||
.navigationTitle(String(localized: "Sidebar", comment: "Sidebar"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Tracks the Sidebar settings in AppDefaults, updating when they change.
|
||||
@MainActor @Observable final class SidebarSettingsModel {
|
||||
|
||||
private(set) var showFeedIcons = AppDefaults.sidebarShowsIcons
|
||||
private(set) var showToday = AppDefaults.showTodayFeed
|
||||
private(set) var showAllUnread = AppDefaults.showUnreadFeed
|
||||
private(set) var showStarred = AppDefaults.showStarredFeed
|
||||
|
||||
init() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleSidebarShowsIconsDidChange(_:)), name: .sidebarShowsIconsDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleSidebarSmartFeedsVisibilityDidChange(_:)), name: .sidebarSmartFeedsVisibilityDidChange, object: nil)
|
||||
}
|
||||
|
||||
@objc func handleSidebarShowsIconsDidChange(_ notification: Notification) {
|
||||
showFeedIcons = AppDefaults.sidebarShowsIcons
|
||||
}
|
||||
|
||||
@objc func handleSidebarSmartFeedsVisibilityDidChange(_ notification: Notification) {
|
||||
showToday = AppDefaults.showTodayFeed
|
||||
showAllUnread = AppDefaults.showUnreadFeed
|
||||
showStarred = AppDefaults.showStarredFeed
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
//
|
||||
// SidebarSettingsViewController.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Brent Simmons on 11/15/26.
|
||||
// Copyright © 2026 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
final class SidebarSettingsViewController: UITableViewController {
|
||||
|
||||
private enum Section: Int, CaseIterable {
|
||||
case feedIcons
|
||||
case smartFeeds
|
||||
}
|
||||
|
||||
private let showFeedIconsSwitch = UISwitch()
|
||||
private let showTodaySwitch = UISwitch()
|
||||
private let showAllUnreadSwitch = UISwitch()
|
||||
private let showStarredSwitch = UISwitch()
|
||||
|
||||
private var cells = [Section: [UITableViewCell]]()
|
||||
|
||||
init() {
|
||||
super.init(style: .insetGrouped)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
title = NSLocalizedString("Sidebar", comment: "Sidebar")
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleSidebarShowsIconsDidChange(_:)), name: .sidebarShowsIconsDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleSidebarSmartFeedsVisibilityDidChange(_:)), name: .sidebarSmartFeedsVisibilityDidChange, object: nil)
|
||||
|
||||
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(_:)))
|
||||
]
|
||||
|
||||
updateShowFeedIconsSwitch()
|
||||
updateSmartFeedsSwitches()
|
||||
}
|
||||
|
||||
// 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 {
|
||||
cellsInSection(section).count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
cellsInSection(indexPath.section)[indexPath.row]
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@objc func switchShowFeedIcons(_ sender: UISwitch) {
|
||||
AppDefaults.sidebarShowsIcons = sender.isOn
|
||||
}
|
||||
|
||||
@objc func switchShowToday(_ sender: UISwitch) {
|
||||
AppDefaults.showTodayFeed = sender.isOn
|
||||
}
|
||||
|
||||
@objc func switchShowAllUnread(_ sender: UISwitch) {
|
||||
AppDefaults.showUnreadFeed = sender.isOn
|
||||
}
|
||||
|
||||
@objc func switchShowStarred(_ sender: UISwitch) {
|
||||
AppDefaults.showStarredFeed = sender.isOn
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@objc func handleSidebarShowsIconsDidChange(_ notification: Notification) {
|
||||
updateShowFeedIconsSwitch()
|
||||
}
|
||||
|
||||
@objc func handleSidebarSmartFeedsVisibilityDidChange(_ notification: Notification) {
|
||||
updateSmartFeedsSwitches()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
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
|
||||
cell.textLabel?.text = title
|
||||
cell.textLabel?.numberOfLines = 0
|
||||
cell.textLabel?.adjustsFontForContentSizeCategory = true
|
||||
toggle.onTintColor = Assets.Colors.primaryAccent
|
||||
toggle.addTarget(self, action: action, for: .valueChanged)
|
||||
cell.accessoryView = toggle
|
||||
return cell
|
||||
}
|
||||
|
||||
func updateShowFeedIconsSwitch() {
|
||||
showFeedIconsSwitch.isOn = AppDefaults.sidebarShowsIcons
|
||||
}
|
||||
|
||||
func updateSmartFeedsSwitches() {
|
||||
showTodaySwitch.isOn = AppDefaults.showTodayFeed
|
||||
showAllUnreadSwitch.isOn = AppDefaults.showUnreadFeed
|
||||
showStarredSwitch.isOn = AppDefaults.showStarredFeed
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user