diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 2686f539a..127a497a1 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,6 +11,10 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2021/10/24** + +* 修复夜间模式不随系统变化的bug + **2021/10/22** * 修复封面 diff --git a/app/src/main/java/io/legado/app/base/AppContextWrapper.kt b/app/src/main/java/io/legado/app/base/AppContextWrapper.kt index 9f2f5f0c6..510c262d6 100644 --- a/app/src/main/java/io/legado/app/base/AppContextWrapper.kt +++ b/app/src/main/java/io/legado/app/base/AppContextWrapper.kt @@ -8,16 +8,15 @@ import android.os.LocaleList import io.legado.app.constant.PreferKey import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefString +import io.legado.app.utils.sysConfiguration import java.util.* +@Suppress("unused") object AppContextWrapper { 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 configuration: Configuration = resources.configuration val targetLocale = getSetLocale(context) @@ -28,20 +27,28 @@ object AppContextWrapper { @Suppress("DEPRECATION") configuration.locale = targetLocale } - configuration.fontScale = fontScale + configuration.fontScale = getFontScale(context) 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 { val locale: Locale if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //7.0有多语言设置获取顶部的语言 - locale = Resources.getSystem().configuration.locales.get(0) + locale = sysConfiguration.locales.get(0) } else { @Suppress("DEPRECATION") - locale = Resources.getSystem().configuration.locale + locale = sysConfiguration.locale } return locale } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index ee966b5ca..3d90863ad 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -12,6 +12,7 @@ import android.view.View import android.widget.SeekBar import androidx.preference.Preference import io.legado.app.R +import io.legado.app.base.AppContextWrapper import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus @@ -277,10 +278,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), PreferKey.barElevation -> preference.summary = getString(R.string.bar_elevation_s, value) PreferKey.fontScale -> { - var fontScale = getPrefInt(PreferKey.fontScale) / 10f - if (fontScale !in 0.8f..1.6f) { - fontScale = resources.configuration.fontScale - } + val fontScale = AppContextWrapper.getFontScale(requireContext()) preference.summary = getString(R.string.font_scale_summary, fontScale) } PreferKey.bgImage,