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 fc0576f60..fb7ad11c5 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 @@ -4,6 +4,7 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.util.AttributeSet +import android.util.Log import android.view.View import io.legado.app.R import io.legado.app.constant.PreferKey @@ -80,10 +81,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private fun drawScrollPage(canvas: Canvas) { textPage.textLines.forEach { textLine -> - val yPy = pageOffset - val lineTop = textLine.lineTop + yPy - val lineBase = textLine.lineBase + yPy - val lineBottom = textLine.lineBottom + yPy + val lineTop = textLine.lineTop + pageOffset + val lineBase = textLine.lineBase + pageOffset + val lineBottom = textLine.lineBottom + pageOffset drawChars( canvas, textLine.textChars, @@ -148,7 +148,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at fun onScroll(mOffset: Float) { if (mOffset == 0f) return - var offset = -mOffset + var offset = mOffset if (offset > maxScrollOffset) { offset = maxScrollOffset } else if (offset < -maxScrollOffset) { @@ -159,6 +159,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (pageOffset > 0) { pageFactory.moveToPrev() textPage = pageFactory.currentPage ?: TextPage().format() + Log.e("pageOffSet", pageOffset.toString() + " " + textPage.height) pageOffset -= textPage.height callBack.upContent(0, false) } else if (pageOffset < -textPage.height) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index d0d6ac377..3140e6d1a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -100,6 +100,7 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.resetPageOffset() content_text_view.setContent(textPage) } + content_text_view.invalidate() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 2a90c79f1..681159059 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -6,9 +6,9 @@ import android.graphics.Canvas import android.graphics.RectF import android.view.GestureDetector import android.view.MotionEvent +import android.view.animation.DecelerateInterpolator import android.widget.Scroller import androidx.annotation.CallSuper -import androidx.interpolator.view.animation.FastOutLinearInInterpolator import com.google.android.material.snackbar.Snackbar import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig @@ -47,16 +47,13 @@ abstract class PageDelegate(protected val pageView: PageView) : protected var viewWidth: Int = pageView.width protected var viewHeight: Int = pageView.height - //textView在顶端或低端 - protected var atTop: Boolean = false - protected var atBottom: Boolean = false private val snackBar: Snackbar by lazy { Snackbar.make(pageView, "", Snackbar.LENGTH_SHORT) } private val scroller: Scroller by lazy { - Scroller(pageView.context, FastOutLinearInInterpolator()) + Scroller(pageView.context, DecelerateInterpolator()) } private val detector: GestureDetector by lazy { @@ -83,7 +80,7 @@ abstract class PageDelegate(protected val pageView: PageView) : touchY = y if (invalidate) { - invalidate() + pageView.invalidate() } } @@ -93,7 +90,7 @@ abstract class PageDelegate(protected val pageView: PageView) : touchY = y if (invalidate) { - invalidate() + pageView.postInvalidate() } onScroll() @@ -103,10 +100,6 @@ abstract class PageDelegate(protected val pageView: PageView) : detector.setIsLongpressEnabled(selectAble) } - protected fun invalidate() { - pageView.invalidate() - } - open fun fling( startX: Int, startY: Int, velocityX: Int, velocityY: Int, minX: Int, maxX: Int, minY: Int, maxY: Int @@ -114,7 +107,7 @@ abstract class PageDelegate(protected val pageView: PageView) : scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY) isRunning = true isStarted = true - invalidate() + pageView.invalidate() } protected fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int) { @@ -127,13 +120,13 @@ abstract class PageDelegate(protected val pageView: PageView) : ) isRunning = true isStarted = true - invalidate() + pageView.invalidate() } private fun stopScroll() { isRunning = false isStarted = false - invalidate() + pageView.invalidate() bitmap?.recycle() bitmap = null } @@ -141,7 +134,7 @@ abstract class PageDelegate(protected val pageView: PageView) : fun setViewSize(width: Int, height: Int) { viewWidth = width viewHeight = height - invalidate() + pageView.invalidate() centerRectF.set( width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index c9e097808..894e4b9b8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -22,7 +22,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } override fun onDraw(canvas: Canvas) { - curPage.onScroll(lastY - touchY) + curPage.onScroll(touchY - lastY) } override fun onAnimStop() { @@ -52,23 +52,19 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { if (!isMoved && abs(distanceX) < abs(distanceY)) { if (distanceY < 0) { - if (atTop) { - //如果上一页不存在 - if (!hasPrev()) { - noNext = true - return true - } - setDirection(Direction.PREV) + //如果上一页不存在 + if (!hasPrev()) { + noNext = true + return true } + setDirection(Direction.PREV) } else { - if (atBottom) { - //如果不存在表示没有下一页了 - if (!hasNext()) { - noNext = true - return true - } - setDirection(Direction.NEXT) + //如果上一页不存在 + if (!hasNext()) { + noNext = true + return true } + setDirection(Direction.PREV) } isMoved = true }