diff --git a/iOS/Settings/ModernTimelineCustomizerTableViewController.swift b/iOS/Settings/ModernTimelineCustomizerTableViewController.swift new file mode 100644 index 000000000..45677d747 --- /dev/null +++ b/iOS/Settings/ModernTimelineCustomizerTableViewController.swift @@ -0,0 +1,130 @@ +// +// ModernTimelineCustomizerTableViewController.swift +// NetNewsWire-iOS +// +// Created by Stuart Breckenridge on 21/08/2025. +// Copyright © 2025 Ranchero Software. All rights reserved. +// + +import UIKit +import Articles + +class ModernTimelineCustomizerTableViewController: UITableViewController { + + + private var previewArticle: Article { + var components = DateComponents() + components.year = 1925 + components.month = 4 + components.day = 10 + + let calendar = Calendar.current + let date = calendar.date(from: components)! + + return Article(accountID: "_testID", + articleID: "_testArticleID", + webFeedID: "_testWebFeedID", + uniqueID: UUID().uuidString, + title: "Chapter 1", + contentHTML: nil, + contentText: "In my younger and more vulnerable years my father gave me some advice that I’ve been turning over in my mind ever since. 'Whenever you feel like criticizing any one,' he told me, 'just remember that all the people in this world haven’t had the advantages that you’ve had.'", + url: nil, + externalURL: nil, + summary: nil, + imageURL: nil, + datePublished: date, + dateModified: nil, + authors: Set([Author(authorID: "_testAuthorID", name: "F. Scott Fitzgerald", 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(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil) + + } + + + 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 3 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + if section == 2 { return 2 } + 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")} + return NSLocalizedString("Previews", comment: "Previews") + } + + + 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 && indexPath.row == 0 { + let cell = tableView.dequeueReusableCell(withIdentifier: "MainTimelineIconFeedCell") as? MainTimelineIconFeedCell ?? MainTimelineIconFeedCell() + cell.cellData = MainTimelineCellData(article: previewArticle, + showFeedName: .byline, + feedName: "The Great Gatsby", + byline: "F. Scott Fitzgerald", + iconImage: IconImage(UIImage(named: "nnwFeedIcon")!), + showIcon: true, + numberOfLines: AppDefaults.shared.timelineNumberOfLines, + iconSize: AppDefaults.shared.timelineIconSize) + return cell + } + + if indexPath.section == 2 && indexPath.row == 1 { + let cell = tableView.dequeueReusableCell(withIdentifier: "MainTimelineFeedCell") as? MainTimelineFeedCell ?? MainTimelineFeedCell() + cell.cellData = MainTimelineCellData(article: previewArticle, + showFeedName: .byline, + feedName: "The Great Gatsby", + byline: "F. Scott Fitzgerald", + iconImage: nil, + showIcon: false, + numberOfLines: AppDefaults.shared.timelineNumberOfLines, + iconSize: AppDefaults.shared.timelineIconSize) + 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 + @objc func userDefaultsDidChange(_ note: Notification) { + tableView.reloadSections(IndexSet(integer: 2), with: .none) + } + +} + diff --git a/iOS/Settings/ModernTimelineSliderCell.swift b/iOS/Settings/ModernTimelineSliderCell.swift new file mode 100644 index 000000000..9098149aa --- /dev/null +++ b/iOS/Settings/ModernTimelineSliderCell.swift @@ -0,0 +1,63 @@ +// +// ModernTimelineSliderCell.swift +// NetNewsWire-iOS +// +// Created by Stuart Breckenridge on 21/08/2025. +// Copyright © 2025 Ranchero Software. All rights reserved. +// + +import UIKit + +enum SliderConfiguration { + case numberOfLines + case iconSize +} + +class ModernTimelineSliderCell: UITableViewCell { + + + @IBOutlet weak var slider: UISlider! + + var sliderConfiguration: SliderConfiguration! { + didSet { + switch sliderConfiguration { + case .numberOfLines: + slider.minimumValue = 1 + slider.maximumValue = 6 + slider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 6) + slider.value = Float(AppDefaults.shared.timelineNumberOfLines) + case .iconSize: + slider.minimumValue = 1 + slider.maximumValue = 3 + slider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 3) + slider.value = Float(AppDefaults.shared.timelineIconSize.rawValue) + case .none: + return + } + } + } + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + @IBAction func sliderValueChanges(_ sender: Any) { + switch sliderConfiguration { + case .numberOfLines: + AppDefaults.shared.timelineNumberOfLines = Int(slider.value.rounded()) + case .iconSize: + guard let iconSize = IconSize(rawValue: Int(slider.value.rounded())) else { return } + AppDefaults.shared.timelineIconSize = iconSize + case .none: + return + } + } + +} diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 2257bc692..34efb01b5 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -1,10 +1,11 @@ - + - + + @@ -578,6 +579,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -730,109 +947,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -849,46 +963,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -973,9 +1047,6 @@ - - - @@ -983,13 +1054,10 @@ - - - - + - + diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index 77753225a..3ab94f412 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -196,7 +196,7 @@ class SettingsViewController: UITableViewController { case 3: switch indexPath.row { case 3: - let timeline = UIStoryboard.settings.instantiateController(ofType: TimelineCustomizerViewController.self) + let timeline = UIStoryboard.settings.instantiateController(ofType: ModernTimelineCustomizerTableViewController.self) self.navigationController?.pushViewController(timeline, animated: true) default: break diff --git a/iOS/Settings/TimelineCustomizerViewController.swift b/iOS/Settings/TimelineCustomizerViewController.swift deleted file mode 100644 index 68c1f72d5..000000000 --- a/iOS/Settings/TimelineCustomizerViewController.swift +++ /dev/null @@ -1,95 +0,0 @@ -// -// TimelineCustomizerViewController.swift -// NetNewsWire-iOS -// -// Created by Maurice Parker on 11/8/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import UIKit - -class TimelineCustomizerViewController: UIViewController { - - @IBOutlet weak var iconSizeSliderContainerView: UIView! - @IBOutlet weak var iconSizeModernSlider: UISlider! - - @IBOutlet weak var numberOfLinesSliderContainerView: UIView! - @IBOutlet weak var numberOfLinesModernSlider: UISlider! - - @IBOutlet weak var previewWidthConstraint: NSLayoutConstraint! - @IBOutlet weak var previewHeightConstraint: NSLayoutConstraint! - - @IBOutlet weak var previewContainerView: UIView! - var previewController: TimelinePreviewTableViewController { - return children.first as! TimelinePreviewTableViewController - } - - override func viewDidLoad() { - super.viewDidLoad() - - iconSizeModernSlider.minimumValue = 1 - iconSizeModernSlider.maximumValue = 3 - iconSizeModernSlider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 3) - iconSizeModernSlider.value = Float(AppDefaults.shared.timelineIconSize.rawValue) - iconSizeSliderContainerView.layer.cornerRadius = 10 - - numberOfLinesModernSlider.minimumValue = 1 - numberOfLinesModernSlider.maximumValue = 6 - numberOfLinesModernSlider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 6) - numberOfLinesModernSlider.value = Float(AppDefaults.shared.timelineNumberOfLines) - numberOfLinesSliderContainerView.layer.cornerRadius = 10 - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - updatePreviewBorder() - updatePreview() - } - - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - updatePreviewBorder() - updatePreview() - } - - @IBAction func iconSizeChanged(_ sender: Any) { - guard let iconSize = IconSize(rawValue: Int(iconSizeModernSlider.value.rounded())) else { return } - AppDefaults.shared.timelineIconSize = iconSize - updatePreview() - } - - @IBAction func numberOfLinesChanged(_ sender: Any) { - AppDefaults.shared.timelineNumberOfLines = Int(numberOfLinesModernSlider.value.rounded()) - updatePreview() - } - -} - -// MARK: Private - -private extension TimelineCustomizerViewController { - - func updatePreview() { - let previewWidth: CGFloat = { - if traitCollection.userInterfaceIdiom == .phone { - return view.bounds.width - } else { - return view.bounds.width / 1.5 - } - }() - - previewWidthConstraint.constant = previewWidth - previewHeightConstraint.constant = previewController.heightFor(width: previewWidth) - - previewController.reload() - } - - func updatePreviewBorder() { - if traitCollection.userInterfaceStyle == .dark { - previewContainerView.layer.borderColor = UIColor.black.cgColor - previewContainerView.layer.borderWidth = 1 - } else { - previewContainerView.layer.borderWidth = 0 - } - } - -} diff --git a/iOS/Settings/TimelinePreviewTableViewController.swift b/iOS/Settings/TimelinePreviewTableViewController.swift deleted file mode 100644 index e53158ae2..000000000 --- a/iOS/Settings/TimelinePreviewTableViewController.swift +++ /dev/null @@ -1,77 +0,0 @@ -// -// TimelinePreviewTableViewController.swift -// NetNewsWire-iOS -// -// Created by Maurice Parker on 11/8/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import UIKit -import Articles - -class TimelinePreviewTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { - - @IBOutlet weak var tableView: UITableView! - - override func viewDidLoad() { - super.viewDidLoad() - - tableView.delegate = self - tableView.dataSource = self - - } - - func heightFor(width: CGFloat) -> CGFloat { - if UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory { - let layout = MainTimelineAccessibilityCellLayout(width: width, insets: tableView.safeAreaInsets, cellData: prototypeCellData) - return layout.height - } else { - let layout = MainTimelineDefaultCellLayout(width: width, insets: tableView.safeAreaInsets, cellData: prototypeCellData) - return layout.height - } - } - - // MARK: - Table view data source - - func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 1 - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MainTimelineTableViewCell - cell.cellData = prototypeCellData - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.selectRow(at: nil, animated: true, scrollPosition: .none) - } - // MARK: API - - func reload() { - tableView.reloadData() - } - -} - -// MARK: Private - -private extension TimelinePreviewTableViewController { - - var prototypeCellData: MainTimelineCellData { - let longTitle = "Enim ut tellus elementum sagittis vitae et. Nibh praesent tristique magna sit amet purus gravida quis blandit. Neque volutpat ac tincidunt vitae semper quis lectus nulla. Massa id neque aliquam vestibulum morbi blandit. Ultrices vitae auctor eu augue. Enim eu turpis egestas pretium aenean pharetra magna. Eget gravida cum sociis natoque. Sit amet consectetur adipiscing elit. Auctor eu augue ut lectus arcu bibendum. Maecenas volutpat blandit aliquam etiam erat velit. Ut pharetra sit amet aliquam id diam maecenas ultricies. In hac habitasse platea dictumst quisque sagittis purus sit amet." - - let prototypeID = "prototype" - let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) - let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, webFeedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) - - let iconImage = IconImage(AppAssets.faviconTemplateImage.withTintColor(AppAssets.secondaryAccentColor)) - - return MainTimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Feed Name", byline: nil, iconImage: iconImage, showIcon: true, numberOfLines: AppDefaults.shared.timelineNumberOfLines, iconSize: AppDefaults.shared.timelineIconSize) - } - -}