Skip to content

Commit 46b52d3

Browse files
authored
Feature: user-selectable theme (#460)
* Fix #457 - Persist entry sorting preferences across app launches Changed sorting state from @State to @AppStorage in EntriesView to ensure user preferences are saved to UserDefaults. Also made sorting criteria mutually exclusive for a better UX. * Add option to pick theme (light/dark/auto). Moved language files and other resources into a sub-folder to clean up the structure a little. * use #EnvironmentObject
1 parent a2f9e8e commit 46b52d3

File tree

70 files changed

+263
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+263
-25
lines changed

App/Features/Setting/AppSetting.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,28 @@ import SharedLib
44

55
final class AppSetting: ObservableObject {
66
@Published var webFontSizePercent: Double
7+
@Published var theme: Theme
78

89
private var cancellable = Set<AnyCancellable>()
910

1011
init() {
1112
webFontSizePercent = WallabagUserDefaults.webFontSizePercent
13+
theme = Theme(rawValue: WallabagUserDefaults.theme) ?? .auto
1214

1315
$webFontSizePercent
1416
.sink(receiveValue: updateWebFontSizePercent)
1517
.store(in: &cancellable)
18+
19+
$theme
20+
.sink(receiveValue: updateTheme)
21+
.store(in: &cancellable)
1622
}
1723

1824
private func updateWebFontSizePercent(_ value: Double) {
1925
WallabagUserDefaults.webFontSizePercent = value
2026
}
27+
28+
private func updateTheme(_ value: Theme) {
29+
WallabagUserDefaults.theme = value.rawValue
30+
}
2131
}

App/Features/Setting/SettingView.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Factory
12
import SharedLib
23
import SwiftUI
34

@@ -7,9 +8,17 @@ struct SettingView: View {
78
@AppStorage("badge") var badge: Bool = true
89
@AppStorage("defaultMode") var defaultMode: String = RetrieveMode.allArticles.rawValue
910
@AppStorage("itemPerPageDuringSync") var itemPerPageDuringSync: Int = 50
11+
@EnvironmentObject var appSetting: AppSetting
1012

1113
var body: some View {
1214
Form {
15+
Section("Appearance") {
16+
Picker("Theme", selection: $appSetting.theme) {
17+
ForEach(Theme.allCases) { theme in
18+
Text(theme.name).tag(theme)
19+
}
20+
}
21+
}
1322
Section("Entries list") {
1423
Toggle("Show image in list", isOn: $showImageInList)
1524
Picker("Default mode", selection: $defaultMode) {
@@ -35,5 +44,6 @@ struct SettingView: View {
3544
struct SettingView_Previews: PreviewProvider {
3645
static var previews: some View {
3746
SettingView()
47+
.environmentObject(AppSetting())
3848
}
3949
}

App/Lib/Theme.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import SwiftUI
2+
3+
enum Theme: String, CaseIterable, Identifiable {
4+
case auto
5+
case light
6+
case dark
7+
8+
var id: String { rawValue }
9+
10+
var colorScheme: ColorScheme? {
11+
switch self {
12+
case .auto: return nil
13+
case .light: return .light
14+
case .dark: return .dark
15+
}
16+
}
17+
18+
var name: LocalizedStringKey {
19+
switch self {
20+
case .auto: return "Auto"
21+
case .light: return "Light"
22+
case .dark: return "Dark"
23+
}
24+
}
25+
}

App/Assets.xcassets/AppIcon.appiconset/Contents.json renamed to App/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json

File renamed without changes.

App/Assets.xcassets/AppIcon.appiconset/logo-icon-bg-white-lg.jpg renamed to App/Resources/Assets.xcassets/AppIcon.appiconset/logo-icon-bg-white-lg.jpg

File renamed without changes.

App/Assets.xcassets/AppIcon.appiconset/mac1024.png renamed to App/Resources/Assets.xcassets/AppIcon.appiconset/mac1024.png

File renamed without changes.

App/Assets.xcassets/AppIcon.appiconset/mac128.png renamed to App/Resources/Assets.xcassets/AppIcon.appiconset/mac128.png

File renamed without changes.
File renamed without changes.

App/Assets.xcassets/AppIcon.appiconset/mac256.png renamed to App/Resources/Assets.xcassets/AppIcon.appiconset/mac256.png

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)