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 item.pageSize = textPages.size
} }
return TextChapter( return TextChapter(
bookChapter.index, bookChapter.title, bookChapter.url, bookChapter.index,
textPages, pageLengths bookChapter.title,
bookChapter.url,
textPages,
pageLengths,
chapterSize
) )
} }

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

@ -36,6 +36,10 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
upPageAnim() upPageAnim()
setPageFactory(TextPageFactory.create(object : DataSource { setPageFactory(TextPageFactory.create(object : DataSource {
override fun isScroll(): Boolean {
return pageDelegate is ScrollPageDelegate
}
override fun pageIndex(): Int { override fun pageIndex(): Int {
return callback?.durChapterPos() ?: 0 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 package io.legado.app.ui.widget.page
import android.text.SpannableStringBuilder
data class TextChapter( data class TextChapter(
val position: Int, val position: Int,
val title: String, val title: String,
val url: String, val url: String,
val pages: List<TextPage>, val pages: List<TextPage>,
val pageLengths: List<Int> val pageLengths: List<Int>,
val chaptersSize: Int
) { ) {
fun page(index: Int): TextPage? { fun page(index: Int): TextPage? {
if (index >= 0 && index < pages.size) { if (index >= 0 && index < pages.size) {
@ -21,6 +24,17 @@ data class TextChapter(
return null 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 { fun lastIndex(): Int {
return pages.size - 1 return pages.size - 1
} }

@ -62,11 +62,18 @@ class TextPageFactory private constructor(dataSource: DataSource) :
} }
override fun currentPage(): TextPage? = dataSource.pageIndex().let { index -> override fun currentPage(): TextPage? = dataSource.pageIndex().let { index ->
return dataSource.getCurrentChapter()?.page(index) return if (dataSource.isScroll()) {
?: TextPage(index = index, title = "index:$index") dataSource.getCurrentChapter()?.scrollPage()
} else {
dataSource.getCurrentChapter()?.page(index)
} ?: TextPage(index = index, title = "index:$index")
} }
override fun nextPage(): TextPage? = dataSource.pageIndex().let { 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 { dataSource.getCurrentChapter()?.let {
if (index < it.pageSize() - 1) { if (index < it.pageSize() - 1) {
return dataSource.getCurrentChapter()?.page(index + 1)?.removePageAloudSpan() 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 -> 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) { if (index > 0) {
return dataSource.getCurrentChapter()?.page(index - 1)?.removePageAloudSpan() return dataSource.getCurrentChapter()?.page(index - 1)?.removePageAloudSpan()
?: TextPage(index = index - 1, title = "index:${index - 1}") ?: TextPage(index = index - 1, title = "index:${index - 1}")

Loading…
Cancel
Save