@@ -122,19 +122,28 @@ object ColorManager {
122122 }
123123
124124 /* *
125- * 切换到指定配色,切换成功后写入 AppPrefs
125+ * 切换到指定配色后,写入 AppPrefs
126126 * @param colorSchemeId 配色 id
127127 * */
128128 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 ) {
129139 if (! presetColorSchemes.containsKey(colorSchemeId)) {
130140 Timber .w(" Color scheme %s not found" , colorSchemeId)
131141 return
132142 }
133143 Timber .d(" switch color scheme from %s to %s" , selectedColor, colorSchemeId)
134- selectedColor = colorSchemeId
135144 // 刷新配色
136145 val isFirst = currentColors.isEmpty()
137- refreshColorValues()
146+ refreshColorValues(colorSchemeId )
138147 if (isNightMode) {
139148 lastDarkColorSchemeId = colorSchemeId
140149 } else {
@@ -148,15 +157,14 @@ object ColorManager {
148157 Timber .d(" Initialization finished" )
149158 }
150159 }
151- prefs.selectedColor = colorSchemeId
152160 if (! isFirst) fireChange()
153161 }
154162
155163 /* * 切换深色/亮色模式 */
156164 private fun switchNightMode (isNightMode : Boolean ) {
157165 this .isNightMode = isNightMode
158166 val newId = getColorSchemeId()
159- if (newId != null ) setColorScheme (newId)
167+ if (newId != null ) switchColorScheme (newId)
160168 Timber .d(
161169 " System changing color, current ColorScheme: $selectedColor , isDarkMode=$isNightMode " ,
162170 )
@@ -185,9 +193,9 @@ object ColorManager {
185193 return selectedColor
186194 }
187195
188- private fun refreshColorValues () {
196+ private fun refreshColorValues (colorSchemeId : String ) {
189197 currentColors.clear()
190- val colorMap = presetColorSchemes[selectedColor ]
198+ val colorMap = presetColorSchemes[colorSchemeId ]
191199 colorMap?.forEach { (key, value) ->
192200 when (key) {
193201 " name" , " author" , " light_scheme" , " dark_scheme" , " sound" -> {}
0 commit comments