-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserPreferencesRepositoryImpl.swift
More file actions
113 lines (93 loc) · 3.79 KB
/
UserPreferencesRepositoryImpl.swift
File metadata and controls
113 lines (93 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// UserPreferencesRepositoryImpl.swift
// DevLog
//
// Created by 최윤진 on 2/25/26.
//
import Foundation
import Combine
final class UserPreferencesRepositoryImpl: UserPreferencesRepository {
private enum Key {
static let theme = "theme"
static let recentQueries = "Search.recentQueries"
static let pushSortOrder = "PushNotification.sortOption"
static let pushTimeFilter = "PushNotification.timeFilter"
static let pushUnreadOnly = "PushNotification.showUnreadOnly"
static let profileHeatmapActivityTypes = "Profile.heatmap.activityTypes"
static let todayDueDateVisibility = "Today.dueDateVisibility"
static let todayFocusVisibility = "Today.focusVisibility"
}
private let store: UserDefaultsStore
private let themeStore: ThemeStore
init(
store: UserDefaultsStore,
themeStore: ThemeStore
) {
self.store = store
self.themeStore = themeStore
themeStore.send(systemTheme())
}
var systemThemePublisher: AnyPublisher<SystemTheme, Never> {
themeStore.themePublisher
}
func systemTheme() -> SystemTheme {
guard let rawValue = store.string(forKey: Key.theme),
let theme = SystemTheme(rawValue: rawValue) else {
return .automatic
}
return theme
}
func setSystemTheme(_ theme: SystemTheme) {
store.setString(theme.rawValue, forKey: Key.theme)
themeStore.send(theme)
}
func recentSearchQueries() -> [String] {
store.stringArray(forKey: Key.recentQueries)
}
func setRecentSearchQueries(_ queries: [String]) {
store.setStringArray(queries, forKey: Key.recentQueries)
}
func pushNotificationSortOrder() -> PushNotificationQuery.SortOrder {
guard let rawValue = store.string(forKey: Key.pushSortOrder) else { return .latest }
return rawValue == "oldest" ? .oldest : .latest
}
func setPushNotificationSortOrder(_ order: PushNotificationQuery.SortOrder) {
let value = order == .oldest ? "oldest" : "latest"
store.setString(value, forKey: Key.pushSortOrder)
}
func pushNotificationTimeFilter() -> PushNotificationQuery.TimeFilter {
let id = store.string(forKey: Key.pushTimeFilter) ?? "none"
return PushNotificationQuery.TimeFilter(id: id)
}
func setPushNotificationTimeFilter(_ filter: PushNotificationQuery.TimeFilter) {
store.setString(filter.id, forKey: Key.pushTimeFilter)
}
func pushNotificationUnreadOnly() -> Bool {
store.bool(forKey: Key.pushUnreadOnly)
}
func setPushNotificationUnreadOnly(_ value: Bool) {
store.setBool(value, forKey: Key.pushUnreadOnly)
}
func profileHeatmapActivityTypes() -> [String] {
store.stringArray(forKey: Key.profileHeatmapActivityTypes)
}
func setProfileHeatmapActivityTypes(_ activityTypes: [String]) {
store.setStringArray(activityTypes, forKey: Key.profileHeatmapActivityTypes)
}
func todayDisplayOptions() -> TodayDisplayOptions {
let dueDateVisibilityRawValue = store.string(forKey: Key.todayDueDateVisibility)
let focusVisibilityRawValue = store.string(forKey: Key.todayFocusVisibility)
return TodayDisplayOptions(
dueDateVisibility: TodayDisplayOptions.DueDateVisibility(
rawValue: dueDateVisibilityRawValue ?? ""
) ?? .all,
focusVisibility: TodayDisplayOptions.FocusVisibility(
rawValue: focusVisibilityRawValue ?? ""
) ?? .all
)
}
func setTodayDisplayOptions(_ options: TodayDisplayOptions) {
store.setString(options.dueDateVisibility.rawValue, forKey: Key.todayDueDateVisibility)
store.setString(options.focusVisibility.rawValue, forKey: Key.todayFocusVisibility)
}
}