Skip to content

Commit e12599b

Browse files
committed
修复深色模式没有跟随系统切换
1 parent 534484d commit e12599b

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

app/src/main/java/remix/myplayer/data/prefs/ThemePrefs.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package remix.myplayer.data.prefs
22

33
import android.content.Context
44
import android.content.res.Configuration
5-
import android.content.res.Resources
65
import androidx.core.graphics.toColorInt
76
import dagger.hilt.android.qualifiers.ApplicationContext
87
import javax.inject.Inject
@@ -32,8 +31,12 @@ class ThemePrefs @Inject constructor(
3231

3332
var coloredNaviBar by PrefsDelegate(sp, PrefKeys.Theme.COLOR_NAVIGATION, false)
3433

35-
fun resolveTheme(darkTheme: String, blackTheme: Boolean): String {
36-
return if (darkTheme == ALWAYS_ON || (darkTheme == FOLLOW_SYSTEM && (Resources.getSystem().configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES)) {
34+
fun resolveTheme(
35+
darkTheme: String,
36+
blackTheme: Boolean,
37+
uiMode: Int = context.resources.configuration.uiMode
38+
): String {
39+
return if (darkTheme == ALWAYS_ON || (darkTheme == FOLLOW_SYSTEM && (uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES)) {
3740
if (blackTheme) {
3841
BLACK
3942
} else {

app/src/main/java/remix/myplayer/ui/activity/ComposeActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ComposeActivity : BaseMusicActivity() {
100100

101101
override fun onConfigurationChanged(newConfig: Configuration) {
102102
super.onConfigurationChanged(newConfig)
103-
themeController.onSystemThemeChanged()
103+
themeController.onSystemThemeChanged(newConfig.uiMode)
104104
}
105105

106106
private fun handleIntent() {

app/src/main/java/remix/myplayer/ui/theme/ThemeController.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface ThemeController {
2121

2222
var black: Boolean
2323

24-
fun onSystemThemeChanged()
24+
fun onSystemThemeChanged(uiMode: Int)
2525

2626
fun setColoredNaviBar(colored: Boolean)
2727

@@ -70,11 +70,11 @@ class ThemeControllerImpl @Inject constructor(private val storage: ThemePrefs) :
7070
)
7171
}
7272

73-
override fun onSystemThemeChanged() {
73+
override fun onSystemThemeChanged(uiMode: Int) {
7474
if (storage.darkTheme != FOLLOW_SYSTEM) {
7575
return
7676
}
77-
val resolved = storage.resolveTheme(storage.darkTheme, storage.blackTheme)
77+
val resolved = storage.resolveTheme(storage.darkTheme, storage.blackTheme, uiMode)
7878
if (_currentTheme.value.theme == resolved) {
7979
return
8080
}
@@ -96,4 +96,4 @@ class ThemeControllerImpl @Inject constructor(private val storage: ThemePrefs) :
9696
_currentTheme.value = _currentTheme.value.copy(secondary = color)
9797
}
9898

99-
}
99+
}

0 commit comments

Comments
 (0)