This commit is contained in:
Horis 2024-04-12 13:10:25 +08:00
parent e6d181a5fd
commit a99e170bba
20 changed files with 87 additions and 18 deletions

View File

@ -144,6 +144,7 @@ object PreferKey {
const val volumeKeyPageOnPlay = "volumeKeyPageOnPlay"
const val mouseWheelPage = "mouseWheelPage"
const val recordHeapDump = "recordHeapDump"
const val optimizeRender = "optimizeRender"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"

View File

@ -37,6 +37,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
var clickActionBR = appCtx.getPrefInt(PreferKey.clickActionBR, 1)
var themeMode = appCtx.getPrefString(PreferKey.themeMode, "0")
var useDefaultCover = appCtx.getPrefBoolean(PreferKey.useDefaultCover, false)
var optimizeRender = appCtx.getPrefBoolean(PreferKey.optimizeRender, false)
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) {
@ -85,6 +86,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
PreferKey.useDefaultCover -> useDefaultCover =
appCtx.getPrefBoolean(PreferKey.useDefaultCover, false)
PreferKey.optimizeRender -> optimizeRender =
appCtx.getPrefBoolean(PreferKey.optimizeRender, false)
}
}

View File

@ -717,7 +717,7 @@ object ReadBook : CoroutineScope by MainScope() {
fun contentLoadFinish()
fun upPageAnim()
fun upPageAnim(upRecorder: Boolean = false)
fun notifyBookChanged()
}

View File

@ -942,9 +942,9 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
override fun upPageAnim() {
override fun upPageAnim(upRecorder: Boolean) {
lifecycleScope.launch {
binding.readView.upPageAnim()
binding.readView.upPageAnim(upRecorder)
}
}

View File

@ -4,7 +4,12 @@ import android.annotation.SuppressLint
import android.content.DialogInterface
import android.content.SharedPreferences
import android.os.Bundle
import android.view.*
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewConfiguration
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import androidx.preference.Preference
@ -152,6 +157,13 @@ class MoreConfigDialog : DialogFragment() {
PreferKey.noAnimScrollPage -> {
ReadBook.callBack?.upPageAnim()
}
PreferKey.optimizeRender -> {
ReadBook.callBack?.run {
upPageAnim(true)
upContent(resetPageOffset = false)
}
}
}
}

View File

