diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index d817b5357..5faef48df 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -238,7 +238,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea override fun loadContentFinish(bookChapter: BookChapter, content: String) { launch { val textChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) - content_text_view.text = textChapter.pages[0].text + content_text_view.text = textChapter.pages[0].stringBuilder } } 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 c80c4bd2b..8083b02ab 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 @@ -1,5 +1,8 @@ package io.legado.app.ui.widget.page +import android.text.Spannable +import android.text.SpannableStringBuilder +import android.text.style.RelativeSizeSpan import io.legado.app.data.entities.BookChapter @@ -11,8 +14,18 @@ object ChapterProvider { var surplusText = content var pageIndex = 0 while (surplusText.isNotEmpty()) { - textView.text = surplusText - textPages.add(TextPage(pageIndex, surplusText.substring(0, textView.getCharNum()))) + val spannableStringBuilder = SpannableStringBuilder(surplusText) + if (pageIndex == 0) { + val span = RelativeSizeSpan(1.5f) + spannableStringBuilder.setSpan(span, 0, surplusText.indexOf("\n"), Spannable.SPAN_INCLUSIVE_EXCLUSIVE) + } + textView.text = spannableStringBuilder + textPages.add( + TextPage( + pageIndex, + spannableStringBuilder.delete(textView.getCharNum(), spannableStringBuilder.length) + ) + ) surplusText = surplusText.substring(textView.getCharNum()) pageIndex++ } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt index 186eb757e..4feeaf64e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt @@ -1,3 +1,5 @@ package io.legado.app.ui.widget.page -data class TextPage(val index: Int, val text: String) +import android.text.SpannableStringBuilder + +data class TextPage(val index: Int, val stringBuilder: SpannableStringBuilder) 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 2fd3d951c..e42895454 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 @@ -1,5 +1,7 @@ package io.legado.app.ui.widget.page +import android.text.SpannableStringBuilder + class TextPageFactory private constructor(dataSource: DataSource) : PageFactory(dataSource) { companion object{ @@ -15,11 +17,11 @@ class TextPageFactory private constructor(dataSource: DataSource) : PageFactory< } override fun nextPage(): TextPage { - return TextPage(index.plus(1), "index:$index") + return TextPage(index.plus(1), SpannableStringBuilder("index:$index")) } override fun previousPage(): TextPage { - return TextPage(index.minus(1), "index:$index") + return TextPage(index.minus(1), SpannableStringBuilder("index:$index")) }