From 8f8b302fb24f41df51eef6af21469f6cb1d18a3e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 17 Aug 2019 15:17:30 +0800 Subject: [PATCH] up --- .../java/io/legado/app/ui/widget/page/ChapterProvider.kt | 9 ++++++--- .../java/io/legado/app/ui/widget/page/TextChapter.kt | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) 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 e0a675d15..2c6afd592 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 @@ -11,6 +11,7 @@ object ChapterProvider { @Synchronized fun getTextChapter(textView: ContentTextView, bookChapter: BookChapter, content: String): TextChapter { val textPages = arrayListOf() + val pageLengths = arrayListOf() var surplusText = content var pageIndex = 0 while (surplusText.isNotEmpty()) { @@ -20,16 +21,18 @@ object ChapterProvider { spannableStringBuilder.setSpan(span, 0, surplusText.indexOf("\n"), Spannable.SPAN_INCLUSIVE_EXCLUSIVE) } textView.text = spannableStringBuilder + pageLengths.add(textView.getCharNum()) textPages.add( TextPage( pageIndex, - spannableStringBuilder.delete(textView.getCharNum(), spannableStringBuilder.length) + spannableStringBuilder.delete(pageLengths[pageIndex], spannableStringBuilder.length) ) ) - surplusText = surplusText.substring(textView.getCharNum()) + surplusText = surplusText.substring(pageLengths[pageIndex]) + pageIndex++ } - return TextChapter(bookChapter.index, bookChapter.title, textPages) + return TextChapter(bookChapter.index, bookChapter.title, textPages, pageLengths) } 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 df1643b17..032a732c1 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 @@ -3,7 +3,8 @@ package io.legado.app.ui.widget.page data class TextChapter( val position: Int, val title: String, - val pages: List + val pages: List, + val pageLengths: List ) { fun page(index: Int): TextPage? { if (index >= 0 && index < pages.size) {