From f120b1a280cc371a552401b6ce24f5edf7eb41da Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Tue, 27 Jan 2026 22:12:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20#5028?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainTimelineCollectionViewCell.swift | 5 + iOS/Settings/Settings.storyboard | 336 +++++++++--------- iOS/Settings/SettingsViewController.swift | 2 +- ...ell.swift => TimelineCustomizerCell.swift} | 52 +-- ...neCustomizerCollectionViewController.swift | 183 ++++++++++ ...imelineCustomizerTableViewController.swift | 132 ------- iOS/Settings/TimelineHeaderView.swift | 36 ++ 7 files changed, 408 insertions(+), 338 deletions(-) rename iOS/Settings/{ModernTimelineSliderCell.swift => TimelineCustomizerCell.swift} (50%) create mode 100644 iOS/Settings/TimelineCustomizerCollectionViewController.swift delete mode 100644 iOS/Settings/TimelineCustomizerTableViewController.swift create mode 100644 iOS/Settings/TimelineHeaderView.swift diff --git a/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift b/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift index 2ef966d0d..6b7ee3113 100644 --- a/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift +++ b/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift @@ -296,6 +296,11 @@ class MainTimelineCollectionViewCell: UICollectionViewCell { } adjustArticleContentColor() updateIndicatorView(state) + + if isPreview { + backgroundConfig.backgroundColor = .secondarySystemBackground + topSeparator.alpha = 0.0 + } self.backgroundConfiguration = backgroundConfig } diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index d9e9015e9..cc2f0d971 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -5,8 +5,8 @@ - + @@ -641,195 +641,197 @@ - - + + - - - + + + - - - - - - + + + + + + + + + + + + - - + + - + - - - - - + + + + - + + - + - - - - - + + + + + - + - - + + - + - - - - - + + + + - - + + - + - - - - - - - + + + + + + + - - - + + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - - + - - - - - - - - - - - - + + + + + + + + + + + + - - + + - - - - - + + + + + + - - - + + - - + + - - - - + + + - + @@ -983,13 +983,19 @@ - + + + + + + + - + - - + + diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index dd0f4af10..2ce55bc4a 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -202,7 +202,7 @@ final class SettingsViewController: UITableViewController { case 3: switch indexPath.row { case 3: - let timeline = UIStoryboard.settings.instantiateController(ofType: TimelineCustomizerTableViewController.self) + let timeline = UIStoryboard.settings.instantiateController(ofType: TimelineCustomizerCollectionViewController.self) self.navigationController?.pushViewController(timeline, animated: true) default: break diff --git a/iOS/Settings/ModernTimelineSliderCell.swift b/iOS/Settings/TimelineCustomizerCell.swift similarity index 50% rename from iOS/Settings/ModernTimelineSliderCell.swift rename to iOS/Settings/TimelineCustomizerCell.swift index b55aa4dc1..42bce8efd 100644 --- a/iOS/Settings/ModernTimelineSliderCell.swift +++ b/iOS/Settings/TimelineCustomizerCell.swift @@ -1,5 +1,5 @@ // -// ModernTimelineSliderCell.swift +// TimelineCustomizerCell.swift // NetNewsWire-iOS // // Created by Stuart Breckenridge on 21/08/2025. @@ -13,44 +13,9 @@ enum SliderConfiguration { case iconSize } -final class ModernTimelineSliderCell: UITableViewCell { +final class TimelineCustomizerCell: UICollectionViewCell { @IBOutlet var slider: UISlider! - - private let container = UIView() - - override func awakeFromNib() { - MainActor.assumeIsolated { - super.awakeFromNib() - setup() - } - } - - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - setup() - } - - required init?(coder: NSCoder) { - super.init(coder: coder) - setup() - } - - private func setup() { - container.layer.cornerRadius = contentView.frame.height/2 - container.backgroundColor = .systemBackground - container.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(container) - contentView.sendSubviewToBack(container) - - NSLayoutConstraint.activate([ - container.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0), - container.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 0), - container.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16), - container.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16) - ]) - contentView.backgroundColor = .systemGroupedBackground - } - + var sliderConfiguration: SliderConfiguration! { didSet { switch sliderConfiguration { @@ -69,7 +34,7 @@ final class ModernTimelineSliderCell: UITableViewCell { } } } - + @IBAction func sliderValueChanges(_ sender: Any) { switch sliderConfiguration { case .numberOfLines: @@ -81,5 +46,12 @@ final class ModernTimelineSliderCell: UITableViewCell { return } } - + + override func updateConfiguration(using state: UICellConfigurationState) { + var backgroundConfig = UIBackgroundConfiguration.listCell().updated(for: state) + backgroundConfig.backgroundColor = .secondarySystemBackground + backgroundConfig.cornerRadius = 20 + self.backgroundConfiguration = backgroundConfig + } + } diff --git a/iOS/Settings/TimelineCustomizerCollectionViewController.swift b/iOS/Settings/TimelineCustomizerCollectionViewController.swift new file mode 100644 index 000000000..49ff48752 --- /dev/null +++ b/iOS/Settings/TimelineCustomizerCollectionViewController.swift @@ -0,0 +1,183 @@ +// +// TimelineCustomizerCollectionViewController.swift +// NetNewsWire-iOS +// +// Created by Stuart Breckenridge on 27/01/2026. +// Copyright © 2026 Ranchero Software. All rights reserved. +// + +import UIKit +import Articles + +class TimelineCustomizerCollectionViewController: UICollectionViewController { + private var previewArticle: Article { + var components = DateComponents() + components.year = 1954 + components.month = 7 + components.day = 29 + + let calendar = Calendar.current + let date = calendar.date(from: components)! + + return Article(accountID: "_testID", + articleID: "_testArticleID", + feedID: "_testFeedID", + uniqueID: UUID().uuidString, + title: "At The Sign Of The Prancing Pony", + contentHTML: nil, + contentText: "Bree was the chief village of Bree-land, a small country a few miles broad whose chief claim to fame was its aluminum siding industry. The Men of Bree were cheerful and independant: they belonged to nobody but themselves. In the lands beyond Bree there were mysterious wanderers.", + markdown: nil, + url: nil, + externalURL: nil, + summary: nil, + imageURL: nil, + datePublished: date, + dateModified: nil, + authors: Set([Author(authorID: "_testAuthorID", name: "J. R. R. Tolkien", url: nil, avatarURL: nil, emailAddress: nil)!]), + status: ArticleStatus(articleID: "_testArticleID", read: false, starred: false, dateArrived: .now)) + } + + private var cachedTimelineLines: Int = AppDefaults.shared.timelineNumberOfLines + private var cachedIconSize: IconSize = AppDefaults.shared.timelineIconSize + + override func viewDidLoad() { + super.viewDidLoad() + title = NSLocalizedString("Timeline Customizer", comment: "Timeline Customizer") + + NotificationCenter.default.addObserver(forName: UserDefaults.didChangeNotification, object: nil, queue: .main) { [weak self] _ in + guard let self = self else { return } + Task { @MainActor in + + if AppDefaults.shared.timelineNumberOfLines != self.cachedTimelineLines { + self.cachedTimelineLines = AppDefaults.shared.timelineNumberOfLines + self.userDefaultsDidChange() + } + + if AppDefaults.shared.timelineIconSize != self.cachedIconSize { + self.cachedIconSize = AppDefaults.shared.timelineIconSize + self.userDefaultsDidChange() + } + } + } + + configureCollectionView() + } + + private func configureCollectionView() { + collectionView.register( + TimelineHeaderView.self, + forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, + withReuseIdentifier: TimelineHeaderView.reuseIdentifier + ) + + var config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) + config.showsSeparators = false + config.headerMode = .supplementary + + let layout = UICollectionViewCompositionalLayout.list(using: config) + + collectionView.setCollectionViewLayout(layout, animated: false) + } + + // MARK: UICollectionViewDataSource + + override func numberOfSections(in collectionView: UICollectionView) -> Int { + return 4 + } + + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + // #warning Incomplete implementation, return the number of items + return 1 + } + + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + + if indexPath.section == 0 { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "IconSizeSelector", for: indexPath) as! TimelineCustomizerCell + cell.sliderConfiguration = .iconSize + return cell + } + + if indexPath.section == 1 { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NumberOfLinesSelector", for: indexPath) as! TimelineCustomizerCell + cell.sliderConfiguration = .numberOfLines + return cell + } + + if indexPath.section == 2 { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainTimelineCellStandard", for: indexPath) as! MainTimelineCollectionViewCell + cell.cellData = MainTimelineCellData(article: previewArticle, + showFeedName: .byline, + feedName: "The Fellowship of the Ring", + byline: "J. R. R. Tolkien", + iconImage: IconImage(Assets.Images.nnwFeedIcon), + showIcon: false, + numberOfLines: AppDefaults.shared.timelineNumberOfLines, + iconSize: AppDefaults.shared.timelineIconSize) + cell.isPreview = true + return cell + } + + if indexPath.section == 3 { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainTimelineCellIcon", for: indexPath) as! MainTimelineCollectionViewCell + cell.cellData = MainTimelineCellData(article: previewArticle, + showFeedName: .byline, + feedName: "The Fellowship of the Ring", + byline: "J. R. R. Tolkien", + iconImage: IconImage(Assets.Images.nnwFeedIcon), + showIcon: true, + numberOfLines: AppDefaults.shared.timelineNumberOfLines, + iconSize: AppDefaults.shared.timelineIconSize) + cell.isPreview = true + return cell + } + + + + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainTimelineCellStandard", for: indexPath) + return cell + } + + // MARK: UICollectionViewDelegate + + override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath + ) -> UICollectionReusableView { + + guard kind == UICollectionView.elementKindSectionHeader else { + return UICollectionReusableView() + } + + let header = collectionView.dequeueReusableSupplementaryView( + ofKind: kind, + withReuseIdentifier: TimelineHeaderView.reuseIdentifier, + for: indexPath + ) as! TimelineHeaderView + + switch indexPath.section { + case 0: + header.label.text = NSLocalizedString("Icon Size", comment: "Icon Size") + case 1: + header.label.text = NSLocalizedString("Number of Lines", comment: "Number of Lines") + case 2: + header.label.text = NSLocalizedString("No Icon Preview", comment: "No Icon Preview") + case 3: + header.label.text = NSLocalizedString("Icon Preview", comment: "Icon Preview") + default: + header.label.text = NSLocalizedString("", comment: "") + } + return header + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int + ) -> CGSize { + CGSize(width: collectionView.bounds.width, height: 50) + } + + + // MARK: Notifications + + func userDefaultsDidChange() { + collectionView.reloadSections([2,3]) + } + +} diff --git a/iOS/Settings/TimelineCustomizerTableViewController.swift b/iOS/Settings/TimelineCustomizerTableViewController.swift deleted file mode 100644 index 06acd6a79..000000000 --- a/iOS/Settings/TimelineCustomizerTableViewController.swift +++ /dev/null @@ -1,132 +0,0 @@ -// -// TimelineCustomizerTableViewController.swift -// NetNewsWire-iOS -// -// Created by Stuart Breckenridge on 21/08/2025. -// Copyright © 2025 Ranchero Software. All rights reserved. -// - -import UIKit -import Articles - -final class TimelineCustomizerTableViewController: UITableViewController { - private var previewArticle: Article { - var components = DateComponents() - components.year = 1954 - components.month = 7 - components.day = 29 - - let calendar = Calendar.current - let date = calendar.date(from: components)! - - return Article(accountID: "_testID", - articleID: "_testArticleID", - feedID: "_testFeedID", - uniqueID: UUID().uuidString, - title: "At The Sign Of The Prancing Pony", - contentHTML: nil, - contentText: "Bree was the chief village of Bree-land, a small country a few miles broad whose chief claim to fame was its aluminum siding industry. The Men of Bree were cheerful and independant: they belonged to nobody but themselves. In the lands beyond Bree there were mysterious wanderers.", - markdown: nil, - url: nil, - externalURL: nil, - summary: nil, - imageURL: nil, - datePublished: date, - dateModified: nil, - authors: Set([Author(authorID: "_testAuthorID", name: "J. R. R. Tolkien", url: nil, avatarURL: nil, emailAddress: nil)!]), - status: ArticleStatus(articleID: "_testArticleID", read: false, starred: false, dateArrived: .now)) - } - - override func viewDidLoad() { - super.viewDidLoad() - title = NSLocalizedString("Timeline Customizer", comment: "Timeline Customizer") - - NotificationCenter.default.addObserver(forName: UserDefaults.didChangeNotification, object: nil, queue: .main) { [weak self] _ in - Task { @MainActor in - self?.userDefaultsDidChange() - } - } - } - - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - tableView.reloadSections(IndexSet(integer: 2), with: .fade) - } - - // MARK: - Table view data source - - override func numberOfSections(in tableView: UITableView) -> Int { - return 4 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 1 - } - - override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - if section == 0 { return NSLocalizedString("Icon Size", comment: "Icon Size")} - if section == 1 { return NSLocalizedString("Number of Lines", comment: "Number of Lines")} - if section == 2 { return NSLocalizedString("Preview with Icon", comment: "Previews") } - if section == 3 { return NSLocalizedString("Preview without Icon", comment: "Previews") } - return nil - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - - if indexPath.section == 0 { - let cell = tableView.dequeueReusableCell(withIdentifier: "IconSizeCell") as! ModernTimelineSliderCell - cell.sliderConfiguration = .iconSize - return cell - } - - if indexPath.section == 1 { - let cell = tableView.dequeueReusableCell(withIdentifier: "NumberOfLinesCell") as! ModernTimelineSliderCell - cell.sliderConfiguration = .numberOfLines - return cell - } - - if indexPath.section == 2 { - let cell = tableView.dequeueReusableCell(withIdentifier: MainTimelineModernViewController.CellIdentifier.icon) as! MainTimelineCell - cell.cellData = MainTimelineCellData(article: previewArticle, - showFeedName: .byline, - feedName: "The Fellowship of the Ring", - byline: "J. R. R. Tolkien", - iconImage: IconImage(Assets.Images.nnwFeedIcon), - showIcon: true, - numberOfLines: AppDefaults.shared.timelineNumberOfLines, - iconSize: AppDefaults.shared.timelineIconSize) - cell.isPreview = true - return cell - } - - if indexPath.section == 3 { - let cell = tableView.dequeueReusableCell(withIdentifier: MainTimelineModernViewController.CellIdentifier.standard) as! MainTimelineCell - cell.cellData = MainTimelineCellData(article: previewArticle, - showFeedName: .byline, - feedName: "The Fellowship of the Ring", - byline: "J. R. R. Tolkien", - iconImage: nil, - showIcon: false, - numberOfLines: AppDefaults.shared.timelineNumberOfLines, - iconSize: AppDefaults.shared.timelineIconSize) - cell.isPreview = true - return cell - } - - return UITableViewCell() - - } - - override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { - return nil - } - - override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { - return false - } - - // MARK: - Notifications - - func userDefaultsDidChange() { - tableView.reloadSections(IndexSet(integersIn: 2...3), with: .none) - } -} diff --git a/iOS/Settings/TimelineHeaderView.swift b/iOS/Settings/TimelineHeaderView.swift new file mode 100644 index 000000000..598e62d9b --- /dev/null +++ b/iOS/Settings/TimelineHeaderView.swift @@ -0,0 +1,36 @@ +// +// TimelineHeaderView.swift +// NetNewsWire +// +// Created by Stuart Breckenridge on 27/01/2026. +// Copyright © 2026 Ranchero Software. All rights reserved. +// + + +final class TimelineHeaderView: UICollectionReusableView { + static let reuseIdentifier = "TimelineHeaderView" + + let label = UILabel() + + override init(frame: CGRect) { + super.init(frame: frame) + + label.translatesAutoresizingMaskIntoConstraints = false + label.font = .preferredFont(forTextStyle: .headline) + label.textColor = .label + + addSubview(label) + + NSLayoutConstraint.activate([ + label.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor), + label.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor), + label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, constant: 8), + label.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, constant: -8) + ]) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} +