This commit is contained in:
Horis
2024-02-20 17:05:27 +08:00
parent 6ed8cb9023
commit 020f956ce0
10 changed files with 59 additions and 24 deletions
@@ -13,9 +13,21 @@ import io.legado.app.constant.Theme
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.utils.* import io.legado.app.utils.BitmapUtils
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.FileUtils
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
import io.legado.app.utils.hexString
import io.legado.app.utils.postEvent
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.putPrefInt
import io.legado.app.utils.stackBlur
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
@Keep @Keep
@@ -43,6 +55,7 @@ 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() {
@@ -387,11 +387,6 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
override fun onNightModeChanged(mode: Int) {
super.onNightModeChanged(mode)
binding.readView.invalidateTextPage()
}
/** /**
* 菜单 * 菜单
*/ */
@@ -1298,7 +1293,7 @@ class ReadBookActivity : BaseReadBookActivity(),
when (dialogId) { when (dialogId) {
TEXT_COLOR -> { TEXT_COLOR -> {
setCurTextColor(color) setCurTextColor(color)
postEvent(EventBus.UP_CONFIG, arrayOf(2, 6)) postEvent(EventBus.UP_CONFIG, arrayOf(2, 9))
} }
BG_COLOR -> { BG_COLOR -> {
@@ -1492,6 +1487,7 @@ class ReadBookActivity : BaseReadBookActivity(),
8 -> ChapterProvider.upStyle() 8 -> ChapterProvider.upStyle()
9 -> binding.readView.invalidateTextPage() 9 -> binding.readView.invalidateTextPage()
10 -> ChapterProvider.upLayout() 10 -> ChapterProvider.upLayout()
11 -> binding.readView.submitRenderTask()
} }
} }
} }
@@ -187,7 +187,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
val layoutNames = defaultConfigs.map { it.name } val layoutNames = defaultConfigs.map { it.name }
context?.selector("选择预设布局", layoutNames) { _, i -> context?.selector("选择预设布局", layoutNames) { _, i ->
if (i >= 0) { if (i >= 0) {
ReadBookConfig.durConfig = defaultConfigs[i].copy() ReadBookConfig.durConfig = defaultConfigs[i].copy().apply { initColorInt() }
initData() initData()
postEvent(EventBus.UP_CONFIG, arrayOf(1, 2, 5)) postEvent(EventBus.UP_CONFIG, arrayOf(1, 2, 5))
} }
@@ -199,7 +199,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
} }
binding.swUnderline.setOnCheckedChangeListener { _, isChecked -> binding.swUnderline.setOnCheckedChangeListener { _, isChecked ->
underline = isChecked underline = isChecked
postEvent(EventBus.UP_CONFIG, arrayOf(9)) postEvent(EventBus.UP_CONFIG, arrayOf(9, 11))
} }
binding.tvTextColor.setOnClickListener { binding.tvTextColor.setOnClickListener {
ColorPickerDialog.newBuilder() ColorPickerDialog.newBuilder()
@@ -42,8 +42,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
private var callBack: CallBack private var callBack: CallBack
private val visibleRect = ChapterProvider.visibleRect private val visibleRect = ChapterProvider.visibleRect
val selectStart = TextPos(0, 0, 0) val selectStart = TextPos(0, -1, -1)
private val selectEnd = TextPos(0, 0, 0) private val selectEnd = TextPos(0, -1, -1)
var textPage: TextPage = TextPage() var textPage: TextPage = TextPage()
private set private set
var isMainView = false var isMainView = false
@@ -81,7 +81,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} else { } else {
invalidate() invalidate()
} }
submitRenderTask()
} }
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
@@ -564,8 +563,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
} }
} }
// 由后台线程完成渲染后通知视图重绘 postInvalidate()
submitRenderTask()
} }
private fun upSelectedStart(x: Float, y: Float, top: Float) { private fun upSelectedStart(x: Float, y: Float, top: Float) {
@@ -601,7 +599,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
} }
} }
submitRenderTask() selectStart.reset()
selectEnd.reset()
postInvalidate()
callBack.onCancelSelect() callBack.onCancelSelect()
} }
@@ -320,7 +320,7 @@ class PageView(context: Context) : FrameLayout(context) {
binding.contentTextView.setAutoPager(autoPager) binding.contentTextView.setAutoPager(autoPager)
} }
fun submitPreRenderTask() { fun submitRenderTask() {
binding.contentTextView.submitRenderTask() binding.contentTextView.submitRenderTask()
} }
@@ -635,7 +635,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
nextPage.invalidateAll() nextPage.invalidateAll()
nextPlusPage.invalidateAll() nextPlusPage.invalidateAll()
} }
upContent()
} }
fun onScrollAnimStart() { fun onScrollAnimStart() {
@@ -648,7 +647,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
fun onPageChange() { fun onPageChange() {
autoPager.reset() autoPager.reset()
curPage.submitPreRenderTask() submitRenderTask()
}
fun submitRenderTask() {
curPage.submitRenderTask()
} }
override val currentChapter: TextChapter? override val currentChapter: TextChapter?
@@ -60,4 +60,13 @@ data class TextPos(
else -> 0 else -> 0
} }
} }
fun reset() {
relativePagePos = 0
lineIndex = -1
columnIndex = -1
isTouch = true
isLast = false
}
} }
@@ -46,7 +46,9 @@ class CanvasRecorderApi29Impl : BaseCanvasRecorder() {
} }
override fun draw(canvas: Canvas) { override fun draw(canvas: Canvas) {
if (renderNode == null || picture == null) return if (renderNode == null || picture == null) {
return
}
if (canvas.isHardwareAccelerated) { if (canvas.isHardwareAccelerated) {
if (!renderNode!!.hasDisplayList()) { if (!renderNode!!.hasDisplayList()) {
flushRenderNode() flushRenderNode()
@@ -14,8 +14,8 @@ inline fun CanvasRecorder.recordIfNeeded(
} }
inline fun CanvasRecorder.record(width: Int, height: Int, block: Canvas.() -> Unit) { inline fun CanvasRecorder.record(width: Int, height: Int, block: Canvas.() -> Unit) {
val canvas = beginRecording(width, height)
try { try {
val canvas = beginRecording(width, height)
canvas.withSave { canvas.withSave {
block() block()
} }
@@ -30,7 +30,9 @@ class CanvasRecorderLocked(private val delegate: CanvasRecorder) :
} }
override fun draw(canvas: Canvas) { override fun draw(canvas: Canvas) {
if (lock == null) return if (lock == null) {
return
}
lock!!.lock() lock!!.lock()
try { try {
delegate.draw(canvas) delegate.draw(canvas)
@@ -40,12 +42,22 @@ class CanvasRecorderLocked(private val delegate: CanvasRecorder) :
} }
override fun isLocked(): Boolean { override fun isLocked(): Boolean {
if (lock == null) return false if (lock == null) {
return false
}
return lock!!.isLocked return lock!!.isLocked
} }
override fun recycle() { override fun recycle() {
delegate.recycle() if (lock == null) {
return
}
lock!!.lock()
try {
delegate.recycle()
} finally {
lock!!.unlock()
}
lock = null lock = null
} }