2025-08-21 12:10:43 +08:00
//
2026-01-02 10:30:01 -08:00
// TimelineCustomizerTableViewController.swift
2025-08-21 12:10:43 +08:00
// NetNewsWire-iOS
//
// Created by Stuart Breckenridge on 21/08/2025.
// Copyright © 2025 Ranchero Software. All rights reserved.
//
import UIKit
import Articles
2026-01-02 10:30:01 -08:00
final class TimelineCustomizerTableViewController : UITableViewController {
2025-08-21 12:10:43 +08:00
private var previewArticle : Article {
var components = DateComponents ()
2026-01-23 22:24:20 +08:00
components . year = 1954
components . month = 7
components . day = 29
2025-08-21 12:10:43 +08:00
let calendar = Calendar . current
let date = calendar . date ( from : components ) !
2025-11-05 11:22:10 -08:00
2025-08-21 12:10:43 +08:00
return Article ( accountID : "_testID" ,
articleID : "_testArticleID" ,
2025-11-02 15:57:33 -08:00
feedID : "_testFeedID" ,
2025-08-21 12:10:43 +08:00
uniqueID : UUID (). uuidString ,
2026-01-23 22:24:20 +08:00
title : "At The Sign Of The Prancing Pony" ,
2025-08-21 12:10:43 +08:00
contentHTML : nil ,
2026-01-23 22:24:20 +08:00
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." ,
2025-11-01 17:03:53 -07:00
markdown : nil ,
2025-08-21 12:10:43 +08:00
url : nil ,
externalURL : nil ,
summary : nil ,
imageURL : nil ,
datePublished : date ,
dateModified : nil ,
2026-01-23 22:24:20 +08:00
authors : Set ([ Author ( authorID : "_testAuthorID" , name : "J. R. R. Tolkien" , url : nil , avatarURL : nil , emailAddress : nil ) ! ]),
2025-08-21 12:10:43 +08:00
status : ArticleStatus ( articleID : "_testArticleID" , read : false , starred : false , dateArrived : . now ))
}
2025-11-05 11:22:10 -08:00
2025-08-21 12:10:43 +08:00
override func viewDidLoad () {
super . viewDidLoad ()
title = NSLocalizedString ( "Timeline Customizer" , comment : "Timeline Customizer" )
2025-11-05 11:22:10 -08:00
2025-11-18 20:22:48 -08:00
NotificationCenter . default . addObserver ( forName : UserDefaults . didChangeNotification , object : nil , queue : . main ) { [ weak self ] _ in
Task { @ MainActor in
self ?. userDefaultsDidChange ()
}
}
2025-08-21 12:10:43 +08:00
}
override func traitCollectionDidChange ( _ previousTraitCollection : UITraitCollection ?) {
tableView . reloadSections ( IndexSet ( integer : 2 ), with : . fade )
}
// MARK: - Table view data source
override func numberOfSections ( in tableView : UITableView ) -> Int {
2025-08-22 08:22:54 +08:00
return 4
2025-08-21 12:10:43 +08:00
}
override func tableView ( _ tableView : UITableView , numberOfRowsInSection section : Int ) -> Int {
return 1
}
2025-11-05 11:22:10 -08:00
2025-08-21 12:10:43 +08:00
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" )}
2025-08-22 08:22:54 +08:00
if section == 2 { return NSLocalizedString ( "Preview with Icon" , comment : "Previews" ) }
if section == 3 { return NSLocalizedString ( "Preview without Icon" , comment : "Previews" ) }
return nil
2025-08-21 12:10:43 +08:00
}
override func tableView ( _ tableView : UITableView , cellForRowAt indexPath : IndexPath ) -> UITableViewCell {
2026-01-23 09:30:49 -08:00
2026-01-23 22:24:20 +08:00
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 {
2026-01-25 14:49:34 +08:00
let cell = tableView . dequeueReusableCell ( withIdentifier : MainTimelineModernViewController . CellIdentifier . icon ) as ! MainTimelineCell
2026-01-23 22:24:20 +08:00
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 {
2026-01-25 14:49:34 +08:00
let cell = tableView . dequeueReusableCell ( withIdentifier : MainTimelineModernViewController . CellIdentifier . standard ) as ! MainTimelineCell
2026-01-23 22:24:20 +08:00
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
}
2025-11-05 11:22:10 -08:00
2025-08-21 12:10:43 +08:00
return UITableViewCell ()
2025-11-05 11:22:10 -08:00
2025-08-21 12:10:43 +08:00
}
2025-11-05 11:22:10 -08:00
2025-08-21 12:10:43 +08:00
override func tableView ( _ tableView : UITableView , willSelectRowAt indexPath : IndexPath ) -> IndexPath ? {
return nil
}
override func tableView ( _ tableView : UITableView , shouldHighlightRowAt indexPath : IndexPath ) -> Bool {
return false
}
2025-11-05 11:22:10 -08:00
2025-08-21 12:10:43 +08:00
// MARK: - Notifications
2025-11-18 20:22:48 -08:00
func userDefaultsDidChange () {
2025-08-22 08:22:54 +08:00
tableView . reloadSections ( IndexSet ( integersIn : 2. .. 3 ), with : . none )
2025-08-21 12:10:43 +08:00
}
}