This commit is contained in:
Horis
2024-02-20 17:05:27 +08:00
parent 0fc79ecbef
commit 51673357e9
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.lib.theme.ThemeStore
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 java.io.File
@Keep
@@ -43,6 +55,7 @@ object ThemeConfig {
initNightMode()
BookCover.upDefaultCover()
postEvent(EventBus.RECREATE, "")
postEvent(EventBus.UP_CONFIG, arrayOf(2, 9))
}
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) {
TEXT_COLOR -> {
setCurTextColor(color)
postEvent(EventBus.UP_CONFIG, arrayOf(2, 6))
postEvent(EventBus.UP_CONFIG, arrayOf(2, 9))
}
BG_COLOR -> {
@@ -1492,6 +1487,7 @@ class ReadBookActivity : BaseReadBookActivity(),
8 -> ChapterProvider.upStyle()
9 -> binding.readView.invalidateTextPage()
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 }
context?.selector("选择预设布局", layoutNames) { _, i ->
if (i >= 0) {
ReadBookConfig.durConfig = defaultConfigs[i].copy()
ReadBookConfig.durConfig = defaultConfigs[i].copy().apply { initColorInt() }
initData()
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 ->
underline = isChecked
postEvent(EventBus.UP_CONFIG, arrayOf(9))
postEvent(EventBus.UP_CONFIG, arrayOf(9, 11))
}
binding.tvTextColor.setOnClickListener {
ColorPickerDialog.newBuilder()
@@ -42,8 +42,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
private var callBack: CallBack
private val visibleRect = ChapterProvider.visibleRect
val selectStart = TextPos(0, 0, 0)
private val selectEnd = TextPos(0, 0, 0)
val selectStart = TextPos(0, -1, -1)
private val selectEnd = TextPos(0, -1, -1)
var textPage: TextPage = TextPage()
private set
var isMainView = false
@@ -81,7 +81,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} else {
invalidate()
}
submitRenderTask()
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
@@ -564,8 +563,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
}
// 由后台线程完成渲染后通知视图重绘
submitRenderTask()
postInvalidate()
}
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()
}
@@ -320,7 +320,7 @@ class PageView(context: Context) : FrameLayout(context) {
binding.contentTextView.setAutoPager(autoPager)
}
fun submitPreRenderTask() {
fun submitRenderTask() {
binding.contentTextView.submitRenderTask()
}
@@ -635,7 +635,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
nextPage.invalidateAll()
nextPlusPage.invalidateAll()
}
upContent()
}
fun onScrollAnimStart() {
@@ -648,7 +647,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
fun onPageChange() {
autoPager.reset()
curPage.submitPreRenderTask()
submitRenderTask()
}
fun submitRenderTask() {
curPage.submitRenderTask()
}
override val currentChapter: TextChapter?
@@ -60,4 +60,13 @@ data class TextPos(
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) {
if (renderNode == null || picture == null) return
if (renderNode == null || picture == null) {
return
}
if (canvas.isHardwareAccelerated) {
if (!renderNode!!.hasDisplayList()) {
flushRenderNode()
@@ -14,8 +14,8 @@ inline fun CanvasRecorder.recordIfNeeded(
}
inline fun CanvasRecorder.record(width: Int, height: Int, block: Canvas.() -> Unit) {
val canvas = beginRecording(width, height)
try {
val canvas = beginRecording(width, height)
canvas.withSave {
block()
}
@@ -30,7 +30,9 @@ class CanvasRecorderLocked(private val delegate: CanvasRecorder) :
}
override fun draw(canvas: Canvas) {
if (lock == null) return
if (lock == null) {
return
}
lock!!.lock()
try {
delegate.draw(canvas)
@@ -40,12 +42,22 @@ class CanvasRecorderLocked(private val delegate: CanvasRecorder) :
}
override fun isLocked(): Boolean {
if (lock == null) return false
if (lock == null) {
return false
}
return lock!!.isLocked
}
override fun recycle() {
delegate.recycle()
if (lock == null) {
return
}
lock!!.lock()
try {
delegate.recycle()
} finally {
lock!!.unlock()
}
lock = null
}