|
|
@ -13,64 +13,77 @@ object ChapterProvider { |
|
|
|
var readAloudSpan = ForegroundColorSpan(App.INSTANCE.accentColor) |
|
|
|
var readAloudSpan = ForegroundColorSpan(App.INSTANCE.accentColor) |
|
|
|
private val titleSpan = RelativeSizeSpan(1.2f) |
|
|
|
private val titleSpan = RelativeSizeSpan(1.2f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var textView: ContentTextView? = null |
|
|
|
|
|
|
|
|
|
|
|
fun getTextChapter( |
|
|
|
fun getTextChapter( |
|
|
|
textView: ContentTextView, bookChapter: BookChapter, |
|
|
|
bookChapter: BookChapter, |
|
|
|
content: String, chapterSize: Int |
|
|
|
content: String, chapterSize: Int |
|
|
|
): TextChapter { |
|
|
|
): TextChapter { |
|
|
|
val textPages = arrayListOf<TextPage>() |
|
|
|
textView?.let { |
|
|
|
val pageLines = arrayListOf<Int>() |
|
|
|
val textPages = arrayListOf<TextPage>() |
|
|
|
val pageLengths = arrayListOf<Int>() |
|
|
|
val pageLines = arrayListOf<Int>() |
|
|
|
var surplusText = content |
|
|
|
val pageLengths = arrayListOf<Int>() |
|
|
|
var pageIndex = 0 |
|
|
|
var surplusText = content |
|
|
|
while (surplusText.isNotEmpty()) { |
|
|
|
var pageIndex = 0 |
|
|
|
val spannableStringBuilder = SpannableStringBuilder(surplusText) |
|
|
|
while (surplusText.isNotEmpty()) { |
|
|
|
if (pageIndex == 0) { |
|
|
|
val spannableStringBuilder = SpannableStringBuilder(surplusText) |
|
|
|
val end = surplusText.indexOf("\n") |
|
|
|
if (pageIndex == 0) { |
|
|
|
if (end > 0) { |
|
|
|
val end = surplusText.indexOf("\n") |
|
|
|
spannableStringBuilder.setSpan( |
|
|
|
if (end > 0) { |
|
|
|
titleSpan, |
|
|
|
spannableStringBuilder.setSpan( |
|
|
|
0, |
|
|
|
titleSpan, |
|
|
|
end, |
|
|
|
0, |
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE |
|
|
|
end, |
|
|
|
|
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
it.text = spannableStringBuilder |
|
|
|
|
|
|
|
val lastLine = it.getLineNum() |
|
|
|
|
|
|
|
val lastCharNum = it.getCharNum(lastLine) |
|
|
|
|
|
|
|
if (lastCharNum == 0) { |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pageLines.add(lastLine) |
|
|
|
|
|
|
|
pageLengths.add(lastCharNum) |
|
|
|
|
|
|
|
textPages.add( |
|
|
|
|
|
|
|
TextPage( |
|
|
|
|
|
|
|
index = pageIndex, |
|
|
|
|
|
|
|
text = spannableStringBuilder.delete( |
|
|
|
|
|
|
|
lastCharNum, |
|
|
|
|
|
|
|
spannableStringBuilder.length |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
title = bookChapter.title, |
|
|
|
|
|
|
|
chapterSize = chapterSize, |
|
|
|
|
|
|
|
chapterIndex = bookChapter.index |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
surplusText = surplusText.substring(lastCharNum) |
|
|
|
|
|
|
|
pageIndex++ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
textView.text = spannableStringBuilder |
|
|
|
for (item in textPages) { |
|
|
|
val lastLine = textView.getLineNum() |
|
|
|
item.pageSize = textPages.size |
|
|
|
val lastCharNum = textView.getCharNum(lastLine) |
|
|
|
|
|
|
|
if (lastCharNum == 0) { |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pageLines.add(lastLine) |
|
|
|
|
|
|
|
pageLengths.add(lastCharNum) |
|
|
|
|
|
|
|
textPages.add( |
|
|
|
|
|
|
|
TextPage( |
|
|
|
|
|
|
|
index = pageIndex, |
|
|
|
|
|
|
|
text = spannableStringBuilder.delete( |
|
|
|
|
|
|
|
lastCharNum, |
|
|
|
|
|
|
|
spannableStringBuilder.length |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
title = bookChapter.title, |
|
|
|
|
|
|
|
chapterSize = chapterSize, |
|
|
|
|
|
|
|
chapterIndex = bookChapter.index |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
surplusText = surplusText.substring(lastCharNum) |
|
|
|
|
|
|
|
pageIndex++ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return TextChapter( |
|
|
|
for (item in textPages) { |
|
|
|
bookChapter.index, |
|
|
|
item.pageSize = textPages.size |
|
|
|
bookChapter.title, |
|
|
|
} |
|
|
|
bookChapter.url, |
|
|
|
return TextChapter( |
|
|
|
textPages, |
|
|
|
|
|
|
|
pageLines, |
|
|
|
|
|
|
|
pageLengths, |
|
|
|
|
|
|
|
chapterSize |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} ?: return TextChapter( |
|
|
|
bookChapter.index, |
|
|
|
bookChapter.index, |
|
|
|
bookChapter.title, |
|
|
|
bookChapter.title, |
|
|
|
bookChapter.url, |
|
|
|
bookChapter.url, |
|
|
|
textPages, |
|
|
|
arrayListOf(), |
|
|
|
pageLines, |
|
|
|
arrayListOf(), |
|
|
|
pageLengths, |
|
|
|
arrayListOf(), |
|
|
|
chapterSize |
|
|
|
chapterSize |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun upReadAloudSpan() { |
|
|
|
fun upReadAloudSpan() { |
|
|
|