@ -18,6 +18,7 @@ import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.ContentEditDialog
import io.legado.app.ui.book.read.page.api.DataSource
import io.legado.app.ui.book.read.page.delegate.CoverPageDelegate
import io.legado.app.ui.book.read.page.delegate.HorizontalPageDelegate
import io.legado.app.ui.book.read.page.delegate.NoAnimPageDelegate
import io.legado.app.ui.book.read.page.delegate.PageDelegate
import io.legado.app.ui.book.read.page.delegate.ScrollPageDelegate
@ -486,7 +487,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
/**
* 更新翻页动画
*/
fun upPageAnim() {
fun upPageAnim(upRecorder: Boolean = false) {
isScroll = ReadBook.pageAnim() == 3
ChapterProvider.upLayout()
when (ReadBook.pageAnim()) {
@ -511,6 +512,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
}
}
(pageDelegate as? ScrollPageDelegate)?.noAnim = AppConfig.noAnimScrollPage
if (upRecorder) {
(pageDelegate as? HorizontalPageDelegate)?.upRecorder()
}
pageDelegate?.setViewSize(width, height)
if (isScroll) {
curPage.setAutoPager(autoPager)
@ -665,6 +669,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
}
fun submitRenderTask() {
if (!AppConfig.optimizeRender) {
return
}
curPage.submitRenderTask()
}

View File

@ -8,9 +8,9 @@ import io.legado.app.utils.screenshot
abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readView) {
protected val curRecorder = CanvasRecorderFactory.create()
protected val prevRecorder = CanvasRecorderFactory.create()
protected val nextRecorder = CanvasRecorderFactory.create()
protected var curRecorder = CanvasRecorderFactory.create()
protected var prevRecorder = CanvasRecorderFactory.create()
protected var nextRecorder = CanvasRecorderFactory.create()
private val slopSquare get() = readView.pageSlopSquare2
override fun setDirection(direction: PageDirection) {
@ -34,6 +34,15 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
}
}
fun upRecorder() {
curRecorder.recycle()
prevRecorder.recycle()
nextRecorder.recycle()
curRecorder = CanvasRecorderFactory.create()
prevRecorder = CanvasRecorderFactory.create()
nextRecorder = CanvasRecorderFactory.create()
}
override fun onTouch(event: MotionEvent) {
when (event.action) {
MotionEvent.ACTION_DOWN -> {

View File

@ -8,6 +8,7 @@ import androidx.annotation.Keep
import androidx.core.graphics.withTranslation
import io.legado.app.help.PaintPool
import io.legado.app.help.book.isImage
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.model.ReadBook
@ -143,8 +144,12 @@ data class TextLine(
}
fun draw(view: ContentTextView, canvas: Canvas) {
canvasRecorder.recordIfNeededThenDraw(canvas, view.width, height.toInt()) {
drawTextLine(view, this)
if (AppConfig.optimizeRender) {
canvasRecorder.recordIfNeededThenDraw(canvas, view.width, height.toInt()) {
drawTextLine(view, this)
}
} else {
drawTextLine(view, canvas)
}
}
@ -215,7 +220,7 @@ data class TextLine(
}
fun checkFastDraw(): Boolean {
if (exceed || !onlyTextColumn || textPage.isMsgPage) {
if (!AppConfig.optimizeRender || exceed || !onlyTextColumn || textPage.isMsgPage) {
return false
}
if (wordSpacing != 0f && (!atLeastApi26 || !wordSpacingWorking)) {

View File

@ -8,6 +8,7 @@ import androidx.annotation.Keep
import androidx.core.graphics.withTranslation
import io.legado.app.R
import io.legado.app.help.PaintPool
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.ui.book.read.page.ContentTextView
import io.legado.app.ui.book.read.page.entities.TextChapter.Companion.emptyTextChapter
@ -286,9 +287,15 @@ data class TextPage(
}
fun draw(view: ContentTextView, canvas: Canvas, relativeOffset: Float) {
render(view)
canvas.withTranslation(0f, relativeOffset + paddingTop) {
canvasRecorder.draw(this)
if (AppConfig.optimizeRender) {
render(view)
canvas.withTranslation(0f, relativeOffset + paddingTop) {
canvasRecorder.draw(this)
}
} else {
canvas.withTranslation(0f, relativeOffset + paddingTop) {
drawPage(view, this)
}
}
}

View File

@ -13,6 +13,7 @@ import android.text.style.LineHeightSpan
import android.util.AttributeSet
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatTextView
import io.legado.app.help.config.AppConfig
import io.legado.app.utils.canvasrecorder.CanvasRecorderFactory
import io.legado.app.utils.canvasrecorder.recordIfNeededThenDraw
import io.legado.app.utils.dpToPx
@ -80,10 +81,16 @@ class BatteryView @JvmOverloads constructor(
}
override fun onDraw(canvas: Canvas) {
canvasRecorder.recordIfNeededThenDraw(canvas, width, height) {
super.onDraw(this)
if (!isBattery) return@recordIfNeededThenDraw
drawBattery(this)
if (AppConfig.optimizeRender) {
canvasRecorder.recordIfNeededThenDraw(canvas, width, height) {
super.onDraw(this)
if (!isBattery) return@recordIfNeededThenDraw
drawBattery(this)
}
} else {
super.onDraw(canvas)
if (!isBattery) return
drawBattery(canvas)
}
}

View File

@ -1,6 +1,7 @@
package io.legado.app.utils.canvasrecorder
import android.os.Build
import io.legado.app.help.config.AppConfig
object CanvasRecorderFactory {
@ -9,6 +10,7 @@ object CanvasRecorderFactory {
fun create(locked: Boolean = false): CanvasRecorder {
val impl = when {
!AppConfig.optimizeRender -> CanvasRecorderImpl()
atLeastApi29 -> CanvasRecorderApi29Impl()
atLeastApi23 -> CanvasRecorderApi23Impl()
else -> CanvasRecorderImpl()

View File

@ -1146,4 +1146,5 @@
<string name="record_heap_dump_t">记录堆转储</string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -1149,4 +1149,5 @@
<string name="record_heap_dump_t">记录堆转储</string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -1149,4 +1149,5 @@
<string name="record_heap_dump_t">记录堆转储</string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -1145,4 +1145,5 @@ Còn </string>
<string name="record_heap_dump_t">记录堆转储</string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -1146,4 +1146,5 @@
<string name="record_heap_dump_t">记录堆转储</string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -1148,4 +1148,5 @@
<string name="record_heap_dump_t">记录堆转储</string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -1148,4 +1148,5 @@
<string name="record_heap_dump_t">记录堆转储</string>
<string name="font_weight_text">中/粗/细</string>
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -1149,4 +1149,5 @@
<string name="record_heap_dump_t">Capture heap dump</string>
<string name="font_weight_text">N/B/L</string>
<string name="keep_swipe_tip">Keep swiping to load the next chapter…</string>
<string name="enable_optimize_render">启用绘制优化</string>
</resources>

View File

@ -150,6 +150,13 @@
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="optimizeRender"
android:title="@string/enable_optimize_render"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.lib.prefs.Preference
android:key="clickRegionalConfig"
android:title="@string/click_regional_config"