pull/32/head
kunfei 5 years ago
parent 4fb7b6cd30
commit 148bdae34e
  1. 19
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 22
      app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt

@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.view.KeyEvent import android.view.KeyEvent
import android.view.Menu import android.view.Menu
@ -91,6 +90,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
Help.upSystemUiVisibility(window, !read_menu.isVisible) Help.upSystemUiVisibility(window, !read_menu.isVisible)
} }
/**
* 初始化View
*/
private fun initView() { private fun initView() {
tv_chapter_name.onClick { tv_chapter_name.onClick {
viewModel.bookSource?.let { viewModel.bookSource?.let {
@ -461,26 +463,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
launch(IO) { launch(IO) {
viewModel.curTextChapter?.let { viewModel.curTextChapter?.let {
val pageStart = chapterStart - it.getReadLength(viewModel.durPageIndex) val pageStart = chapterStart - it.getReadLength(viewModel.durPageIndex)
val page = it.page(viewModel.durPageIndex) it.page(viewModel.durPageIndex)?.upPageAloudSpan(pageStart)
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) { withContext(Main) {
page_view.upContent() page_view.upContent()
} }
} }
} }
} }
}
observeEvent<Boolean>(Bus.TTS_NEXT) { observeEvent<Boolean>(Bus.TTS_NEXT) {
if (it) { if (it) {
moveToNextChapter() moveToNextChapter()

@ -1,5 +1,8 @@
package io.legado.app.ui.widget.page package io.legado.app.ui.widget.page
import android.text.Spannable
import android.text.SpannableStringBuilder
data class TextPage( data class TextPage(
val index: Int, val index: Int,
val text: CharSequence, val text: CharSequence,
@ -7,4 +10,21 @@ data class TextPage(
var pageSize: Int = 0, var pageSize: Int = 0,
var chapterSize: Int = 0, var chapterSize: Int = 0,
var chapterIndex: 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
)
}
}
}

Loading…
Cancel
Save