pull/1415/head
gedoor 3 years ago
parent e711093efe
commit b264ff2f05
  1. 9
      app/src/main/java/io/legado/app/base/AppContextWrapper.kt
  2. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 22
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  4. 2
      app/src/main/res/values-es-rES/strings.xml
  5. 2
      app/src/main/res/values-ja-rJP/strings.xml
  6. 2
      app/src/main/res/values-pt-rBR/strings.xml
  7. 2
      app/src/main/res/values-zh-rHK/strings.xml
  8. 2
      app/src/main/res/values-zh-rTW/strings.xml
  9. 2
      app/src/main/res/values-zh/strings.xml
  10. 2
      app/src/main/res/values/strings.xml
  11. 7
      app/src/main/res/xml/pref_config_theme.xml

@ -6,6 +6,7 @@ import android.content.res.Resources
import android.os.Build import android.os.Build
import android.os.LocaleList 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.getPrefString import io.legado.app.utils.getPrefString
import java.util.* import java.util.*
@ -13,13 +14,17 @@ import java.util.*
object AppContextWrapper { object AppContextWrapper {
fun wrap(context: Context): Context { fun wrap(context: Context): Context {
var fontScale = context.getPrefInt(PreferKey.fontScale) / 10f
if (fontScale !in 1f..2f) {
fontScale = Configuration().fontScale
}
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
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)
configuration.setLocale(targetLocale) configuration.setLocale(targetLocale)
configuration.setLocales(LocaleList(targetLocale)) configuration.setLocales(LocaleList(targetLocale))
configuration.fontScale = 1f configuration.fontScale = fontScale
context.createConfigurationContext(configuration) context.createConfigurationContext(configuration)
} else { } else {
val resources: Resources = context.resources val resources: Resources = context.resources
@ -27,7 +32,7 @@ object AppContextWrapper {
val configuration: Configuration = resources.configuration val configuration: Configuration = resources.configuration
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
configuration.locale = targetLocale configuration.locale = targetLocale
configuration.fontScale = 1f configuration.fontScale = fontScale
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
resources.updateConfiguration(configuration, resources.displayMetrics) resources.updateConfiguration(configuration, resources.displayMetrics)
context context

@ -2,6 +2,7 @@ package io.legado.app.constant
object PreferKey { object PreferKey {
const val language = "language" const val language = "language"
const val fontScale = "fontScale"
const val themeMode = "themeMode" const val themeMode = "themeMode"
const val userAgent = "userAgent" const val userAgent = "userAgent"
const val showUnread = "showUnread" const val showUnread = "showUnread"

@ -56,6 +56,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage)) upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage))
upPreferenceSummary(PreferKey.bgImageN, getPrefString(PreferKey.bgImageN)) upPreferenceSummary(PreferKey.bgImageN, getPrefString(PreferKey.bgImageN))
upPreferenceSummary(PreferKey.barElevation, AppConfig.elevation.toString()) upPreferenceSummary(PreferKey.barElevation, AppConfig.elevation.toString())
upPreferenceSummary(PreferKey.fontScale)
findPreference<ColorPreference>(PreferKey.cBackground)?.let { findPreference<ColorPreference>(PreferKey.cBackground)?.let {
it.onSaveColor = { color -> it.onSaveColor = { color ->
if (!ColorUtils.isColorLight(color)) { if (!ColorUtils.isColorLight(color)) {
@ -152,6 +153,18 @@ class ThemeConfigFragment : BasePreferenceFragment(),
AppConfig.elevation = it AppConfig.elevation = it
recreateActivities() recreateActivities()
} }
PreferKey.fontScale -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.font_scale))
.setMaxValue(20)
.setMinValue(10)
.setCustomButton((R.string.btn_default_s)) {
putPrefInt(PreferKey.fontScale, 0)
recreateActivities()
}
.show {
putPrefInt(PreferKey.fontScale, it)
recreateActivities()
}
PreferKey.bgImage -> selectBgAction(false) PreferKey.bgImage -> selectBgAction(false)
PreferKey.bgImageN -> selectBgAction(true) PreferKey.bgImageN -> selectBgAction(true)
"themeList" -> ThemeListDialog().show(childFragmentManager, "themeList") "themeList" -> ThemeListDialog().show(childFragmentManager, "themeList")
@ -257,11 +270,18 @@ class ThemeConfigFragment : BasePreferenceFragment(),
postEvent(EventBus.RECREATE, "") postEvent(EventBus.RECREATE, "")
} }
private fun upPreferenceSummary(preferenceKey: String, value: String?) { private fun upPreferenceSummary(preferenceKey: String, value: String? = null) {
val preference = findPreference<Preference>(preferenceKey) ?: return val preference = findPreference<Preference>(preferenceKey) ?: return
when (preferenceKey) { when (preferenceKey) {
PreferKey.barElevation -> preference.summary = PreferKey.barElevation -> preference.summary =
getString(R.string.bar_elevation_s, value) getString(R.string.bar_elevation_s, value)
PreferKey.fontScale -> {
var fontScale = getPrefInt(PreferKey.fontScale) / 10f
if (fontScale !in 1f..2f) {
fontScale = resources.configuration.fontScale
}
preference.summary = getString(R.string.font_scale_summary, fontScale)
}
PreferKey.bgImage, PreferKey.bgImage,
PreferKey.bgImageN -> preference.summary = if (value.isNullOrBlank()) { PreferKey.bgImageN -> preference.summary = if (value.isNullOrBlank()) {
getString(R.string.select_image) getString(R.string.select_image)

@ -900,5 +900,7 @@
<string name="del_login_header">删除登录头</string> <string name="del_login_header">删除登录头</string>
<string name="show_login_header">查看登录头</string> <string name="show_login_header">查看登录头</string>
<string name="login_header">登录头</string> <string name="login_header">登录头</string>
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</string>
</resources> </resources>

@ -904,5 +904,7 @@
<string name="del_login_header">删除登录头</string> <string name="del_login_header">删除登录头</string>
<string name="show_login_header">查看登录头</string> <string name="show_login_header">查看登录头</string>
<string name="login_header">登录头</string> <string name="login_header">登录头</string>
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</string>
</resources> </resources>

@ -904,5 +904,7 @@
<string name="del_login_header">删除登录头</string> <string name="del_login_header">删除登录头</string>
<string name="show_login_header">查看登录头</string> <string name="show_login_header">查看登录头</string>
<string name="login_header">登录头</string> <string name="login_header">登录头</string>
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</string>
</resources> </resources>

@ -901,5 +901,7 @@
<string name="del_login_header">删除登录头</string> <string name="del_login_header">删除登录头</string>
<string name="show_login_header">查看登录头</string> <string name="show_login_header">查看登录头</string>
<string name="login_header">登录头</string> <string name="login_header">登录头</string>
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</string>
</resources> </resources>

@ -903,5 +903,7 @@
<string name="del_login_header">删除登录头</string> <string name="del_login_header">删除登录头</string>
<string name="show_login_header">查看登录头</string> <string name="show_login_header">查看登录头</string>
<string name="login_header">登录头</string> <string name="login_header">登录头</string>
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</string>
</resources> </resources>

@ -903,5 +903,7 @@
<string name="del_login_header">删除登录头</string> <string name="del_login_header">删除登录头</string>
<string name="show_login_header">查看登录头</string> <string name="show_login_header">查看登录头</string>
<string name="login_header">登录头</string> <string name="login_header">登录头</string>
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</string>
</resources> </resources>

@ -904,5 +904,7 @@
<string name="del_login_header">删除登录头</string> <string name="del_login_header">删除登录头</string>
<string name="show_login_header">查看登录头</string> <string name="show_login_header">查看登录头</string>
<string name="login_header">登录头</string> <string name="login_header">登录头</string>
<string name="font_scale">字体大小</string>
<string name="font_scale_summary">当前字体大小:%.1f</string>
</resources> </resources>

@ -33,6 +33,13 @@
android:title="@string/bar_elevation" android:title="@string/bar_elevation"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference
android:defaultValue="true"
android:key="fontScale"
android:summary="@string/font_scale_summary"
android:title="@string/font_scale"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:defaultValue="false" android:defaultValue="false"
android:key="coverConfig" android:key="coverConfig"

Loading…
Cancel
Save