mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
5cef6f8e39
commit
6d8deca130
17
app/src/main/java/io/legado/app/help/PaintPool.kt
Normal file
17
app/src/main/java/io/legado/app/help/PaintPool.kt
Normal file
@ -0,0 +1,17 @@
|
||||
package io.legado.app.help
|
||||
|
||||
import android.graphics.Paint
|
||||
import io.legado.app.utils.objectpool.BaseSafeObjectPool
|
||||
|
||||
object PaintPool : BaseSafeObjectPool<Paint>(8) {
|
||||
|
||||
private val emptyPaint = Paint()
|
||||
|
||||
override fun create(): Paint = Paint()
|
||||
|
||||
override fun recycle(target: Paint) {
|
||||
target.set(emptyPaint)
|
||||
super.recycle(target)
|
||||
}
|
||||
|
||||
}
|
@ -55,7 +55,6 @@ object ThemeConfig {
|
||||
initNightMode()
|
||||
BookCover.upDefaultCover()
|
||||
postEvent(EventBus.RECREATE, "")
|
||||
postEvent(EventBus.UP_CONFIG, arrayOf(2, 9))
|
||||
}
|
||||
|
||||
private fun initNightMode() {
|
||||
@ -74,10 +73,12 @@ object ThemeConfig {
|
||||
context.getPrefString(PreferKey.bgImage),
|
||||
context.getPrefInt(PreferKey.bgImageBlurring, 0)
|
||||
)
|
||||
|
||||
Theme.Dark -> Pair(
|
||||
context.getPrefString(PreferKey.bgImageN),
|
||||
context.getPrefInt(PreferKey.bgImageNBlurring, 0)
|
||||
)
|
||||
|
||||
else -> null
|
||||
} ?: return null
|
||||
if (bgCfg.first.isNullOrBlank()) return null
|
||||
@ -218,6 +219,7 @@ object ThemeConfig {
|
||||
.bottomBackground(Color.WHITE)
|
||||
.apply()
|
||||
}
|
||||
|
||||
AppConfig.isNightTheme -> {
|
||||
val primary =
|
||||
getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
|
||||
@ -238,6 +240,7 @@ object ThemeConfig {
|
||||
.bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
|
||||
.apply()
|
||||
}
|
||||
|
||||
else -> {
|
||||
val primary =
|
||||
getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_brown_500))
|
||||
|
@ -460,6 +460,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
||||
fun onDestroy() {
|
||||
pageDelegate?.onDestroy()
|
||||
curPage.cancelSelect()
|
||||
invalidateTextPage()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities.column
|
||||
|
||||
import android.graphics.Canvas
|
||||
import androidx.annotation.Keep
|
||||
import io.legado.app.help.PaintPool
|
||||
import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.lib.theme.ThemeStore
|
||||
import io.legado.app.ui.book.read.page.ContentTextView
|
||||
@ -42,15 +43,18 @@ data class TextColumn(
|
||||
} else {
|
||||
ChapterProvider.contentPaint
|
||||
}
|
||||
if (textLine.isReadAloud || isSearchResult) {
|
||||
synchronized(textPaint) {
|
||||
textPaint.color = ThemeStore.accentColor
|
||||
canvas.drawText(charData, start, textLine.lineBase - textLine.lineTop, textPaint)
|
||||
textPaint.color = ReadBookConfig.textColor
|
||||
}
|
||||
val textColor = if (textLine.isReadAloud || isSearchResult) {
|
||||
ThemeStore.accentColor
|
||||
} else {
|
||||
canvas.drawText(charData, start, textLine.lineBase - textLine.lineTop, textPaint)
|
||||
ReadBookConfig.textColor
|
||||
}
|
||||
val paint = PaintPool.obtain()
|
||||
paint.set(textPaint)
|
||||
if (paint.color != textColor) {
|
||||
paint.color = textColor
|
||||
}
|
||||
canvas.drawText(charData, start, textLine.lineBase - textLine.lineTop, paint)
|
||||
PaintPool.recycle(paint)
|
||||
if (selected) {
|
||||
canvas.drawRect(start, 0f, end, textLine.height, view.selectedPaint)
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ package io.legado.app.utils.canvasrecorder
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Picture
|
||||
import io.legado.app.utils.canvasrecorder.objectpool.synchronized
|
||||
import io.legado.app.utils.canvasrecorder.pools.PicturePool
|
||||
import io.legado.app.utils.objectpool.synchronized
|
||||
|
||||
class CanvasRecorderApi23Impl : BaseCanvasRecorder() {
|
||||
|
||||
|
@ -5,7 +5,7 @@ import android.graphics.Picture
|
||||
import android.graphics.RenderNode
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import io.legado.app.utils.canvasrecorder.objectpool.synchronized
|
||||
import io.legado.app.utils.objectpool.synchronized
|
||||
import io.legado.app.utils.canvasrecorder.pools.PicturePool
|
||||
import io.legado.app.utils.canvasrecorder.pools.RenderNodePool
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
package io.legado.app.utils.canvasrecorder.objectpool
|
||||
|
||||
import androidx.annotation.CallSuper
|
||||
import java.lang.ref.SoftReference
|
||||
import java.util.LinkedList
|
||||
|
||||
abstract class BaseObjectPool<T> : ObjectPool<T> {
|
||||
|
||||
private val pool = LinkedList<SoftReference<T>>()
|
||||
|
||||
override fun obtain(): T {
|
||||
while (true) {
|
||||
if (pool.isEmpty()) break
|
||||
return pool.poll()?.get() ?: continue
|
||||
}
|
||||
return create()
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
override fun recycle(target: T) {
|
||||
pool.add(SoftReference(target))
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package io.legado.app.utils.canvasrecorder.pools
|
||||
|
||||
import android.graphics.Picture
|
||||
import io.legado.app.utils.canvasrecorder.objectpool.BaseObjectPool
|
||||
import io.legado.app.utils.objectpool.BaseObjectPool
|
||||
|
||||
class PicturePool : BaseObjectPool<Picture>() {
|
||||
class PicturePool : BaseObjectPool<Picture>(64) {
|
||||
|
||||
override fun create(): Picture = Picture()
|
||||
|
||||
|
@ -3,10 +3,10 @@ package io.legado.app.utils.canvasrecorder.pools
|
||||
import android.graphics.RenderNode
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import io.legado.app.utils.canvasrecorder.objectpool.BaseObjectPool
|
||||
import io.legado.app.utils.objectpool.BaseObjectPool
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.Q)
|
||||
class RenderNodePool : BaseObjectPool<RenderNode>() {
|
||||
class RenderNodePool : BaseObjectPool<RenderNode>(64) {
|
||||
|
||||
override fun recycle(target: RenderNode) {
|
||||
target.discardDisplayList()
|
||||
|
@ -0,0 +1,19 @@
|
||||
package io.legado.app.utils.objectpool
|
||||
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.core.util.Pools
|
||||
|
||||
abstract class BaseObjectPool<T : Any>(size: Int) : ObjectPool<T> {
|
||||
|
||||
open val pool = Pools.SimplePool<T>(size)
|
||||
|
||||
override fun obtain(): T {
|
||||
return pool.acquire() ?: create()
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
override fun recycle(target: T) {
|
||||
pool.release(target)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package io.legado.app.utils.objectpool
|
||||
|
||||
import androidx.core.util.Pools
|
||||
|
||||
abstract class BaseSafeObjectPool<T : Any>(size: Int): BaseObjectPool<T>(size) {
|
||||
|
||||
override val pool = Pools.SynchronizedPool<T>(size)
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.legado.app.utils.canvasrecorder.objectpool
|
||||
package io.legado.app.utils.objectpool
|
||||
|
||||
interface ObjectPool<T> {
|
||||
|
@ -1,3 +1,3 @@
|
||||
package io.legado.app.utils.canvasrecorder.objectpool
|
||||
package io.legado.app.utils.objectpool
|
||||
|
||||
fun <T> ObjectPool<T>.synchronized(): ObjectPool<T> = ObjectPoolLocked(this)
|
@ -1,4 +1,4 @@
|
||||
package io.legado.app.utils.canvasrecorder.objectpool
|
||||
package io.legado.app.utils.objectpool
|
||||
|
||||
class ObjectPoolLocked<T>(private val delegate: ObjectPool<T>) : ObjectPool<T> by delegate {
|
||||
|
Loading…
Reference in New Issue
Block a user