diff --git a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt index ace52897c..e04af5b86 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.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) { diff --git a/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt index 01a012bc5..8394e0fce 100644 --- a/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt @@ -38,7 +38,6 @@ object ThemeConfig { } fun applyDayNight(context: Context) { - ReadBookConfig.upBg() applyTheme(context) initNightMode() BookCover.upDefaultCover() diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index c507cb2cf..1ca3712d9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -984,7 +984,6 @@ class ReadBookActivity : BaseReadBookActivity(), } BG_COLOR -> { setCurBg(0, "#${color.hexString}") - ReadBookConfig.upBg() postEvent(EventBus.UP_CONFIG, false) } TIP_COLOR -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt index 81cacd945..1dfb26983 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index e1cd8a329..4105d7ea5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index eca08ee46..840c80bd3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 9f1fd01ed..13bc4c849 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index c96eb6fed..350436c5a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -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() {