优化翻页

pull/357/head
gedoor 4 years ago
parent b1f5f15eae
commit ade4632e4c
  1. 7
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  3. 11
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -49,6 +49,9 @@ class PageView(context: Context, attrs: AttributeSet) :
var touchX: Float = 0f var touchX: Float = 0f
var touchY: Float = 0f var touchY: Float = 0f
//是否停止动画动作
var isAbortAnim = false
//长按 //长按
private var longPressed = false private var longPressed = false
private val longPressTimeout = 800L private val longPressTimeout = 800L
@ -227,7 +230,9 @@ class PageView(context: Context, attrs: AttributeSet) :
return true return true
} }
if (centerRectF.contains(startX, startY)) { if (centerRectF.contains(startX, startY)) {
callBack.clickCenter() if (!isAbortAnim) {
callBack.clickCenter()
}
} else if (ReadBookConfig.clickTurnPage) { } else if (ReadBookConfig.clickTurnPage) {
if (startX > width / 2 || AppConfig.clickAllNext) { if (startX > width / 2 || AppConfig.clickAllNext) {
pageDelegate?.nextPageByAnim(defaultAnimationSpeed) pageDelegate?.nextPageByAnim(defaultAnimationSpeed)

@ -100,6 +100,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
override fun abortAnim() { override fun abortAnim() {
if (!scroller.isFinished) { if (!scroller.isFinished) {
pageView.isAbortAnim = true
scroller.abortAnimation() scroller.abortAnimation()
isStarted = false isStarted = false
isMoved = false isMoved = false
@ -108,6 +109,8 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
pageView.fillPage(mDirection) pageView.fillPage(mDirection)
pageView.invalidate() pageView.invalidate()
} }
} else {
pageView.isAbortAnim = false
} }
} }

@ -86,18 +86,25 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
override fun abortAnim() { override fun abortAnim() {
if (!scroller.isFinished) { if (!scroller.isFinished) {
pageView.isAbortAnim = true
scroller.abortAnimation() scroller.abortAnimation()
} else {
pageView.isAbortAnim = false
} }
} }
override fun nextPageByAnim(animationSpeed: Int) { override fun nextPageByAnim(animationSpeed: Int) {
abortAnim() if (pageView.isAbortAnim) {
return
}
pageView.setStartPoint(0f, 0f, false) pageView.setStartPoint(0f, 0f, false)
startScroll(0, 0, 0, -ChapterProvider.visibleHeight, animationSpeed) startScroll(0, 0, 0, -ChapterProvider.visibleHeight, animationSpeed)
} }
override fun prevPageByAnim(animationSpeed: Int) { override fun prevPageByAnim(animationSpeed: Int) {
abortAnim() if (pageView.isAbortAnim) {
return
}
pageView.setStartPoint(0f, 0f, false) pageView.setStartPoint(0f, 0f, false)
startScroll(0, 0, 0, ChapterProvider.visibleHeight, animationSpeed) startScroll(0, 0, 0, ChapterProvider.visibleHeight, animationSpeed)
} }

Loading…
Cancel
Save