pull/1403/head 3.21.102414
gedoor 3 years ago
parent 637f31a3b7
commit 85afd1b578
  1. 4
      app/src/main/assets/updateLog.md
  2. 21
      app/src/main/java/io/legado/app/base/AppContextWrapper.kt
  3. 6
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -11,6 +11,10 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2021/10/24**
* 修复夜间模式不随系统变化的bug
**2021/10/22** **2021/10/22**
* 修复封面 * 修复封面

@ -8,16 +8,15 @@ import android.os.LocaleList
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.sysConfiguration
import java.util.* import java.util.*
@Suppress("unused")
object AppContextWrapper { object AppContextWrapper {
fun wrap(context: Context): Context { fun wrap(context: Context): Context {
var fontScale = context.getPrefInt(PreferKey.fontScale) / 10f
if (fontScale !in 0.8f..1.6f) {
fontScale = 0f
}
val resources: Resources = context.resources val resources: Resources = context.resources
val configuration: Configuration = resources.configuration val configuration: Configuration = resources.configuration
val targetLocale = getSetLocale(context) val targetLocale = getSetLocale(context)
@ -28,20 +27,28 @@ object AppContextWrapper {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
configuration.locale = targetLocale configuration.locale = targetLocale
} }
configuration.fontScale = fontScale configuration.fontScale = getFontScale(context)
return context.createConfigurationContext(configuration) return context.createConfigurationContext(configuration)
} }
fun getFontScale(context: Context): Float {
var fontScale = context.getPrefInt(PreferKey.fontScale) / 10f
if (fontScale !in 0.8f..1.6f) {
fontScale = sysConfiguration.fontScale
}
return fontScale
}
/** /**
* 当前系统语言 * 当前系统语言
*/ */
private fun getSystemLocale(): Locale { private fun getSystemLocale(): Locale {
val locale: Locale val locale: Locale
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //7.0有多语言设置获取顶部的语言 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //7.0有多语言设置获取顶部的语言
locale = Resources.getSystem().configuration.locales.get(0) locale = sysConfiguration.locales.get(0)
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
locale = Resources.getSystem().configuration.locale locale = sysConfiguration.locale
} }
return locale return locale
} }

@ -12,6 +12,7 @@ import android.view.View
import android.widget.SeekBar import android.widget.SeekBar
import androidx.preference.Preference import androidx.preference.Preference
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.AppContextWrapper
import io.legado.app.base.BasePreferenceFragment import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
@ -277,10 +278,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
PreferKey.barElevation -> preference.summary = PreferKey.barElevation -> preference.summary =
getString(R.string.bar_elevation_s, value) getString(R.string.bar_elevation_s, value)
PreferKey.fontScale -> { PreferKey.fontScale -> {
var fontScale = getPrefInt(PreferKey.fontScale) / 10f val fontScale = AppContextWrapper.getFontScale(requireContext())
if (fontScale !in 0.8f..1.6f) {
fontScale = resources.configuration.fontScale
}
preference.summary = getString(R.string.font_scale_summary, fontScale) preference.summary = getString(R.string.font_scale_summary, fontScale)
} }
PreferKey.bgImage, PreferKey.bgImage,

Loading…
Cancel
Save