@@ -122,19 +122,28 @@ object ColorManager {
122
122
}
123
123
124
124
/* *
125
- * 切换到指定配色,切换成功后写入 AppPrefs
125
+ * 切换到指定配色后,写入 AppPrefs
126
126
* @param colorSchemeId 配色 id
127
127
* */
128
128
fun setColorScheme (colorSchemeId : String ) {
129
+ switchColorScheme(colorSchemeId)
130
+ selectedColor = colorSchemeId
131
+ prefs.selectedColor = colorSchemeId
132
+ }
133
+
134
+ /* *
135
+ * 切换到指定配色
136
+ * @param colorSchemeId 配色 id
137
+ * */
138
+ private fun switchColorScheme (colorSchemeId : String ) {
129
139
if (! presetColorSchemes.containsKey(colorSchemeId)) {
130
140
Timber .w(" Color scheme %s not found" , colorSchemeId)
131
141
return
132
142
}
133
143
Timber .d(" switch color scheme from %s to %s" , selectedColor, colorSchemeId)
134
- selectedColor = colorSchemeId
135
144
// 刷新配色
136
145
val isFirst = currentColors.isEmpty()
137
- refreshColorValues()
146
+ refreshColorValues(colorSchemeId )
138
147
if (isNightMode) {
139
148
lastDarkColorSchemeId = colorSchemeId
140
149
} else {
@@ -148,15 +157,14 @@ object ColorManager {
148
157
Timber .d(" Initialization finished" )
149
158
}
150
159
}
151
- prefs.selectedColor = colorSchemeId
152
160
if (! isFirst) fireChange()
153
161
}
154
162
155
163
/* * 切换深色/亮色模式 */
156
164
private fun switchNightMode (isNightMode : Boolean ) {
157
165
this .isNightMode = isNightMode
158
166
val newId = getColorSchemeId()
159
- if (newId != null ) setColorScheme (newId)
167
+ if (newId != null ) switchColorScheme (newId)
160
168
Timber .d(
161
169
" System changing color, current ColorScheme: $selectedColor , isDarkMode=$isNightMode " ,
162
170
)
@@ -185,9 +193,9 @@ object ColorManager {
185
193
return selectedColor
186
194
}
187
195
188
- private fun refreshColorValues () {
196
+ private fun refreshColorValues (colorSchemeId : String ) {
189
197
currentColors.clear()
190
- val colorMap = presetColorSchemes[selectedColor ]
198
+ val colorMap = presetColorSchemes[colorSchemeId ]
191
199
colorMap?.forEach { (key, value) ->
192
200
when (key) {
193
201
" name" , " author" , " light_scheme" , " dark_scheme" , " sound" -> {}
0 commit comments