diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 43cf51183..790ad109b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -46,9 +46,7 @@ import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.view_read_menu.* import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult @@ -543,12 +541,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEventSticky(EventBus.TTS_START) { chapterStart -> launch(IO) { if (BaseReadAloudService.isPlay()) { - ReadBook.curTextChapter?.let { - val pageStart = chapterStart - it.getReadLength(ReadBook.durPageIndex) - it.page(ReadBook.durPageIndex)?.upPageAloudSpan(pageStart) - withContext(Main) { - page_view.upContent() - } + ReadBook.curTextChapter?.let { textChapter -> + val pageStart = + chapterStart - textChapter.getReadLength(ReadBook.durPageIndex) + textChapter.page(ReadBook.durPageIndex)?.upPageAloudSpan(pageStart) + upContent() } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index ba08b92c4..927c3eb5a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -178,6 +178,7 @@ object ChapterProvider { val words = title.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) + textLine.text = words val desiredWidth = layout.getLineMax(lineIndex) if (lineIndex != layout.lineCount - 1) { val gapCount: Int = words.length - 1 @@ -201,6 +202,7 @@ object ChapterProvider { } } else { //最后一行 + textLine.text = "$words\n" stringBuilder.append("\n") var x = 0 for (i in words.indices) { @@ -262,6 +264,7 @@ object ChapterProvider { var words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) + textLine.text = words val desiredWidth = layout.getLineMax(lineIndex) if (lineIndex == 0 && layout.lineCount > 1) { //第一行 @@ -297,6 +300,7 @@ object ChapterProvider { } else if (lineIndex == layout.lineCount - 1) { //最后一行 stringBuilder.append("\n") + textLine.text = "$words\n" var x = 0 for (i in words.indices) { val char = words[i].toString() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index eb4b7d236..c5282aba3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.book.read.page.entities data class TextLine( + var text: String = "", val textChars: ArrayList = arrayListOf(), var lineTop: Int = 0, var lineBottom: Int = 0, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 9378439d6..356199690 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -24,10 +24,9 @@ data class TextPage( fun upPageAloudSpan(pageStart: Int) { if (text is SpannableStringBuilder) { removePageAloudSpan() - var end = text.indexOf("\n", pageStart) - if (end == -1) end = text.length - var start = text.lastIndexOf("\n", pageStart) - if (start == -1) start = 0 + for (textLine in textLines) { + + } } } }