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 db7ccc13d..a48778686 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 @@ -166,10 +166,10 @@ object ChapterProvider { textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineBottom = paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex)) - textLine.lineTop = paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex)) + textLine.lineBottom = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() + textLine.lineTop = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() val words = title.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) @@ -246,10 +246,10 @@ object ChapterProvider { textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineBottom = paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex)) - textLine.lineTop = paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex)) + textLine.lineBottom = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() + textLine.lineTop = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() var words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 059f0ad8c..b2db492cc 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -9,6 +9,7 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor +import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.activity import io.legado.app.utils.getCompatColor @@ -31,8 +32,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private var textPage: TextPage? = null //滚动参数 private val maxScrollOffset = 100f - private val pageOffset = 0f - private val isLastPage = false + private var pageOffset = 0f + private var isLastPage = false init { activityCallBack = activity as CallBack @@ -70,15 +71,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at canvas.drawText( it.charData, it.leftBottomPosition.x, - it.leftBottomPosition.y.toFloat(), + it.leftBottomPosition.y, textPaint ) if (it.selected) { canvas.drawRect( it.leftBottomPosition.x, - it.rightTopPosition.y.toFloat(), + it.rightTopPosition.y, it.rightTopPosition.x, - it.leftBottomPosition.y.toFloat(), + it.leftBottomPosition.y, selectedPaint ) } @@ -87,14 +88,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } - fun onScroll(offset: Float) { - var mOffset = offset + fun onScroll(mOffset: Float) { + var offset = mOffset if (offset > maxScrollOffset) { - mOffset = maxScrollOffset + offset = maxScrollOffset } else if (offset < -maxScrollOffset) { - mOffset = -maxScrollOffset + offset = -maxScrollOffset } + if (!isLastPage || offset < 0) { + pageOffset += offset + isLastPage = false + } + // 首页 + if (pageOffset < 0 && ReadBook.durChapterIndex == 0 && ReadBook.durPageIndex == 0) { + pageOffset = 0f + } } @@ -112,11 +121,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectCharEnd = charIndex upSelectedStart( textChar.leftBottomPosition.x, - textChar.leftBottomPosition.y.toFloat() + textChar.leftBottomPosition.y ) upSelectedEnd( textChar.rightTopPosition.x, - textChar.leftBottomPosition.y.toFloat() + textChar.leftBottomPosition.y ) return true } @@ -139,7 +148,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectCharStart = charIndex upSelectedStart( textChar.leftBottomPosition.x, - textChar.leftBottomPosition.y.toFloat() + textChar.leftBottomPosition.y ) upSelectChars(textPage) } @@ -163,7 +172,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectCharEnd = charIndex upSelectedEnd( textChar.rightTopPosition.x, - textChar.leftBottomPosition.y.toFloat() + textChar.leftBottomPosition.y ) upSelectChars(textPage) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt deleted file mode 100644 index 0be88dae6..000000000 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.legado.app.ui.book.read.page.entities - -data class SelectPoint( - var startX: Float, - var startY: Float, - var endX: Float, - var endY: Float -) \ No newline at end of file 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 c5282aba3..00ae4bff6 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 @@ -3,8 +3,8 @@ 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, + var lineTop: Float = 0f, + var lineBottom: Float = 0f, val isTitle: Boolean = false, var isReadAloud: Boolean = false ) \ No newline at end of file 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 653f352e5..92d91b1e5 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 @@ -10,7 +10,8 @@ data class TextPage( val textLines: ArrayList = arrayListOf(), var pageSize: Int = 0, var chapterSize: Int = 0, - var chapterIndex: Int = 0 + var chapterIndex: Int = 0, + var height: Int = 0 ) { fun removePageAloudSpan(): TextPage { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt index 44b81c2a9..07bb142b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt @@ -2,5 +2,5 @@ package io.legado.app.ui.book.read.page.entities data class TextPoint( val x: Float, - val y: Int + val y: Float ) \ No newline at end of file