fix: 背景图片
This commit is contained in:
4 files changed
+16
-16
No files matched your search
@@ -7,7 +7,7 @@ import android.content.res.Configuration
|
|||||||
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.ui.config.themeConfig.ThemeConfig
|
||||||
import io.legado.app.utils.getPrefString
|
import io.legado.app.utils.getPrefString
|
||||||
import io.legado.app.utils.sysConfiguration
|
import io.legado.app.utils.sysConfiguration
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -42,7 +42,7 @@ object AppContextWrapper {
|
|||||||
|
|
||||||
|
|
||||||
fun getFontScale(context: Context): Float {
|
fun getFontScale(context: Context): Float {
|
||||||
var fontScale = context.getPrefInt(PreferKey.fontScale) / 10f
|
var fontScale = ThemeConfig.fontScale / 10f
|
||||||
if (fontScale !in 0.8f..1.6f) {
|
if (fontScale !in 0.8f..1.6f) {
|
||||||
fontScale = sysConfiguration.fontScale
|
fontScale = sysConfiguration.fontScale
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -853,10 +853,10 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val hasLightBg: Boolean
|
val hasLightBg: Boolean
|
||||||
get() = !appCtx.getPrefString(PreferKey.bgImage).isNullOrEmpty()
|
get() = !ThemeConfig.bgImageLight.isNullOrEmpty()
|
||||||
|
|
||||||
val hasDarkBg: Boolean
|
val hasDarkBg: Boolean
|
||||||
get() = !appCtx.getPrefString(PreferKey.bgImageN).isNullOrEmpty()
|
get() = !ThemeConfig.bgImageDark.isNullOrEmpty()
|
||||||
|
|
||||||
val hasImageBg: Boolean
|
val hasImageBg: Boolean
|
||||||
get() = hasLightBg && hasDarkBg
|
get() = hasLightBg && hasDarkBg
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ object ThemeConfigStore {
|
|||||||
fun getBgImage(context: Context, metrics: DisplayMetrics): Bitmap? {
|
fun getBgImage(context: Context, metrics: DisplayMetrics): Bitmap? {
|
||||||
val bgCfg = when (getTheme()) {
|
val bgCfg = when (getTheme()) {
|
||||||
Theme.Light -> Pair(
|
Theme.Light -> Pair(
|
||||||
context.getPrefString(PreferKey.bgImage),
|
ThemeConfig.bgImageLight,
|
||||||
context.getPrefInt(PreferKey.bgImageBlurring, 0)
|
ThemeConfig.bgImageBlurring
|
||||||
)
|
)
|
||||||
|
|
||||||
Theme.Dark -> Pair(
|
Theme.Dark -> Pair(
|
||||||
context.getPrefString(PreferKey.bgImageN),
|
ThemeConfig.bgImageDark,
|
||||||
context.getPrefInt(PreferKey.bgImageNBlurring, 0)
|
ThemeConfig.bgImageNBlurring
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
@@ -146,13 +146,13 @@ object ThemeConfigStore {
|
|||||||
* 清理无用背景图片
|
* 清理无用背景图片
|
||||||
*/
|
*/
|
||||||
fun clearBg() {
|
fun clearBg() {
|
||||||
val bgImagePath = appCtx.getPrefString(PreferKey.bgImage)
|
val bgImagePath = ThemeConfig.bgImageLight
|
||||||
appCtx.externalFiles.getFile(PreferKey.bgImage).listFiles()?.forEach {
|
appCtx.externalFiles.getFile(PreferKey.bgImage).listFiles()?.forEach {
|
||||||
if (it.absolutePath != bgImagePath) {
|
if (it.absolutePath != bgImagePath) {
|
||||||
it.delete()
|
it.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val bgImageNPath = appCtx.getPrefString(PreferKey.bgImageN)
|
val bgImageNPath = ThemeConfig.bgImageDark
|
||||||
appCtx.externalFiles.getFile(PreferKey.bgImageN).listFiles()?.forEach {
|
appCtx.externalFiles.getFile(PreferKey.bgImageN).listFiles()?.forEach {
|
||||||
if (it.absolutePath != bgImageNPath) {
|
if (it.absolutePath != bgImageNPath) {
|
||||||
it.delete()
|
it.delete()
|
||||||
@@ -184,9 +184,9 @@ object ThemeConfigStore {
|
|||||||
val bBackground =
|
val bBackground =
|
||||||
context.getPrefInt(PreferKey.cBBackground, context.getCompatColor(R.color.md_grey_200))
|
context.getPrefInt(PreferKey.cBBackground, context.getCompatColor(R.color.md_grey_200))
|
||||||
val bgImgPath =
|
val bgImgPath =
|
||||||
context.getPrefString(PreferKey.bgImage)
|
ThemeConfig.bgImageLight
|
||||||
val bgImgBlur =
|
val bgImgBlur =
|
||||||
context.getPrefInt(PreferKey.bgImageBlurring, 0)
|
ThemeConfig.bgImageBlurring
|
||||||
|
|
||||||
return Config(
|
return Config(
|
||||||
themeName = name,
|
themeName = name,
|
||||||
@@ -216,9 +216,9 @@ object ThemeConfigStore {
|
|||||||
val bBackground =
|
val bBackground =
|
||||||
context.getPrefInt(PreferKey.cNBBackground, context.getCompatColor(R.color.md_grey_850))
|
context.getPrefInt(PreferKey.cNBBackground, context.getCompatColor(R.color.md_grey_850))
|
||||||
val bgImgPath =
|
val bgImgPath =
|
||||||
context.getPrefString(PreferKey.bgImageN)
|
ThemeConfig.bgImageDark
|
||||||
val bgImgBlur =
|
val bgImgBlur =
|
||||||
context.getPrefInt(PreferKey.bgImageNBlurring, 0)
|
ThemeConfig.bgImageNBlurring
|
||||||
return Config(
|
return Config(
|
||||||
themeName = name,
|
themeName = name,
|
||||||
isNightTheme = true,
|
isNightTheme = true,
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co
|
|||||||
holder.card.setOnClickListener {
|
holder.card.setOnClickListener {
|
||||||
if (value != currentValue) {
|
if (value != currentValue) {
|
||||||
if (value == "13") {
|
if (value == "13") {
|
||||||
val hasLightBg = !appCtx.getPrefString(PreferKey.bgImage).isNullOrEmpty()
|
val hasLightBg = !ThemeConfig.bgImageLight.isNullOrEmpty()
|
||||||
val hasDarkBg = !appCtx.getPrefString(PreferKey.bgImageN).isNullOrEmpty()
|
val hasDarkBg = !ThemeConfig.bgImageDark.isNullOrEmpty()
|
||||||
if (!hasLightBg || !hasDarkBg) {
|
if (!hasLightBg || !hasDarkBg) {
|
||||||
context.toastOnUi(R.string.transparent_theme_alarm)
|
context.toastOnUi(R.string.transparent_theme_alarm)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
|||||||
Reference in new issue
Block a user