|
|
|
@ -1,12 +1,11 @@ |
|
|
|
|
package io.legado.app.ui.book.read.page.entities |
|
|
|
|
|
|
|
|
|
import android.text.SpannableStringBuilder |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
|
|
data class TextPage( |
|
|
|
|
var index: Int = 0, |
|
|
|
|
var text: CharSequence = App.INSTANCE.getString(R.string.data_loading), |
|
|
|
|
var text: String = App.INSTANCE.getString(R.string.data_loading), |
|
|
|
|
var title: String = "", |
|
|
|
|
val textLines: ArrayList<TextLine> = arrayListOf(), |
|
|
|
|
var pageSize: Int = 0, |
|
|
|
@ -22,16 +21,28 @@ data class TextPage( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun upPageAloudSpan(pageStart: Int) { |
|
|
|
|
if (text is SpannableStringBuilder) { |
|
|
|
|
removePageAloudSpan() |
|
|
|
|
var lineStart = 0 |
|
|
|
|
for (textLine in textLines) { |
|
|
|
|
for ((index, textLine) in textLines.withIndex()) { |
|
|
|
|
if (pageStart > lineStart && pageStart < lineStart + textLine.text.length) { |
|
|
|
|
textLine.isReadAloud = true |
|
|
|
|
for (i in index - 1 downTo 0) { |
|
|
|
|
if (textLines[i].text.endsWith("\n")) { |
|
|
|
|
break |
|
|
|
|
} else { |
|
|
|
|
textLines[i].isReadAloud = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (i in index until textLines.size) { |
|
|
|
|
if (textLines[i].text.endsWith("\n")) { |
|
|
|
|
textLines[i].isReadAloud = true |
|
|
|
|
break |
|
|
|
|
} else { |
|
|
|
|
textLines[i].isReadAloud = true |
|
|
|
|
} |
|
|
|
|
lineStart += textLine.text.length |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
lineStart += textLine.text.length |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|