pull/34/head
kunfei 5 years ago
parent e790f6eb5b
commit d0bc02e9a4
  1. 8
      app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt
  2. 6
      app/src/main/java/io/legado/app/ui/widget/page/DataSource.kt
  3. 4
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  4. 3
      app/src/main/java/io/legado/app/ui/widget/page/ScrollContentView.kt
  5. 16
      app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt
  6. 15
      app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt

@ -60,8 +60,12 @@ object ChapterProvider {
item.pageSize = textPages.size
}
return TextChapter(
bookChapter.index, bookChapter.title, bookChapter.url,
textPages, pageLengths
bookChapter.index,
bookChapter.title,
bookChapter.url,
textPages,
pageLengths,
chapterSize
)
}

@ -1,8 +1,7 @@
package io.legado.app.ui.widget.page
import io.legado.app.data.entities.BookChapter
interface DataSource {
fun isScroll(): Boolean
fun pageIndex(): Int
@ -28,7 +27,4 @@ interface DataSource {
fun moveToPrevChapter()
interface CallBack {
fun onLoadFinish(bookChapter: BookChapter, content: String)
}
}

@ -36,6 +36,10 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
upPageAnim()
setPageFactory(TextPageFactory.create(object : DataSource {
override fun isScroll(): Boolean {
return pageDelegate is ScrollPageDelegate
}
override fun pageIndex(): Int {
return callback?.durChapterPos() ?: 0
}

@ -1,3 +0,0 @@
package io.legado.app.ui.widget.page
class ScrollContentView

@ -1,11 +1,14 @@
package io.legado.app.ui.widget.page
import android.text.SpannableStringBuilder
data class TextChapter(
val position: Int,
val title: String,
val url: String,
val pages: List<TextPage>,
val pageLengths: List<Int>
val pageLengths: List<Int>,
val chaptersSize: Int
) {
fun page(index: Int): TextPage? {
if (index >= 0 && index < pages.size) {
@ -21,6 +24,17 @@ data class TextChapter(
return null
}
fun scrollPage(): TextPage? {
if (pages.isNotEmpty()) {
val spannableStringBuilder = SpannableStringBuilder()
pages.forEach {
spannableStringBuilder.append(it.text)
}
return TextPage(0, spannableStringBuilder, title, position, chaptersSize)
}
return null
}
fun lastIndex(): Int {
return pages.size - 1
}

@ -62,11 +62,18 @@ class TextPageFactory private constructor(dataSource: DataSource) :
}
override fun currentPage(): TextPage? = dataSource.pageIndex().let { index ->
return dataSource.getCurrentChapter()?.page(index)
?: TextPage(index = index, title = "index:$index")
return if (dataSource.isScroll()) {
dataSource.getCurrentChapter()?.scrollPage()
} else {
dataSource.getCurrentChapter()?.page(index)
} ?: TextPage(index = index, title = "index:$index")
}
override fun nextPage(): TextPage? = dataSource.pageIndex().let { index ->
if (dataSource.isScroll()) {
return dataSource.getNextChapter()?.scrollPage()
?: TextPage(index = index + 1, title = "index:${index + 1}")
}
dataSource.getCurrentChapter()?.let {
if (index < it.pageSize() - 1) {
return dataSource.getCurrentChapter()?.page(index + 1)?.removePageAloudSpan()
@ -78,6 +85,10 @@ class TextPageFactory private constructor(dataSource: DataSource) :
}
override fun previousPage(): TextPage? = dataSource.pageIndex().let { index ->
if (dataSource.isScroll()) {
return dataSource.getPreviousChapter()?.scrollPage()
?: TextPage(index = index + 1, title = "index:${index + 1}")
}
if (index > 0) {
return dataSource.getCurrentChapter()?.page(index - 1)?.removePageAloudSpan()
?: TextPage(index = index - 1, title = "index:${index - 1}")

Loading…
Cancel
Save