Revised settings views

Notes:
- A lot of representable shims over UIKit view controllers. These misbehave a little. They should be re-written in SwiftUI.
- Settings no longer uses VibrantTableViewCell
- Changes to AppDefaults trigger objectWillSend
This commit is contained in:
Stuart Breckenridge
2022-11-12 19:50:13 +08:00
parent 35440ba542
commit c8306c8660
12 changed files with 636 additions and 52 deletions

View File

@@ -7,6 +7,8 @@
//
import UIKit
import Combine
import SwiftUI
enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable {
case automatic = 0
@@ -26,7 +28,7 @@ enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable {
}
final class AppDefaults {
final class AppDefaults: ObservableObject {
static let defaultThemeName = "Default"
@@ -85,6 +87,7 @@ final class AppDefaults {
}
set {
setInt(for: Key.userInterfaceColorPalette, newValue.rawValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -94,6 +97,7 @@ final class AppDefaults {
}
set {
AppDefaults.setString(for: Key.addWebFeedAccountID, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -103,6 +107,7 @@ final class AppDefaults {
}
set {
AppDefaults.setString(for: Key.addWebFeedFolderName, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -112,6 +117,7 @@ final class AppDefaults {
}
set {
AppDefaults.setString(for: Key.addFolderAccountID, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -121,6 +127,7 @@ final class AppDefaults {
}
set {
UserDefaults.standard.set(newValue, forKey: Key.activeExtensionPointIDs)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -130,6 +137,7 @@ final class AppDefaults {
}
set {
UserDefaults.standard.set(newValue, forKey: Key.hasUsedFullScreenPreviously)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -139,6 +147,7 @@ final class AppDefaults {
}
set {
UserDefaults.standard.setValue(newValue, forKey: Key.useSystemBrowser)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -148,6 +157,7 @@ final class AppDefaults {
}
set {
AppDefaults.setDate(for: Key.lastImageCacheFlushDate, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -157,6 +167,7 @@ final class AppDefaults {
}
set {
AppDefaults.setBool(for: Key.timelineGroupByFeed, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -166,6 +177,7 @@ final class AppDefaults {
}
set {
AppDefaults.setBool(for: Key.refreshClearsReadArticles, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -175,15 +187,33 @@ final class AppDefaults {
}
set {
AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
/// This is a `Bool` wrapper for `timelineSortDirection`'s
/// `ComparisonResult`
var timelineSortDirectionBool: Bool {
get {
if AppDefaults.shared.timelineSortDirection == .orderedAscending {
return true
}
return false
}
set {
if newValue == true { timelineSortDirection = .orderedAscending } else {
timelineSortDirection = .orderedDescending
}
}
}
var articleFullscreenEnabled: Bool {
get {
return AppDefaults.bool(for: Key.articleFullscreenEnabled)
}
set {
AppDefaults.setBool(for: Key.articleFullscreenEnabled, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -193,6 +223,7 @@ final class AppDefaults {
}
set {
AppDefaults.setBool(for: Key.confirmMarkAllAsRead, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -202,6 +233,7 @@ final class AppDefaults {
}
set {
AppDefaults.setDate(for: Key.lastRefresh, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -211,6 +243,7 @@ final class AppDefaults {
}
set {
AppDefaults.setInt(for: Key.timelineNumberOfLines, newValue)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -221,6 +254,7 @@ final class AppDefaults {
}
set {
AppDefaults.store.set(newValue.rawValue, forKey: Key.timelineIconDimension)
AppDefaults.shared.objectWillChange.send()
}
}
@@ -230,6 +264,7 @@ final class AppDefaults {
}
set {
AppDefaults.setString(for: Key.currentThemeName, newValue)
AppDefaults.shared.objectWillChange.send()
}
}