mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
7bf089a53d
commit
7201f92373
@ -6,7 +6,6 @@ import android.graphics.Paint
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.core.graphics.withTranslation
|
||||
import io.legado.app.R
|
||||
import io.legado.app.data.entities.Bookmark
|
||||
import io.legado.app.help.config.AppConfig
|
||||
@ -23,6 +22,7 @@ import io.legado.app.ui.book.read.page.entities.column.TextColumn
|
||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||
import io.legado.app.ui.book.read.page.provider.TextPageFactory
|
||||
import io.legado.app.ui.widget.dialog.PhotoDialog
|
||||
import io.legado.app.utils.PictureMirror
|
||||
import io.legado.app.utils.activity
|
||||
import io.legado.app.utils.getCompatColor
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
@ -102,25 +102,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
*/
|
||||
private fun drawPage(canvas: Canvas) {
|
||||
var relativeOffset = relativeOffset(0)
|
||||
val view = this
|
||||
canvas.withTranslation(0f, relativeOffset) {
|
||||
textPage.draw(view, this)
|
||||
}
|
||||
textPage.draw(this, canvas, relativeOffset)
|
||||
if (!callBack.isScroll) return
|
||||
//滚动翻页
|
||||
if (!pageFactory.hasNext()) return
|
||||
val textPage1 = relativePage(1)
|
||||
relativeOffset = relativeOffset(1)
|
||||
canvas.withTranslation(0f, relativeOffset) {
|
||||
textPage1.draw(view, this)
|
||||
}
|
||||
textPage1.draw(this, canvas, relativeOffset)
|
||||
if (!pageFactory.hasNextPlus()) return
|
||||
relativeOffset = relativeOffset(2)
|
||||
if (relativeOffset < ChapterProvider.visibleHeight) {
|
||||
val textPage2 = relativePage(2)
|
||||
canvas.withTranslation(0f, relativeOffset) {
|
||||
textPage2.draw(view, this)
|
||||
}
|
||||
textPage2.draw(this, canvas, relativeOffset)
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,7 +160,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
}
|
||||
|
||||
fun submitPreRenderTask() {
|
||||
renderThread.submit(renderRunnable)
|
||||
if (PictureMirror.atLeastApi23) {
|
||||
renderThread.submit(renderRunnable)
|
||||
}
|
||||
}
|
||||
|
||||
private fun preRenderPage() {
|
||||
|
@ -121,7 +121,7 @@ data class TextLine(
|
||||
return visible
|
||||
}
|
||||
|
||||
fun draw(view: ContentTextView, canvas: Canvas?) {
|
||||
fun draw(view: ContentTextView, canvas: Canvas) {
|
||||
pictureMirror.draw(canvas, view.width, height.toInt()) {
|
||||
drawTextLine(view, this)
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ data class TextPage(
|
||||
var isMsgPage: Boolean = false
|
||||
var pictureMirror: PictureMirror = PictureMirror()
|
||||
var doublePage = false
|
||||
var paddingTop = 0
|
||||
|
||||
val paragraphs by lazy {
|
||||
paragraphsInternal
|
||||
@ -159,6 +160,7 @@ data class TextPage(
|
||||
addLine(textLine)
|
||||
}
|
||||
height = ChapterProvider.visibleHeight.toFloat()
|
||||
invalidate()
|
||||
}
|
||||
return this
|
||||
}
|
||||
@ -180,7 +182,8 @@ data class TextPage(
|
||||
fun upPageAloudSpan(aloudSpanStart: Int) {
|
||||
removePageAloudSpan()
|
||||
var lineStart = 0
|
||||
for ((index, textLine) in textLines.withIndex()) {
|
||||
for (index in textLines.indices) {
|
||||
val textLine = textLines[index]
|
||||
val lineLength = textLine.text.length + if (textLine.isParagraphEnd) 1 else 0
|
||||
if (aloudSpanStart > lineStart && aloudSpanStart < lineStart + lineLength) {
|
||||
for (i in index - 1 downTo 0) {
|
||||
@ -263,16 +266,19 @@ data class TextPage(
|
||||
return null
|
||||
}
|
||||
|
||||
fun draw(view: ContentTextView, canvas: Canvas?) {
|
||||
pictureMirror.drawLocked(canvas, view.width, height.toInt()) {
|
||||
drawPage(view, this)
|
||||
fun draw(view: ContentTextView, canvas: Canvas, relativeOffset: Float) {
|
||||
val height = height.toInt()
|
||||
canvas.withTranslation(0f, relativeOffset + paddingTop) {
|
||||
pictureMirror.drawLocked(canvas, view.width, height) {
|
||||
drawPage(view, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawPage(view: ContentTextView, canvas: Canvas) {
|
||||
for (i in lines.indices) {
|
||||
val line = lines[i]
|
||||
canvas.withTranslation(0f, line.lineTop) {
|
||||
canvas.withTranslation(0f, line.lineTop - paddingTop) {
|
||||
line.draw(view, this)
|
||||
}
|
||||
}
|
||||
@ -280,7 +286,9 @@ data class TextPage(
|
||||
|
||||
fun preRender(view: ContentTextView): Boolean {
|
||||
if (!pictureMirror.isDirty) return false
|
||||
draw(view, null)
|
||||
pictureMirror.drawLocked(null, view.width, height.toInt()) {
|
||||
drawPage(view, this)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -290,6 +290,7 @@ object ChapterProvider {
|
||||
item.chapterSize = chapterSize
|
||||
item.title = displayTitle
|
||||
item.doublePage = doublePage
|
||||
item.paddingTop = paddingTop
|
||||
item.upLinesPosition()
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean = with(dataSource) {
|
||||
return hasNextChapter() || currentChapter?.isLastIndex(pageIndex) != true
|
||||
return hasNextChapter() || (currentChapter != null && currentChapter?.isLastIndex(pageIndex) != true)
|
||||
}
|
||||
|
||||
override fun hasNextPlus(): Boolean = with(dataSource) {
|
||||
@ -85,14 +85,12 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
return@with TextPage(text = it).format()
|
||||
}
|
||||
currentChapter?.let {
|
||||
val pageIndex = pageIndex
|
||||
if (pageIndex < it.pageSize - 1) {
|
||||
return@with it.getPage(pageIndex + 1)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
}
|
||||
}
|
||||
if (!hasNextChapter()) {
|
||||
return@with TextPage(text = "")
|
||||
}
|
||||
nextChapter?.let {
|
||||
return@with it.getPage(0)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
@ -105,8 +103,9 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
ReadBook.msg?.let {
|
||||
return@with TextPage(text = it).format()
|
||||
}
|
||||
if (pageIndex > 0) {
|
||||
currentChapter?.let {
|
||||
currentChapter?.let {
|
||||
val pageIndex = pageIndex
|
||||
if (pageIndex > 0) {
|
||||
return@with it.getPage(pageIndex - 1)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
}
|
||||
@ -121,6 +120,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
override val nextPlusPage: TextPage
|
||||
get() = with(dataSource) {
|
||||
currentChapter?.let {
|
||||
val pageIndex = pageIndex
|
||||
if (pageIndex < it.pageSize - 2) {
|
||||
return@with it.getPage(pageIndex + 2)?.removePageAloudSpan()
|
||||
?: TextPage(title = it.title).format()
|
||||
@ -133,7 +133,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
|
||||
return@with nc.getPage(1)?.removePageAloudSpan()
|
||||
?: TextPage(text = "继续滑动以加载下一章…").format()
|
||||
}
|
||||
|
||||
}
|
||||
return TextPage().format()
|
||||
}
|
||||
|
@ -23,15 +23,11 @@ class PictureMirror {
|
||||
block: Canvas.() -> Unit
|
||||
) {
|
||||
if (atLeastApi23) {
|
||||
if (picture == null) {
|
||||
if (picture == null || lock == null) {
|
||||
synchronized(this) {
|
||||
if (picture == null) {
|
||||
picture = Picture()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lock == null) {
|
||||
synchronized(this) {
|
||||
if (lock == null) {
|
||||
lock = ReentrantLock()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user