pull/1403/head
gedoor 3 years ago
parent 607e837d50
commit d942aeca12
  1. 5
      app/src/main/java/io/legado/app/App.kt
  2. 1
      app/src/main/java/io/legado/app/base/AppContextWrapper.kt
  3. 2
      app/src/main/java/io/legado/app/help/AppConfig.kt
  4. 14
      app/src/main/java/io/legado/app/utils/ConfigurationExtensions.kt
  5. 9
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -7,7 +7,6 @@ import android.content.res.Configuration
import android.os.Build
import androidx.multidex.MultiDexApplication
import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.base.AppContextWrapper
import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb
@ -38,10 +37,6 @@ class App : MultiDexApplication() {
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
}
override fun attachBaseContext(base: Context) {
super.attachBaseContext(AppContextWrapper.wrap(base))
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) {

@ -25,6 +25,7 @@ object AppContextWrapper {
configuration.setLocale(targetLocale)
configuration.setLocales(LocaleList(targetLocale))
} else {
@Suppress("DEPRECATION")
configuration.locale = targetLocale
}
configuration.fontScale = fontScale

@ -57,7 +57,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
"1" -> false
"2" -> true
"3" -> false
else -> context.sysIsDarkMode()
else -> sysConfiguration.isNightMode
}
}

@ -0,0 +1,14 @@
@file:Suppress("unused")
package io.legado.app.utils
import android.content.res.Configuration
import android.content.res.Resources
val sysConfiguration: Configuration = Resources.getSystem().configuration
val Configuration.isNightMode: Boolean
get() {
val mode = uiMode and Configuration.UI_MODE_NIGHT_MASK
return mode == Configuration.UI_MODE_NIGHT_YES
}

@ -10,7 +10,6 @@ import android.app.Service
import android.content.*
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
@ -250,14 +249,6 @@ fun Context.sendMail(mail: String) {
}
}
/**
* 系统是否暗色主题
*/
fun Context.sysIsDarkMode(): Boolean {
val mode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return mode == Configuration.UI_MODE_NIGHT_YES
}
/**
* 获取电量
*/

Loading…
Cancel
Save