feat: 优化代码

pull/111/head
kunfei 5 years ago
parent 33db7eed5b
commit 9f0241d272
  1. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  4. 40
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -621,6 +621,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
super.onDestroy()
mHandler.removeCallbacks(keepScreenRunnable)
textActionMenu?.dismiss()
page_view.pageDelegate?.onDestroy()
}
override fun observeLiveBus() {

@ -91,6 +91,7 @@ class PageView(context: Context, attrs: AttributeSet) :
}
fun upPageAnim(pageAnim: Int) {
pageDelegate?.onDestroy()
pageDelegate = null
pageDelegate = when (pageAnim) {
0 -> CoverPageDelegate(this)

@ -323,6 +323,10 @@ abstract class PageDelegate(protected val pageView: PageView) :
return hasNext
}
open fun onDestroy() {
bitmap?.recycle()
}
enum class Direction {
NONE, PREV, NEXT
}

@ -2,37 +2,19 @@ package io.legado.app.ui.book.read.page.delegate
import android.graphics.Canvas
import android.view.MotionEvent
import android.view.VelocityTracker
import io.legado.app.ui.book.read.page.PageView
import kotlin.math.abs
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
// 滑动追踪的时间
private val VELOCITY_DURATION = 1000
//速度追踪器
private val mVelocity: VelocityTracker = VelocityTracker.obtain()
override fun onAnimStart() {
if (!atTop && !atBottom) {
stopScroll()
return
}
val distanceY: Float
when (mDirection) {
Direction.NEXT -> distanceY =
if (isCancel) {
var dis = viewHeight - startY + touchY
if (dis > viewHeight) {
dis = viewHeight.toFloat()
}
viewHeight - dis
} else {
-(touchY + (viewHeight - startY))
}
else -> distanceY =
if (isCancel) {
-(touchY - startY)
} else {
viewHeight - (touchY - startY)
}
}
startScroll(0, touchY.toInt(), 0, distanceY.toInt())
}
override fun onDraw(canvas: Canvas) {
@ -45,6 +27,11 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
}
}
override fun onDown(e: MotionEvent): Boolean {
mVelocity.clear()
return super.onDown(e)
}
override fun onScroll(
e1: MotionEvent,
e2: MotionEvent,
@ -94,4 +81,9 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
return isMoved
}
override fun onDestroy() {
super.onDestroy()
mVelocity.recycle()
}
}
Loading…
Cancel
Save