mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
e6d181a5fd
commit
a99e170bba
@ -144,6 +144,7 @@ object PreferKey {
|
|||||||
const val volumeKeyPageOnPlay = "volumeKeyPageOnPlay"
|
const val volumeKeyPageOnPlay = "volumeKeyPageOnPlay"
|
||||||
const val mouseWheelPage = "mouseWheelPage"
|
const val mouseWheelPage = "mouseWheelPage"
|
||||||
const val recordHeapDump = "recordHeapDump"
|
const val recordHeapDump = "recordHeapDump"
|
||||||
|
const val optimizeRender = "optimizeRender"
|
||||||
|
|
||||||
const val cPrimary = "colorPrimary"
|
const val cPrimary = "colorPrimary"
|
||||||
const val cAccent = "colorAccent"
|
const val cAccent = "colorAccent"
|
||||||
|
@ -37,6 +37,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
var clickActionBR = appCtx.getPrefInt(PreferKey.clickActionBR, 1)
|
var clickActionBR = appCtx.getPrefInt(PreferKey.clickActionBR, 1)
|
||||||
var themeMode = appCtx.getPrefString(PreferKey.themeMode, "0")
|
var themeMode = appCtx.getPrefString(PreferKey.themeMode, "0")
|
||||||
var useDefaultCover = appCtx.getPrefBoolean(PreferKey.useDefaultCover, false)
|
var useDefaultCover = appCtx.getPrefBoolean(PreferKey.useDefaultCover, false)
|
||||||
|
var optimizeRender = appCtx.getPrefBoolean(PreferKey.optimizeRender, false)
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
when (key) {
|
when (key) {
|
||||||
@ -85,6 +86,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
PreferKey.useDefaultCover -> useDefaultCover =
|
PreferKey.useDefaultCover -> useDefaultCover =
|
||||||
appCtx.getPrefBoolean(PreferKey.useDefaultCover, false)
|
appCtx.getPrefBoolean(PreferKey.useDefaultCover, false)
|
||||||
|
|
||||||
|
PreferKey.optimizeRender -> optimizeRender =
|
||||||
|
appCtx.getPrefBoolean(PreferKey.optimizeRender, false)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,7 +717,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
|
|
||||||
fun contentLoadFinish()
|
fun contentLoadFinish()
|
||||||
|
|
||||||
fun upPageAnim()
|
fun upPageAnim(upRecorder: Boolean = false)
|
||||||
|
|
||||||
fun notifyBookChanged()
|
fun notifyBookChanged()
|
||||||
}
|
}
|
||||||
|
@ -942,9 +942,9 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun upPageAnim() {
|
override fun upPageAnim(upRecorder: Boolean) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
binding.readView.upPageAnim()
|
binding.readView.upPageAnim(upRecorder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,12 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
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 android.widget.LinearLayout
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
@ -152,6 +157,13 @@ class MoreConfigDialog : DialogFragment() {
|
|||||||
PreferKey.noAnimScrollPage -> {
|
PreferKey.noAnimScrollPage -> {
|
||||||
ReadBook.callBack?.upPageAnim()
|
ReadBook.callBack?.upPageAnim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PreferKey.optimizeRender -> {
|
||||||
|
ReadBook.callBack?.run {
|
||||||
|
upPageAnim(true)
|
||||||
|
upContent(resetPageOffset = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.ContentEditDialog
|
||||||
import io.legado.app.ui.book.read.page.api.DataSource
|
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.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.NoAnimPageDelegate
|
||||||
import io.legado.app.ui.book.read.page.delegate.PageDelegate
|
import io.legado.app.ui.book.read.page.delegate.PageDelegate
|
||||||
import io.legado.app.ui.book.read.page.delegate.ScrollPageDelegate
|
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
|
isScroll = ReadBook.pageAnim() == 3
|
||||||
ChapterProvider.upLayout()
|
ChapterProvider.upLayout()
|
||||||
when (ReadBook.pageAnim()) {
|
when (ReadBook.pageAnim()) {
|
||||||
@ -511,6 +512,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(pageDelegate as? ScrollPageDelegate)?.noAnim = AppConfig.noAnimScrollPage
|
(pageDelegate as? ScrollPageDelegate)?.noAnim = AppConfig.noAnimScrollPage
|
||||||
|
if (upRecorder) {
|
||||||
|
(pageDelegate as? HorizontalPageDelegate)?.upRecorder()
|
||||||
|
}
|
||||||
pageDelegate?.setViewSize(width, height)
|
pageDelegate?.setViewSize(width, height)
|
||||||
if (isScroll) {
|
if (isScroll) {
|
||||||
curPage.setAutoPager(autoPager)
|
curPage.setAutoPager(autoPager)
|
||||||
@ -665,6 +669,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun submitRenderTask() {
|
fun submitRenderTask() {
|
||||||
|
if (!AppConfig.optimizeRender) {
|
||||||
|
return
|
||||||
|
}
|
||||||
curPage.submitRenderTask()
|
curPage.submitRenderTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ import io.legado.app.utils.screenshot
|
|||||||
|
|
||||||
abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readView) {
|
abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readView) {
|
||||||
|
|
||||||
protected val curRecorder = CanvasRecorderFactory.create()
|
protected var curRecorder = CanvasRecorderFactory.create()
|
||||||
protected val prevRecorder = CanvasRecorderFactory.create()
|
protected var prevRecorder = CanvasRecorderFactory.create()
|
||||||
protected val nextRecorder = CanvasRecorderFactory.create()
|
protected var nextRecorder = CanvasRecorderFactory.create()
|
||||||
private val slopSquare get() = readView.pageSlopSquare2
|
private val slopSquare get() = readView.pageSlopSquare2
|
||||||
|
|
||||||
override fun setDirection(direction: PageDirection) {
|
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) {
|
override fun onTouch(event: MotionEvent) {
|
||||||
when (event.action) {
|
when (event.action) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
@ -8,6 +8,7 @@ import androidx.annotation.Keep
|
|||||||
import androidx.core.graphics.withTranslation
|
import androidx.core.graphics.withTranslation
|
||||||
import io.legado.app.help.PaintPool
|
import io.legado.app.help.PaintPool
|
||||||
import io.legado.app.help.book.isImage
|
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.help.config.ReadBookConfig
|
||||||
import io.legado.app.lib.theme.ThemeStore
|
import io.legado.app.lib.theme.ThemeStore
|
||||||
import io.legado.app.model.ReadBook
|
import io.legado.app.model.ReadBook
|
||||||
@ -143,8 +144,12 @@ data class TextLine(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun draw(view: ContentTextView, canvas: Canvas) {
|
fun draw(view: ContentTextView, canvas: Canvas) {
|
||||||
canvasRecorder.recordIfNeededThenDraw(canvas, view.width, height.toInt()) {
|
if (AppConfig.optimizeRender) {
|
||||||
drawTextLine(view, this)
|
canvasRecorder.recordIfNeededThenDraw(canvas, view.width, height.toInt()) {
|
||||||
|
drawTextLine(view, this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
drawTextLine(view, canvas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +220,7 @@ data class TextLine(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun checkFastDraw(): Boolean {
|
fun checkFastDraw(): Boolean {
|
||||||
if (exceed || !onlyTextColumn || textPage.isMsgPage) {
|
if (!AppConfig.optimizeRender || exceed || !onlyTextColumn || textPage.isMsgPage) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (wordSpacing != 0f && (!atLeastApi26 || !wordSpacingWorking)) {
|
if (wordSpacing != 0f && (!atLeastApi26 || !wordSpacingWorking)) {
|
||||||
|
@ -8,6 +8,7 @@ import androidx.annotation.Keep
|
|||||||
import androidx.core.graphics.withTranslation
|
import androidx.core.graphics.withTranslation
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.help.PaintPool
|
import io.legado.app.help.PaintPool
|
||||||
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.config.ReadBookConfig
|
import io.legado.app.help.config.ReadBookConfig
|
||||||
import io.legado.app.ui.book.read.page.ContentTextView
|
import io.legado.app.ui.book.read.page.ContentTextView
|
||||||
import io.legado.app.ui.book.read.page.entities.TextChapter.Companion.emptyTextChapter
|
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) {
|
fun draw(view: ContentTextView, canvas: Canvas, relativeOffset: Float) {
|
||||||
render(view)
|
if (AppConfig.optimizeRender) {
|
||||||
canvas.withTranslation(0f, relativeOffset + paddingTop) {
|
render(view)
|
||||||
canvasRecorder.draw(this)
|
canvas.withTranslation(0f, relativeOffset + paddingTop) {
|
||||||
|
canvasRecorder.draw(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
canvas.withTranslation(0f, relativeOffset + paddingTop) {
|
||||||
|
drawPage(view, this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import android.text.style.LineHeightSpan
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.appcompat.widget.AppCompatTextView
|
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.CanvasRecorderFactory
|
||||||
import io.legado.app.utils.canvasrecorder.recordIfNeededThenDraw
|
import io.legado.app.utils.canvasrecorder.recordIfNeededThenDraw
|
||||||
import io.legado.app.utils.dpToPx
|
import io.legado.app.utils.dpToPx
|
||||||
@ -80,10 +81,16 @@ class BatteryView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
canvasRecorder.recordIfNeededThenDraw(canvas, width, height) {
|
if (AppConfig.optimizeRender) {
|
||||||
super.onDraw(this)
|
canvasRecorder.recordIfNeededThenDraw(canvas, width, height) {
|
||||||
if (!isBattery) return@recordIfNeededThenDraw
|
super.onDraw(this)
|
||||||
drawBattery(this)
|
if (!isBattery) return@recordIfNeededThenDraw
|
||||||
|
drawBattery(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
if (!isBattery) return
|
||||||
|
drawBattery(canvas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.legado.app.utils.canvasrecorder
|
package io.legado.app.utils.canvasrecorder
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import io.legado.app.help.config.AppConfig
|
||||||
|
|
||||||
object CanvasRecorderFactory {
|
object CanvasRecorderFactory {
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ object CanvasRecorderFactory {
|
|||||||
|
|
||||||
fun create(locked: Boolean = false): CanvasRecorder {
|
fun create(locked: Boolean = false): CanvasRecorder {
|
||||||
val impl = when {
|
val impl = when {
|
||||||
|
!AppConfig.optimizeRender -> CanvasRecorderImpl()
|
||||||
atLeastApi29 -> CanvasRecorderApi29Impl()
|
atLeastApi29 -> CanvasRecorderApi29Impl()
|
||||||
atLeastApi23 -> CanvasRecorderApi23Impl()
|
atLeastApi23 -> CanvasRecorderApi23Impl()
|
||||||
else -> CanvasRecorderImpl()
|
else -> CanvasRecorderImpl()
|
||||||
|
@ -1146,4 +1146,5 @@
|
|||||||
<string name="record_heap_dump_t">记录堆转储</string>
|
<string name="record_heap_dump_t">记录堆转储</string>
|
||||||
<string name="font_weight_text">中/粗/细</string>
|
<string name="font_weight_text">中/粗/细</string>
|
||||||
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1149,4 +1149,5 @@
|
|||||||
<string name="record_heap_dump_t">记录堆转储</string>
|
<string name="record_heap_dump_t">记录堆转储</string>
|
||||||
<string name="font_weight_text">中/粗/细</string>
|
<string name="font_weight_text">中/粗/细</string>
|
||||||
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1149,4 +1149,5 @@
|
|||||||
<string name="record_heap_dump_t">记录堆转储</string>
|
<string name="record_heap_dump_t">记录堆转储</string>
|
||||||
<string name="font_weight_text">中/粗/细</string>
|
<string name="font_weight_text">中/粗/细</string>
|
||||||
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1145,4 +1145,5 @@ Còn </string>
|
|||||||
<string name="record_heap_dump_t">记录堆转储</string>
|
<string name="record_heap_dump_t">记录堆转储</string>
|
||||||
<string name="font_weight_text">中/粗/细</string>
|
<string name="font_weight_text">中/粗/细</string>
|
||||||
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1146,4 +1146,5 @@
|
|||||||
<string name="record_heap_dump_t">记录堆转储</string>
|
<string name="record_heap_dump_t">记录堆转储</string>
|
||||||
<string name="font_weight_text">中/粗/细</string>
|
<string name="font_weight_text">中/粗/细</string>
|
||||||
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1148,4 +1148,5 @@
|
|||||||
<string name="record_heap_dump_t">记录堆转储</string>
|
<string name="record_heap_dump_t">记录堆转储</string>
|
||||||
<string name="font_weight_text">中/粗/细</string>
|
<string name="font_weight_text">中/粗/细</string>
|
||||||
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1148,4 +1148,5 @@
|
|||||||
<string name="record_heap_dump_t">记录堆转储</string>
|
<string name="record_heap_dump_t">记录堆转储</string>
|
||||||
<string name="font_weight_text">中/粗/细</string>
|
<string name="font_weight_text">中/粗/细</string>
|
||||||
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
<string name="keep_swipe_tip">继续滑动以加载下一章…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1149,4 +1149,5 @@
|
|||||||
<string name="record_heap_dump_t">Capture heap dump</string>
|
<string name="record_heap_dump_t">Capture heap dump</string>
|
||||||
<string name="font_weight_text">N/B/L</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="keep_swipe_tip">Keep swiping to load the next chapter…</string>
|
||||||
|
<string name="enable_optimize_render">启用绘制优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -150,6 +150,13 @@
|
|||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:isBottomBackground="true" />
|
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
|
<io.legado.app.lib.prefs.Preference
|
||||||
android:key="clickRegionalConfig"
|
android:key="clickRegionalConfig"
|
||||||
android:title="@string/click_regional_config"
|
android:title="@string/click_regional_config"
|
||||||
|
Loading…
Reference in New Issue
Block a user