优化
This commit is contained in:
@@ -37,7 +37,6 @@ object ReadBookConfig {
|
|||||||
if (shareLayout) {
|
if (shareLayout) {
|
||||||
shareConfig = value
|
shareConfig = value
|
||||||
}
|
}
|
||||||
upBg()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var bg: Drawable? = null
|
var bg: Drawable? = null
|
||||||
@@ -88,11 +87,8 @@ object ReadBookConfig {
|
|||||||
shareConfig = c ?: configList.getOrNull(5) ?: Config()
|
shareConfig = c ?: configList.getOrNull(5) ?: Config()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun upBg() {
|
fun upBg(width: Int, height: Int) {
|
||||||
val resources = appCtx.resources
|
val tmp = bg
|
||||||
val dm = resources.displayMetrics
|
|
||||||
val width = dm.widthPixels
|
|
||||||
val height = dm.heightPixels
|
|
||||||
bg = durConfig.curBgDrawable(width, height).apply {
|
bg = durConfig.curBgDrawable(width, height).apply {
|
||||||
if (this is BitmapDrawable) {
|
if (this is BitmapDrawable) {
|
||||||
bgMeanColor = bitmap.getMeanColor()
|
bgMeanColor = bitmap.getMeanColor()
|
||||||
@@ -100,6 +96,7 @@ object ReadBookConfig {
|
|||||||
bgMeanColor = color
|
bgMeanColor = color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(tmp as? BitmapDrawable)?.bitmap?.recycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun save() {
|
fun save() {
|
||||||
@@ -123,7 +120,6 @@ object ReadBookConfig {
|
|||||||
if (styleSelect > 0) {
|
if (styleSelect > 0) {
|
||||||
styleSelect -= 1
|
styleSelect -= 1
|
||||||
}
|
}
|
||||||
upBg()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -572,11 +568,11 @@ object ReadBookConfig {
|
|||||||
1 -> {
|
1 -> {
|
||||||
val path = "bg" + File.separator + curBgStr()
|
val path = "bg" + File.separator + curBgStr()
|
||||||
val bitmap = BitmapUtils.decodeAssetsBitmap(appCtx, path, width, height)
|
val bitmap = BitmapUtils.decodeAssetsBitmap(appCtx, path, width, height)
|
||||||
BitmapDrawable(resources, bitmap)
|
BitmapDrawable(resources, bitmap?.changeSize(width, height))
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val bitmap = BitmapUtils.decodeBitmap(curBgStr(), width, height)
|
val bitmap = BitmapUtils.decodeBitmap(curBgStr(), width, height)
|
||||||
BitmapDrawable(resources, bitmap)
|
BitmapDrawable(resources, bitmap?.changeSize(width, height))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: OutOfMemoryError) {
|
} catch (e: OutOfMemoryError) {
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ object ThemeConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun applyDayNight(context: Context) {
|
fun applyDayNight(context: Context) {
|
||||||
ReadBookConfig.upBg()
|
|
||||||
applyTheme(context)
|
applyTheme(context)
|
||||||
initNightMode()
|
initNightMode()
|
||||||
BookCover.upDefaultCover()
|
BookCover.upDefaultCover()
|
||||||
|
|||||||
@@ -984,7 +984,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
}
|
}
|
||||||
BG_COLOR -> {
|
BG_COLOR -> {
|
||||||
setCurBg(0, "#${color.hexString}")
|
setCurBg(0, "#${color.hexString}")
|
||||||
ReadBookConfig.upBg()
|
|
||||||
postEvent(EventBus.UP_CONFIG, false)
|
postEvent(EventBus.UP_CONFIG, false)
|
||||||
}
|
}
|
||||||
TIP_COLOR -> {
|
TIP_COLOR -> {
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class BgAdapter(context: Context, val textColor: Int) :
|
|||||||
this.setOnClickListener {
|
this.setOnClickListener {
|
||||||
getItemByLayoutPosition(holder.layoutPosition)?.let {
|
getItemByLayoutPosition(holder.layoutPosition)?.let {
|
||||||
ReadBookConfig.durConfig.setCurBg(1, it)
|
ReadBookConfig.durConfig.setCurBg(1, it)
|
||||||
ReadBookConfig.upBg()
|
|
||||||
postEvent(EventBus.UP_CONFIG, false)
|
postEvent(EventBus.UP_CONFIG, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,7 +358,6 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
|||||||
inputStream.copyTo(outputStream)
|
inputStream.copyTo(outputStream)
|
||||||
}
|
}
|
||||||
ReadBookConfig.durConfig.setCurBg(2, file.absolutePath)
|
ReadBookConfig.durConfig.setCurBg(2, file.absolutePath)
|
||||||
ReadBookConfig.upBg()
|
|
||||||
postEvent(EventBus.UP_CONFIG, false)
|
postEvent(EventBus.UP_CONFIG, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,6 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
|
|||||||
val oldIndex = ReadBookConfig.styleSelect
|
val oldIndex = ReadBookConfig.styleSelect
|
||||||
if (index != oldIndex) {
|
if (index != oldIndex) {
|
||||||
ReadBookConfig.styleSelect = index
|
ReadBookConfig.styleSelect = index
|
||||||
ReadBookConfig.upBg()
|
|
||||||
upView()
|
upView()
|
||||||
styleAdapter.notifyItemChanged(oldIndex)
|
styleAdapter.notifyItemChanged(oldIndex)
|
||||||
styleAdapter.notifyItemChanged(index)
|
styleAdapter.notifyItemChanged(index)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.legado.app.ui.book.read.page
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.core.view.isGone
|
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 {
|
fun upStyle() = binding.run {
|
||||||
upTipStyle()
|
upTipStyle()
|
||||||
ReadBookConfig.let {
|
ReadBookConfig.let {
|
||||||
@@ -197,9 +201,9 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setBg(bg: Drawable?) {
|
fun upBg() {
|
||||||
binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor
|
binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor
|
||||||
binding.vwBg.background = bg
|
binding.vwBg.background = ReadBookConfig.bg
|
||||||
upBgAlpha()
|
upBgAlpha()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -486,12 +486,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun upBg() {
|
fun upBg() {
|
||||||
ReadBookConfig.bg ?: let {
|
ReadBookConfig.upBg(width, height)
|
||||||
ReadBookConfig.upBg()
|
curPage.upBg()
|
||||||
}
|
prevPage.upBg()
|
||||||
curPage.setBg(ReadBookConfig.bg)
|
nextPage.upBg()
|
||||||
prevPage.setBg(ReadBookConfig.bg)
|
|
||||||
nextPage.setBg(ReadBookConfig.bg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun upBgAlpha() {
|
fun upBgAlpha() {
|
||||||
|
|||||||
Reference in New Issue
Block a user