优化代码

pull/743/head
gedoor 4 years ago
parent 2801aac80e
commit 082b8503b0
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 9
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  5. 10
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt

@ -430,7 +430,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onMenuItemSelected(itemId: Int): Boolean {
when (itemId) {
R.id.menu_bookmark -> binding.readView.curPage.let {
showBookMark(0, it.selectedText)
showBookMark(it.selectStartPos, it.selectedText)
return true
}
R.id.menu_replace -> {

@ -482,12 +482,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
val selectStartPos: Int
get() {
for (i in 0 until selectStart[0]) {
val page = relativePage(selectStart[0])
page.getTextChapter()?.let {
return it.getReadLength(page.index) +
page.getSelectStartLength(selectStart[1], selectStart[2])
}
return 0
}

@ -272,5 +272,7 @@ class PageView(context: Context) : FrameLayout(context) {
val selectedText: String get() = binding.contentTextView.selectedText
val selectStartPos get() = binding.contentTextView.selectStartPos
val textPage get() = binding.contentTextView.textPage
}

@ -16,6 +16,8 @@ data class TextLine(
var isReadAloud: Boolean = false
) {
val charSize: Int get() = textChars.size
fun upTopBottom(durY: Float, textPaint: TextPaint) {
lineTop = ChapterProvider.paddingTop + durY
lineBottom = lineTop + textPaint.textHeight

@ -8,6 +8,7 @@ import io.legado.app.help.ReadBookConfig
import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import java.text.DecimalFormat
import kotlin.math.min
@Suppress("unused")
data class TextPage(
@ -124,6 +125,15 @@ data class TextPage(
return percent
}
fun getSelectStartLength(lineIndex: Int, charIndex: Int): Int {
var length = 0
val maxIndex = min(lineIndex, lineSize)
for (index in 0 until maxIndex) {
length += textLines[index].charSize
}
return length + charIndex
}
fun getTextChapter(): TextChapter? {
ReadBook.curTextChapter?.let {
if (it.position == chapterIndex) {

Loading…
Cancel
Save