Simplify code.

This commit is contained in:
Brent Simmons 2025-01-26 21:12:15 -08:00
parent 2f12d9f803
commit 1bfd0ee12c

View File

@ -55,36 +55,15 @@ final class SettingsViewController: UITableViewController {
timelineSortOrderSwitch.isOn = false timelineSortOrderSwitch.isOn = false
} }
if AppDefaults.timelineGroupByFeed { groupByFeedSwitch.isOn = AppDefaults.timelineGroupByFeed
groupByFeedSwitch.isOn = true refreshClearsReadArticlesSwitch.isOn = AppDefaults.refreshClearsReadArticles
} else { confirmMarkAllAsReadSwitch.isOn = AppDefaults.confirmMarkAllAsRead
groupByFeedSwitch.isOn = false showFullscreenArticlesSwitch.isOn = AppDefaults.articleFullscreenAvailable
} openLinksInNetNewsWire.isOn = !AppDefaults.useSystemBrowser
if AppDefaults.refreshClearsReadArticles {
refreshClearsReadArticlesSwitch.isOn = true
} else {
refreshClearsReadArticlesSwitch.isOn = false
}
articleThemeDetailLabel.text = ArticleThemesManager.shared.currentTheme.name articleThemeDetailLabel.text = ArticleThemesManager.shared.currentTheme.name
if AppDefaults.confirmMarkAllAsRead {
confirmMarkAllAsReadSwitch.isOn = true
} else {
confirmMarkAllAsReadSwitch.isOn = false
}
if AppDefaults.articleFullscreenAvailable {
showFullscreenArticlesSwitch.isOn = true
} else {
showFullscreenArticlesSwitch.isOn = false
}
colorPaletteDetailLabel.text = String(describing: AppDefaults.userInterfaceColorPalette) colorPaletteDetailLabel.text = String(describing: AppDefaults.userInterfaceColorPalette)
openLinksInNetNewsWire.isOn = !AppDefaults.useSystemBrowser
let buildLabel = NonIntrinsicLabel(frame: CGRect(x: 32.0, y: 0.0, width: 0.0, height: 0.0)) let buildLabel = NonIntrinsicLabel(frame: CGRect(x: 32.0, y: 0.0, width: 0.0, height: 0.0))
buildLabel.font = UIFont.systemFont(ofSize: 11.0) buildLabel.font = UIFont.systemFont(ofSize: 11.0)
buildLabel.textColor = UIColor.gray buildLabel.textColor = UIColor.gray
@ -96,7 +75,6 @@ final class SettingsViewController: UITableViewController {
wrapperView.translatesAutoresizingMaskIntoConstraints = false wrapperView.translatesAutoresizingMaskIntoConstraints = false
wrapperView.addSubview(buildLabel) wrapperView.addSubview(buildLabel)
tableView.tableFooterView = wrapperView tableView.tableFooterView = wrapperView
} }
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
@ -107,7 +85,6 @@ final class SettingsViewController: UITableViewController {
tableView.scrollToRow(at: IndexPath(row: 0, section: 4), at: .top, animated: true) tableView.scrollToRow(at: IndexPath(row: 0, section: 4), at: .top, animated: true)
scrollToArticlesSection = false scrollToArticlesSection = false
} }
} }
// MARK: UITableView // MARK: UITableView
@ -150,7 +127,6 @@ final class SettingsViewController: UITableViewController {
} }
default: default:
cell = super.tableView(tableView, cellForRowAt: indexPath) cell = super.tableView(tableView, cellForRowAt: indexPath)
} }
return cell return cell
@ -234,23 +210,23 @@ final class SettingsViewController: UITableViewController {
} }
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return false false
} }
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return false false
} }
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle { override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .none .none
} }
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension UITableView.automaticDimension
} }
override func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath) -> Int { override func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath) -> Int {
return super.tableView(tableView, indentationLevelForRowAt: IndexPath(row: 0, section: 1)) super.tableView(tableView, indentationLevelForRowAt: IndexPath(row: 0, section: 1))
} }
// MARK: Actions // MARK: Actions
@ -260,51 +236,27 @@ final class SettingsViewController: UITableViewController {
} }
@IBAction func switchTimelineOrder(_ sender: Any) { @IBAction func switchTimelineOrder(_ sender: Any) {
if timelineSortOrderSwitch.isOn { AppDefaults.timelineSortDirection = timelineSortOrderSwitch.isOn ? .orderedAscending : .orderedDescending
AppDefaults.timelineSortDirection = .orderedAscending
} else {
AppDefaults.timelineSortDirection = .orderedDescending
}
} }
@IBAction func switchGroupByFeed(_ sender: Any) { @IBAction func switchGroupByFeed(_ sender: Any) {
if groupByFeedSwitch.isOn { AppDefaults.timelineGroupByFeed = groupByFeedSwitch.isOn
AppDefaults.timelineGroupByFeed = true
} else {
AppDefaults.timelineGroupByFeed = false
}
} }
@IBAction func switchClearsReadArticles(_ sender: Any) { @IBAction func switchClearsReadArticles(_ sender: Any) {
if refreshClearsReadArticlesSwitch.isOn { AppDefaults.refreshClearsReadArticles = refreshClearsReadArticlesSwitch.isOn
AppDefaults.refreshClearsReadArticles = true
} else {
AppDefaults.refreshClearsReadArticles = false
}
} }
@IBAction func switchConfirmMarkAllAsRead(_ sender: Any) { @IBAction func switchConfirmMarkAllAsRead(_ sender: Any) {
if confirmMarkAllAsReadSwitch.isOn { AppDefaults.confirmMarkAllAsRead = confirmMarkAllAsReadSwitch.isOn
AppDefaults.confirmMarkAllAsRead = true
} else {
AppDefaults.confirmMarkAllAsRead = false
}
} }
@IBAction func switchFullscreenArticles(_ sender: Any) { @IBAction func switchFullscreenArticles(_ sender: Any) {
if showFullscreenArticlesSwitch.isOn { AppDefaults.articleFullscreenAvailable = showFullscreenArticlesSwitch.isOn
AppDefaults.articleFullscreenAvailable = true
} else {
AppDefaults.articleFullscreenAvailable = false
}
} }
@IBAction func switchBrowserPreference(_ sender: Any) { @IBAction func switchBrowserPreference(_ sender: Any) {
if openLinksInNetNewsWire.isOn { AppDefaults.useSystemBrowser = !openLinksInNetNewsWire.isOn
AppDefaults.useSystemBrowser = false
} else {
AppDefaults.useSystemBrowser = true
}
} }
// MARK: Notifications // MARK: Notifications
@ -324,7 +276,6 @@ final class SettingsViewController: UITableViewController {
@objc func browserPreferenceDidChange() { @objc func browserPreferenceDidChange() {
tableView.reloadData() tableView.reloadData()
} }
} }
// MARK: OPML Document Picker // MARK: OPML Document Picker
@ -345,7 +296,6 @@ extension SettingsViewController: UIDocumentPickerDelegate {
} }
} }
} }
} }
// MARK: Private // MARK: Private
@ -463,5 +413,4 @@ private extension SettingsViewController {
vc.modalPresentationStyle = .pageSheet vc.modalPresentationStyle = .pageSheet
present(vc, animated: true) present(vc, animated: true)
} }
} }