From d0bc02e9a423fa5e4b5ff34ac0ed631deeb60763 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Sep 2019 17:24:20 +0800 Subject: [PATCH] up --- .../legado/app/ui/widget/page/ChapterProvider.kt | 8 ++++++-- .../io/legado/app/ui/widget/page/DataSource.kt | 6 +----- .../io/legado/app/ui/widget/page/PageView.kt | 4 ++++ .../app/ui/widget/page/ScrollContentView.kt | 3 --- .../io/legado/app/ui/widget/page/TextChapter.kt | 16 +++++++++++++++- .../legado/app/ui/widget/page/TextPageFactory.kt | 15 +++++++++++++-- 6 files changed, 39 insertions(+), 13 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/widget/page/ScrollContentView.kt diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt index 7579ee9b6..4e33bdd51 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.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 ) } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/DataSource.kt b/app/src/main/java/io/legado/app/ui/widget/page/DataSource.kt index 8ba58b6ba..92b09194b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/DataSource.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/DataSource.kt @@ -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) - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 82e3c46bd..cdc870198 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ScrollContentView.kt b/app/src/main/java/io/legado/app/ui/widget/page/ScrollContentView.kt deleted file mode 100644 index 0e1be1865..000000000 --- a/app/src/main/java/io/legado/app/ui/widget/page/ScrollContentView.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.legado.app.ui.widget.page - -class ScrollContentView diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt index 801f23ea7..d9eff7009 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt @@ -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, - val pageLengths: List + val pageLengths: List, + 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 } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt index a3cfa8599..b0eee5632 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt @@ -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}")