pull/1901/head
kunfei 3 years ago
parent 773458f0a9
commit c619dd5177
  1. 14
      app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt
  2. 1
      app/src/main/java/io/legado/app/help/config/ThemeConfig.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt
  5. 1
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  6. 1
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  7. 10
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  8. 10
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt

@ -37,7 +37,6 @@ object ReadBookConfig {
if (shareLayout) {
shareConfig = value
}
upBg()
}
var bg: Drawable? = null
@ -88,11 +87,8 @@ object ReadBookConfig {
shareConfig = c ?: configList.getOrNull(5) ?: Config()
}
fun upBg() {
val resources = appCtx.resources
val dm = resources.displayMetrics
val width = dm.widthPixels
val height = dm.heightPixels
fun upBg(width: Int, height: Int) {
val tmp = bg
bg = durConfig.curBgDrawable(width, height).apply {
if (this is BitmapDrawable) {
bgMeanColor = bitmap.getMeanColor()
@ -100,6 +96,7 @@ object ReadBookConfig {
bgMeanColor = color
}
}
(tmp as? BitmapDrawable)?.bitmap?.recycle()
}
fun save() {
@ -123,7 +120,6 @@ object ReadBookConfig {
if (styleSelect > 0) {
styleSelect -= 1
}
upBg()
return true
}
return false
@ -572,11 +568,11 @@ object ReadBookConfig {
1 -> {
val path = "bg" + File.separator + curBgStr()
val bitmap = BitmapUtils.decodeAssetsBitmap(appCtx, path, width, height)
BitmapDrawable(resources, bitmap)
BitmapDrawable(resources, bitmap?.changeSize(width, height))
}
else -> {
val bitmap = BitmapUtils.decodeBitmap(curBgStr(), width, height)
BitmapDrawable(resources, bitmap)
BitmapDrawable(resources, bitmap?.changeSize(width, height))
}
}
} catch (e: OutOfMemoryError) {

@ -38,7 +38,6 @@ object ThemeConfig {
}
fun applyDayNight(context: Context) {
ReadBookConfig.upBg()
applyTheme(context)
initNightMode()
BookCover.upDefaultCover()

@ -984,7 +984,6 @@ class ReadBookActivity : BaseReadBookActivity(),
}
BG_COLOR -> {
setCurBg(0, "#${color.hexString}")
ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false)
}
TIP_COLOR -> {

@ -41,7 +41,6 @@ class BgAdapter(context: Context, val textColor: Int) :
this.setOnClickListener {
getItemByLayoutPosition(holder.layoutPosition)?.let {
ReadBookConfig.durConfig.setCurBg(1, it)
ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false)
}
}

@ -358,7 +358,6 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
inputStream.copyTo(outputStream)
}
ReadBookConfig.durConfig.setCurBg(2, file.absolutePath)
ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false)
}
}

@ -158,7 +158,6 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
val oldIndex = ReadBookConfig.styleSelect
if (index != oldIndex) {
ReadBookConfig.styleSelect = index
ReadBookConfig.upBg()
upView()
styleAdapter.notifyItemChanged(oldIndex)
styleAdapter.notifyItemChanged(index)

@ -2,7 +2,6 @@ package io.legado.app.ui.book.read.page
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.view.isGone
@ -59,6 +58,11 @@ class PageView(context: Context) : FrameLayout(context) {
}
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
upBg()
}
fun upStyle() = binding.run {
upTipStyle()
ReadBookConfig.let {
@ -197,9 +201,9 @@ class PageView(context: Context) : FrameLayout(context) {
}
}
fun setBg(bg: Drawable?) {
fun upBg() {
binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor
binding.vwBg.background = bg
binding.vwBg.background = ReadBookConfig.bg
upBgAlpha()
}

@ -486,12 +486,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
}
fun upBg() {
ReadBookConfig.bg ?: let {
ReadBookConfig.upBg()
}
curPage.setBg(ReadBookConfig.bg)
prevPage.setBg(ReadBookConfig.bg)
nextPage.setBg(ReadBookConfig.bg)
ReadBookConfig.upBg(width, height)
curPage.upBg()
prevPage.upBg()
nextPage.upBg()
}
fun upBgAlpha() {

Loading…
Cancel
Save