pull/32/head
kunfei 5 years ago
parent 8aaf5bf36a
commit 116a64f90c
  1. 29
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 21
      app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt

@ -42,21 +42,7 @@ object ReadBookConfig {
} }
fun upBg() { fun upBg() {
getConfig().apply { bg = getConfig().bgDrawable()
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"))
}
}
}
}
}
} }
fun save() { fun save() {
@ -113,5 +99,18 @@ object ReadBookConfig {
fun textColor(): Int { fun textColor(): Int {
return Color.parseColor(textColor) 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"))
}
} }
} }

@ -8,6 +8,7 @@ import android.view.ViewGroup
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
@ -79,7 +80,25 @@ class ReadStyleDialog : DialogFragment() {
tv_bg2.setTextColor(ReadBookConfig.getConfig(2).textColor()) tv_bg2.setTextColor(ReadBookConfig.getConfig(2).textColor())
tv_bg3.setTextColor(ReadBookConfig.getConfig(3).textColor()) tv_bg3.setTextColor(ReadBookConfig.getConfig(3).textColor())
tv_bg4.setTextColor(ReadBookConfig.getConfig(4).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() { private fun upBg() {

Loading…
Cancel
Save