diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 588889e40..cea83752d 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -42,21 +42,7 @@ object ReadBookConfig { } fun upBg() { - getConfig().apply { - when (bgType) { - 0 -> bg = ColorDrawable(Color.parseColor(bgStr)) - 1 -> bg = Drawable.createFromStream(App.INSTANCE.assets.open("bg" + File.separator + bgStr), "bg") - else -> { - try { - bg = Drawable.createFromPath(bgStr) - } finally { - bg ?: let { - bg = ColorDrawable(Color.parseColor("#015A86")) - } - } - } - } - } + bg = getConfig().bgDrawable() } fun save() { @@ -113,5 +99,18 @@ object ReadBookConfig { fun textColor(): Int { return Color.parseColor(textColor) } + + fun bgDrawable(): Drawable { + var bgDrawable: Drawable? = null + when (bgType) { + 0 -> bgDrawable = ColorDrawable(Color.parseColor(bgStr)) + 1 -> bgDrawable = + Drawable.createFromStream(App.INSTANCE.assets.open("bg" + File.separator + bgStr), "bg") + else -> runCatching { + bgDrawable = Drawable.createFromPath(bgStr) + } + } + return bgDrawable ?: ColorDrawable(Color.parseColor("#015A86")) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt index efa6d7c14..080e6ff54 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt @@ -8,6 +8,7 @@ import android.view.ViewGroup import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.constant.Bus +import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.primaryTextColor @@ -79,7 +80,25 @@ class ReadStyleDialog : DialogFragment() { tv_bg2.setTextColor(ReadBookConfig.getConfig(2).textColor()) tv_bg3.setTextColor(ReadBookConfig.getConfig(3).textColor()) tv_bg4.setTextColor(ReadBookConfig.getConfig(4).textColor()) - + for (i in 0..4) { + val iv = when (i) { + 1 -> bg1 + 2 -> bg2 + 3 -> bg3 + 4 -> bg4 + else -> bg0 + } + ReadBookConfig.getConfig(i).apply { + when (bgType) { + 2 -> { + ImageLoader.load(requireContext(), bgStr) + .centerCrop() + .setAsFile(iv) + } + else -> iv.setImageDrawable(bgDrawable()) + } + } + } } private fun upBg() {