feat: 优化代码

pull/115/head
kunfei 5 years ago
parent f83479ab8a
commit 41ea3a7eb4
  1. 18
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -34,14 +34,9 @@ abstract class PageDelegate(protected val pageView: PageView) :
protected var touchX: Float = 0f protected var touchX: Float = 0f
protected var touchY: Float = 0f protected var touchY: Float = 0f
protected val nextPage: ContentView protected val nextPage: ContentView get() = pageView.nextPage
get() = pageView.nextPage protected val curPage: ContentView get() = pageView.curPage
protected val prevPage: ContentView get() = pageView.prevPage
protected val curPage: ContentView
get() = pageView.curPage
protected val prevPage: ContentView
get() = pageView.prevPage
protected var bitmap: Bitmap? = null protected var bitmap: Bitmap? = null
@ -90,7 +85,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
touchY = y touchY = y
if (invalidate) { if (invalidate) {
pageView.postInvalidate() pageView.invalidate()
} }
onScroll() onScroll()
@ -187,12 +182,11 @@ abstract class PageDelegate(protected val pageView: PageView) :
abstract fun onAnimStart()//scroller start abstract fun onAnimStart()//scroller start
abstract fun onDraw(canvas: Canvas)//绘制 open fun onDraw(canvas: Canvas) {}//绘制
abstract fun onAnimStop()//scroller finish abstract fun onAnimStop()//scroller finish
open fun onScroll() {//移动contentView, slidePage open fun onScroll() {}//移动contentView, slidePage
}
@CallSuper @CallSuper
open fun setDirection(direction: Direction) { open fun setDirection(direction: Direction) {

@ -1,6 +1,5 @@
package io.legado.app.ui.book.read.page.delegate package io.legado.app.ui.book.read.page.delegate
import android.graphics.Canvas
import android.view.MotionEvent import android.view.MotionEvent
import android.view.VelocityTracker import android.view.VelocityTracker
import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.PageView
@ -21,7 +20,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
) )
} }
override fun onDraw(canvas: Canvas) { override fun onScroll() {
curPage.onScroll(touchY - lastY) curPage.onScroll(touchY - lastY)
} }

Loading…
Cancel
Save