修复滚动bug

pull/436/head
gedoor 4 years ago
parent 5f0a55ea61
commit 67270fc824
  1. 29
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@ -23,7 +23,9 @@ import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefBoolean
import kotlinx.coroutines.CoroutineScope
/**
* 阅读内容界面
*/
class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble)
var upView: ((TextPage) -> Unit)? = null
@ -41,7 +43,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
//滚动参数
private val pageFactory: TextPageFactory get() = callBack.pageFactory
private val maxScrollOffset = 100f
private var pageOffset = 0f
init {
@ -173,17 +174,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
*/
fun onScroll(mOffset: Float) {
if (mOffset == 0f) return
var offset = mOffset
if (offset > maxScrollOffset) {
offset = maxScrollOffset
} else if (offset < -maxScrollOffset) {
offset = -maxScrollOffset
}
pageOffset += offset
pageOffset += mOffset
if (!pageFactory.hasPrev() && pageOffset > 0) {
pageOffset = 0f
} else if (!pageFactory.hasNext() && pageOffset < 0) {
} else if (!pageFactory.hasNext()
&& pageOffset < 0
&& pageOffset + textPage.height < ChapterProvider.visibleHeight
) {
pageOffset = 0f
} else if (pageOffset > 0) {
pageFactory.moveToPrev(false)
@ -263,7 +260,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.start && x < textChar.end) {
if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) {
if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt(selectEnd)) {
if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt(
selectEnd
)
) {
return
}
selectStart[0] = relativePos
@ -306,7 +306,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (x > textChar.start && x < textChar.end) {
Log.e("char", "$relativePos $lineIndex $charIndex")
if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) {
if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt(selectStart)) {
if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt(
selectStart
)
) {
return
}
selectEnd[0] = relativePos

Loading…
Cancel
Save