feat: 优化代码

pull/123/head
kunfei 5 years ago
parent 24a2235fc8
commit cffb082d8b
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt
  3. 10
      app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt

@ -92,6 +92,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
if (!ReadBookConfig.isScroll) return
//滚动翻页
if (!pageFactory.hasNext()) return
val nextPage = relativePage(1)
relativeOffset = relativeOffset(1)
nextPage.textLines.forEach { textLine ->
@ -108,6 +109,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
textLine.isReadAloud
)
}
if (!pageFactory.hasNextPlus()) return
relativeOffset = relativeOffset(2)
if (relativeOffset < ChapterProvider.visibleHeight) {
relativePage(2).textLines.forEach { textLine ->

@ -22,4 +22,5 @@ abstract class PageFactory<DATA>(protected val dataSource: DataSource) {
abstract fun hasPrev(): Boolean
abstract fun hasNextPlus(): Boolean
}

@ -13,6 +13,10 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
return hasNextChapter() || currentChapter?.isLastIndex(pageIndex) != true
}
override fun hasNextPlus(): Boolean = with(dataSource) {
return hasNextChapter() || pageIndex < (currentChapter?.pageSize() ?: 1) - 2
}
override fun moveToFirst() {
ReadBook.setPageIndex(0)
}
@ -86,9 +90,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
?: TextPage(title = it.title).format()
}
}
if (!hasPrevChapter()) {
return@with TextPage(text = "")
}
prevChapter?.let {
return@with it.lastPage()?.removePageAloudSpan()
?: TextPage(title = it.title).format()
@ -103,9 +104,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory<TextPage>(dataSource
return@with it.page(pageIndex + 2)?.removePageAloudSpan()
?: TextPage(title = it.title).format()
}
if (!hasNextChapter()) {
TextPage(text = "")
}
nextChapter?.let { nc ->
if (pageIndex < it.pageSize() - 1) {
return@with nc.page(0)?.removePageAloudSpan()

Loading…
Cancel
Save