正式包移除夜间模式功能

This commit is contained in:
juntao
2022-05-07 09:55:42 +08:00
parent e0bcf947bf
commit aeb7842299
2 changed files with 19 additions and 8 deletions

View File

@ -10,8 +10,13 @@ object NightModeUtils {
* 当前系统是否是深色模式
*/
fun isNightMode(context: Context): Boolean {
val uiMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return uiMode == Configuration.UI_MODE_NIGHT_YES
// 非测试包禁用深色模式
return if (PackageFlavorHelper.IS_TEST_FLAVOR) {
val uiMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
uiMode == Configuration.UI_MODE_NIGHT_YES
} else {
false
}
}
/**
@ -39,13 +44,16 @@ object NightModeUtils {
* @param nightMode 是否是深色模式
*/
fun initNightMode(systemMode: Boolean, nightMode: Boolean) {
if (systemMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
} else {
if (nightMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
// 非测试包禁用深色模式
if (PackageFlavorHelper.IS_TEST_FLAVOR) {
if (systemMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
if (nightMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
}
}
}