|
|
@ -11,6 +11,7 @@ object ChapterProvider { |
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
|
fun getTextChapter(textView: ContentTextView, bookChapter: BookChapter, content: String): TextChapter { |
|
|
|
fun getTextChapter(textView: ContentTextView, bookChapter: BookChapter, content: String): TextChapter { |
|
|
|
val textPages = arrayListOf<TextPage>() |
|
|
|
val textPages = arrayListOf<TextPage>() |
|
|
|
|
|
|
|
val pageLengths = arrayListOf<Int>() |
|
|
|
var surplusText = content |
|
|
|
var surplusText = content |
|
|
|
var pageIndex = 0 |
|
|
|
var pageIndex = 0 |
|
|
|
while (surplusText.isNotEmpty()) { |
|
|
|
while (surplusText.isNotEmpty()) { |
|
|
@ -20,16 +21,18 @@ object ChapterProvider { |
|
|
|
spannableStringBuilder.setSpan(span, 0, surplusText.indexOf("\n"), Spannable.SPAN_INCLUSIVE_EXCLUSIVE) |
|
|
|
spannableStringBuilder.setSpan(span, 0, surplusText.indexOf("\n"), Spannable.SPAN_INCLUSIVE_EXCLUSIVE) |
|
|
|
} |
|
|
|
} |
|
|
|
textView.text = spannableStringBuilder |
|
|
|
textView.text = spannableStringBuilder |
|
|
|
|
|
|
|
pageLengths.add(textView.getCharNum()) |
|
|
|
textPages.add( |
|
|
|
textPages.add( |
|
|
|
TextPage( |
|
|
|
TextPage( |
|
|
|
pageIndex, |
|
|
|
pageIndex, |
|
|
|
spannableStringBuilder.delete(textView.getCharNum(), spannableStringBuilder.length) |
|
|
|
spannableStringBuilder.delete(pageLengths[pageIndex], spannableStringBuilder.length) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
surplusText = surplusText.substring(textView.getCharNum()) |
|
|
|
surplusText = surplusText.substring(pageLengths[pageIndex]) |
|
|
|
|
|
|
|
|
|
|
|
pageIndex++ |
|
|
|
pageIndex++ |
|
|
|
} |
|
|
|
} |
|
|
|
return TextChapter(bookChapter.index, bookChapter.title, textPages) |
|
|
|
return TextChapter(bookChapter.index, bookChapter.title, textPages, pageLengths) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|