Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Feb 20, 2024
1 parent 0fc79ec commit 5167335
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 24 deletions.
17 changes: 15 additions & 2 deletions app/src/main/java/io/legado/app/help/config/ThemeConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,6 +55,7 @@ object ThemeConfig {
initNightMode()
BookCover.upDefaultCover()
postEvent(EventBus.RECREATE, "")
postEvent(EventBus.UP_CONFIG, arrayOf(2, 9))
}

private fun initNightMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,6 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}

override fun onNightModeChanged(mode: Int) {
super.onNightModeChanged(mode)
binding.readView.invalidateTextPage()
}

/**
* 菜单
*/
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -1492,6 +1487,7 @@ class ReadBookActivity : BaseReadBookActivity(),
8 -> ChapterProvider.upStyle()
9 -> binding.readView.invalidateTextPage()
10 -> ChapterProvider.upLayout()
11 -> binding.readView.submitRenderTask()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -564,8 +563,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
}
// 由后台线程完成渲染后通知视图重绘
submitRenderTask()
postInvalidate()
}

private fun upSelectedStart(x: Float, y: Float, top: Float) {
Expand Down Expand Up @@ -601,7 +599,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
}
submitRenderTask()
selectStart.reset()
selectEnd.reset()
postInvalidate()
callBack.onCancelSelect()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class PageView(context: Context) : FrameLayout(context) {
binding.contentTextView.setAutoPager(autoPager)
}

fun submitPreRenderTask() {
fun submitRenderTask() {
binding.contentTextView.submitRenderTask()
}

Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
nextPage.invalidateAll()
nextPlusPage.invalidateAll()
}
upContent()
}

fun onScrollAnimStart() {
Expand All @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ data class TextPos(
else -> 0
}
}

fun reset() {
relativePagePos = 0
lineIndex = -1
columnIndex = -1
isTouch = true
isLast = false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 5167335

Please sign in to comment.