mirror of
https://github.com/gedoor/legado.git
synced 2024-07-17 00:58:29 +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()
|
initNightMode()
|
||||||
BookCover.upDefaultCover()
|
BookCover.upDefaultCover()
|
||||||
postEvent(EventBus.RECREATE, "")
|
postEvent(EventBus.RECREATE, "")
|
||||||
postEvent(EventBus.UP_CONFIG, arrayOf(2, 9))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initNightMode() {
|
private fun initNightMode() {
|
||||||
@ -74,10 +73,12 @@ object ThemeConfig {
|
|||||||
context.getPrefString(PreferKey.bgImage),
|
context.getPrefString(PreferKey.bgImage),
|
||||||
context.getPrefInt(PreferKey.bgImageBlurring, 0)
|
context.getPrefInt(PreferKey.bgImageBlurring, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
Theme.Dark -> Pair(
|
Theme.Dark -> Pair(
|
||||||
context.getPrefString(PreferKey.bgImageN),
|
context.getPrefString(PreferKey.bgImageN),
|
||||||
context.getPrefInt(PreferKey.bgImageNBlurring, 0)
|
context.getPrefInt(PreferKey.bgImageNBlurring, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
} ?: return null
|
} ?: return null
|
||||||
if (bgCfg.first.isNullOrBlank()) return null
|
if (bgCfg.first.isNullOrBlank()) return null
|
||||||
@ -218,6 +219,7 @@ object ThemeConfig {
|
|||||||
.bottomBackground(Color.WHITE)
|
.bottomBackground(Color.WHITE)
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
AppConfig.isNightTheme -> {
|
AppConfig.isNightTheme -> {
|
||||||
val primary =
|
val primary =
|
||||||
getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
|
getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
|
||||||
@ -238,6 +240,7 @@ object ThemeConfig {
|
|||||||
.bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
|
.bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val primary =
|
val primary =
|
||||||
getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_brown_500))
|
getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_brown_500))
|
||||||
|
@ -460,6 +460,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
fun onDestroy() {
|
fun onDestroy() {
|
||||||
pageDelegate?.onDestroy()
|
pageDelegate?.onDestroy()
|
||||||
curPage.cancelSelect()
|
curPage.cancelSelect()
|
||||||
|
invalidateTextPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities.column
|
|||||||
|
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
|
import io.legado.app.help.PaintPool
|
||||||
import io.legado.app.help.config.ReadBookConfig
|
import io.legado.app.help.config.ReadBookConfig
|
||||||
import io.legado.app.lib.theme.ThemeStore
|
import io.legado.app.lib.theme.ThemeStore
|
||||||
import io.legado.app.ui.book.read.page.ContentTextView
|
import io.legado.app.ui.book.read.page.ContentTextView
|
||||||
@ -42,15 +43,18 @@ data class TextColumn(
|
|||||||
} else {
|
} else {
|
||||||
ChapterProvider.contentPaint
|
ChapterProvider.contentPaint
|
||||||
}
|
}
|
||||||
if (textLine.isReadAloud || isSearchResult) {
|
val textColor = if (textLine.isReadAloud || isSearchResult) {
|
||||||
synchronized(textPaint) {
|
ThemeStore.accentColor
|
||||||
textPaint.color = ThemeStore.accentColor
|
|
||||||
canvas.drawText(charData, start, textLine.lineBase - textLine.lineTop, textPaint)
|
|
||||||
textPaint.color = ReadBookConfig.textColor
|
|
||||||
}
|
|
||||||
} else {
|
} 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) {
|
if (selected) {
|
||||||
canvas.drawRect(start, 0f, end, textLine.height, view.selectedPaint)
|
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.Canvas
|
||||||
import android.graphics.Picture
|
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.canvasrecorder.pools.PicturePool
|
||||||
|
import io.legado.app.utils.objectpool.synchronized
|
||||||
|
|
||||||
class CanvasRecorderApi23Impl : BaseCanvasRecorder() {
|
class CanvasRecorderApi23Impl : BaseCanvasRecorder() {
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import android.graphics.Picture
|
|||||||
import android.graphics.RenderNode
|
import android.graphics.RenderNode
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
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.PicturePool
|
||||||
import io.legado.app.utils.canvasrecorder.pools.RenderNodePool
|
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
|
package io.legado.app.utils.canvasrecorder.pools
|
||||||
|
|
||||||
import android.graphics.Picture
|
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()
|
override fun create(): Picture = Picture()
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@ package io.legado.app.utils.canvasrecorder.pools
|
|||||||
import android.graphics.RenderNode
|
import android.graphics.RenderNode
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import io.legado.app.utils.canvasrecorder.objectpool.BaseObjectPool
|
import io.legado.app.utils.objectpool.BaseObjectPool
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.Q)
|
@RequiresApi(Build.VERSION_CODES.Q)
|
||||||
class RenderNodePool : BaseObjectPool<RenderNode>() {
|
class RenderNodePool : BaseObjectPool<RenderNode>(64) {
|
||||||
|
|
||||||
override fun recycle(target: RenderNode) {
|
override fun recycle(target: RenderNode) {
|
||||||
target.discardDisplayList()
|
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> {
|
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)
|
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 {
|
class ObjectPoolLocked<T>(private val delegate: ObjectPool<T>) : ObjectPool<T> by delegate {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user