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 f447221b6..629b69d9a 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 @@ -4,7 +4,6 @@ import android.app.Activity import android.content.Intent import android.net.Uri import android.os.Bundle -import android.text.Spannable import android.text.SpannableStringBuilder import android.view.KeyEvent import android.view.Menu @@ -91,6 +90,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea Help.upSystemUiVisibility(window, !read_menu.isVisible) } + /** + * 初始化View + */ private fun initView() { tv_chapter_name.onClick { viewModel.bookSource?.let { @@ -461,22 +463,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea launch(IO) { viewModel.curTextChapter?.let { val pageStart = chapterStart - it.getReadLength(viewModel.durPageIndex) - val page = it.page(viewModel.durPageIndex) - if (page != null && page.text is SpannableStringBuilder) { - page.text.removeSpan(ChapterProvider.readAloudSpan) - var end = page.text.indexOf("\n", pageStart) - if (end == -1) end = page.text.length - var start = page.text.lastIndexOf("\n", pageStart) - if (start == -1) start = 0 - page.text.setSpan( - ChapterProvider.readAloudSpan, - start, - end, - Spannable.SPAN_INCLUSIVE_EXCLUSIVE - ) - withContext(Main) { - page_view.upContent() - } + it.page(viewModel.durPageIndex)?.upPageAloudSpan(pageStart) + withContext(Main) { + page_view.upContent() } } } 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 503472390..9871a7c7b 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,5 +1,8 @@ package io.legado.app.ui.widget.page +import android.text.Spannable +import android.text.SpannableStringBuilder + data class TextPage( val index: Int, val text: CharSequence, @@ -7,4 +10,21 @@ data class TextPage( var pageSize: Int = 0, var chapterSize: Int = 0, var chapterIndex: Int = 0 -) +) { + + fun upPageAloudSpan(pageStart: Int) { + if (text is SpannableStringBuilder) { + text.removeSpan(ChapterProvider.readAloudSpan) + var end = text.indexOf("\n", pageStart) + if (end == -1) end = text.length + var start = text.lastIndexOf("\n", pageStart) + if (start == -1) start = 0 + text.setSpan( + ChapterProvider.readAloudSpan, + start, + end, + Spannable.SPAN_INCLUSIVE_EXCLUSIVE + ) + } + } +}