feat: 优化代码

pull/117/head
kunfei 5 years ago
parent 854d11b0b0
commit aafa690692
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt
  2. 18
      app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt
  3. 22
      app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt

@ -10,11 +10,13 @@ abstract class PageFactory<DATA>(protected val dataSource: DataSource) {
abstract fun moveToPrev(): Boolean
abstract val nextPage: DATA?
abstract val nextPage: DATA
abstract val prevPage: DATA?
abstract val prevPage: DATA
abstract val currentPage: DATA?
abstract val currentPage: DATA
abstract val nextPagePlus: DATA
abstract fun hasNext(): Boolean

@ -90,5 +90,23 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
return TextPage().format()
}
override val nextPagePlus: TextPage
get() = with(dataSource) {
currentChapter?.let {
if (pageIndex < it.pageSize() - 2) {
return@with it.page(pageIndex + 2)?.removePageAloudSpan()
?: TextPage(title = it.title).format()
}
nextChapter?.let { nc ->
if (pageIndex < it.pageSize() - 1) {
return@with nc.page(0)?.removePageAloudSpan()
?: TextPage(title = nc.title).format()
}
return@with nc.page(1)?.removePageAloudSpan()
?: TextPage(title = nc.title).format()
}
}
return TextPage().format()
}
}

@ -3,6 +3,7 @@ package io.legado.app.ui.book.read.page.content
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import io.legado.app.ui.book.read.page.ChapterProvider
import io.legado.app.ui.book.read.page.entities.TextPage
@ -45,7 +46,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) :
textLine.isReadAloud
)
}
pageFactory.nextPage.textLines.forEach { textLine ->
val nextPage = pageFactory.nextPage
nextPage.textLines.forEach { textLine ->
val yPy = mPageOffset + textPage.height
val lineTop = textLine.lineTop + yPy
val lineBase = textLine.lineBase + yPy
@ -60,7 +62,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) :
textLine.isReadAloud
)
}
if (mPageOffset + textPage.height + nextPage.height < ChapterProvider.visibleHeight) {
pageFactory.nextPagePlus.textLines.forEach { textLine ->
val yPy = mPageOffset + textPage.height + nextPage.height
val lineTop = textLine.lineTop + yPy
val lineBase = textLine.lineBase + yPy
val lineBottom = textLine.lineBottom + yPy
drawChars(
canvas,
textLine.textChars,
lineTop,
lineBase,
lineBottom,
textLine.isTitle,
textLine.isReadAloud
)
}
}
}
fun onScroll(mOffset: Float) {

Loading…
Cancel
Save