diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index c6839b214..ee098e22c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -26,12 +26,12 @@ class PageView(context: Context, attrs: AttributeSet) : init { callBack = activity as CallBack - prevPage = ContentView(context) - addView(prevPage) nextPage = ContentView(context) addView(nextPage) curPage = ContentView(context) addView(curPage) + prevPage = ContentView(context) + addView(prevPage) upBg() setWillNotDraw(false) pageFactory = TextPageFactory(this) @@ -40,6 +40,7 @@ class PageView(context: Context, attrs: AttributeSet) : override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) + prevPage.x = -w.toFloat() pageDelegate?.setViewSize(w, h) if (oldw != 0 && oldh != 0) { ReadBook.loadContent() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt index 21ffcee77..c7d342213 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt @@ -1,14 +1,12 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.Canvas -import android.graphics.Matrix import android.graphics.drawable.GradientDrawable import io.legado.app.ui.book.read.page.PageView class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { private val shadowDrawableR: GradientDrawable - private val bitmapMatrix = Matrix() init { val shadowColors = intArrayOf(0x66111111, 0x00000000) @@ -38,17 +36,9 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { viewWidth - (touchX - startX) } } - startScroll(touchX.toInt(), 0, distanceX.toInt(), 0) } - override fun onAnimStop() { - curPage.x = 0.toFloat() - if (!isCancel) { - pageView.fillPage(mDirection) - } - } - override fun onDraw(canvas: Canvas) { val offsetX = touchX - startX @@ -57,15 +47,13 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { ) return val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth - bitmap?.let { - if (mDirection == Direction.PREV) { - bitmapMatrix.setTranslate(distanceX, 0.toFloat()) - canvas.drawBitmap(it, bitmapMatrix, null) - } else if (mDirection == Direction.NEXT) { - curPage.translationX = offsetX - } - addShadow(distanceX.toInt(), canvas) + if (!isMoved) return + if (mDirection == Direction.PREV) { + prevPage.translationX = offsetX - viewWidth + } else if (mDirection == Direction.NEXT) { + curPage.translationX = offsetX } + addShadow(distanceX.toInt(), canvas) } private fun addShadow(left: Int, canvas: Canvas) { @@ -77,4 +65,13 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { shadowDrawableR.draw(canvas) } } + + override fun onAnimStop() { + curPage.x = 0.toFloat() + prevPage.x = -viewWidth.toFloat() + if (!isCancel) { + pageView.fillPage(mDirection) + } + } + } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 700728b14..b42d04738 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -8,6 +8,9 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie override fun onTouch(event: MotionEvent) { when (event.action) { + MotionEvent.ACTION_DOWN -> { + abort() + } MotionEvent.ACTION_MOVE -> { if (isTextSelected) { selectText(event) @@ -32,7 +35,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie return } setDirection(Direction.PREV) - setBitmap() } else { //如果不存在表示没有下一页了 if (!hasNext()) { @@ -40,7 +42,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie return } setDirection(Direction.NEXT) - setBitmap() } } } @@ -55,7 +56,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie override fun nextPageByAnim() { if (!hasNext()) return setDirection(Direction.NEXT) - setBitmap() setTouchPoint(viewWidth.toFloat(), 0f) onAnimStart() } @@ -63,8 +63,8 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie override fun prevPageByAnim() { if (!hasPrev()) return setDirection(Direction.PREV) - setBitmap() setTouchPoint(0f, 0f) onAnimStart() } + } \ No newline at end of file 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 76b40fb78..3ad9c31ce 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 @@ -1,7 +1,6 @@ package io.legado.app.ui.book.read.page.delegate import android.content.Context -import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.RectF import android.view.GestureDetector @@ -15,7 +14,6 @@ import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.page.ContentView import io.legado.app.ui.book.read.page.PageView -import io.legado.app.utils.screenshot import kotlin.math.abs abstract class PageDelegate(protected val pageView: PageView) : @@ -40,8 +38,6 @@ abstract class PageDelegate(protected val pageView: PageView) : protected val curPage: ContentView get() = pageView.curPage protected val prevPage: ContentView get() = pageView.prevPage - protected var bitmap: Bitmap? = null - protected var viewWidth: Int = pageView.width protected var viewHeight: Int = pageView.height @@ -126,11 +122,10 @@ abstract class PageDelegate(protected val pageView: PageView) : } private fun stopScroll() { + isMoved = false isRunning = false isStarted = false pageView.invalidate() - bitmap?.recycle() - bitmap = null } open fun setViewSize(width: Int, height: Int) { @@ -175,14 +170,6 @@ abstract class PageDelegate(protected val pageView: PageView) : mDirection = direction } - open fun setBitmap() { - bitmap = when (mDirection) { - Direction.NEXT -> nextPage.screenshot() - Direction.PREV -> prevPage.screenshot() - else -> null - } - } - /** * 触摸事件处理 */ @@ -321,7 +308,7 @@ abstract class PageDelegate(protected val pageView: PageView) : } open fun onDestroy() { - bitmap?.recycle() + } enum class Direction { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 6d7dd7bf8..2d587ad2b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -142,6 +142,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi override fun setDirection(direction: Direction) { super.setDirection(direction) + setBitmap() when (direction) { Direction.PREV -> //上一页滑动不出现对角 @@ -158,7 +159,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } } - override fun setBitmap() { + fun setBitmap() { when (mDirection) { Direction.PREV -> { prevBitmap = prevPage.screenshot() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt index 0308d965e..097ef41d9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt @@ -1,13 +1,10 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.Canvas -import android.graphics.Matrix import io.legado.app.ui.book.read.page.PageView class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { - private val bitmapMatrix = Matrix() - override fun onAnimStart() { val distanceX: Float when (mDirection) { @@ -28,7 +25,6 @@ class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { viewWidth - (touchX - startX) } } - startScroll(touchX.toInt(), 0, distanceX.toInt(), 0) } @@ -39,26 +35,19 @@ class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { || (mDirection == Direction.PREV && offsetX < 0) ) return - val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth - bitmap?.let { - bitmapMatrix.setTranslate(distanceX, 0.toFloat()) - canvas.drawBitmap(it, bitmapMatrix, null) + if (!isMoved) return + if (mDirection == Direction.PREV) { + prevPage.translationX = offsetX - viewWidth + curPage.translationX = offsetX + } else if (mDirection == Direction.NEXT) { + curPage.translationX = offsetX + nextPage.translationX = curPage.x + viewWidth } } - override fun onScroll() { - val offsetX = touchX - startX - - if ((mDirection == Direction.NEXT && offsetX > 0) - || (mDirection == Direction.PREV && offsetX < 0) - ) return - - curPage.translationX = offsetX - } - override fun onAnimStop() { curPage.x = 0.toFloat() - + prevPage.x = -viewWidth.toFloat() if (!isCancel) { pageView.fillPage(mDirection) }