feat: 优化代码

pull/106/head
kunfei 5 years ago
parent 861f04c56a
commit 146f012afc
  1. 13
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  4. 7
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.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<ReadBookViewModel>(R.layout.activity_boo
observeEventSticky<Int>(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()
}
}
}

@ -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()

@ -1,6 +1,7 @@
package io.legado.app.ui.book.read.page.entities
data class TextLine(
var text: String = "",
val textChars: ArrayList<TextChar> = arrayListOf(),
var lineTop: Int = 0,
var lineBottom: Int = 0,

@ -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) {
}
}
}
}

Loading…
Cancel
Save