feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 21a8a94341
commit 56531a08df
  1. 7
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  2. 17
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt
  4. 16
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt

@ -4,7 +4,6 @@ import android.view.MotionEvent
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.screenshot
import kotlin.math.abs
abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) {
@ -27,8 +26,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
return true
}
setDirection(Direction.PREV)
//上一页截图
bitmap = prevPage.screenshot()
setBitmap()
} else {
//如果不存在表示没有下一页了
if (!hasNext()) {
@ -36,8 +34,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
return true
}
setDirection(Direction.NEXT)
//下一页截图
bitmap = nextPage.screenshot()
setBitmap()
}
isMoved = true
}

@ -231,10 +231,19 @@ abstract class PageDelegate(protected val pageView: PageView) {
NONE, PREV, NEXT
}
@CallSuper
open fun setDirection(direction: Direction) {
mDirection = direction
}
open fun setBitmap() {
bitmap = when (mDirection) {
Direction.NEXT -> nextPage.screenshot()
Direction.PREV -> prevPage.screenshot()
else -> null
}
}
/**
* 触摸事件处理
*/
@ -264,7 +273,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
pageView.callBack?.clickCenter()
setTouchPoint(x, y)
} else {
bitmap = if (x > viewWidth / 2 ||
if (x > viewWidth / 2 ||
AppConfig.clickAllNext
) {
//设置动画方向
@ -272,15 +281,13 @@ abstract class PageDelegate(protected val pageView: PageView) {
return true
}
setDirection(Direction.PREV)
//下一页截图
nextPage.screenshot()
setBitmap()
} else {
if (!hasPrev()) {
return true
}
setDirection(Direction.NEXT)
//上一页截图
prevPage.screenshot()
setBitmap()
}
setTouchPoint(x, y)
onScrollStart()

@ -7,7 +7,6 @@ import android.view.MotionEvent
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.screenshot
import kotlin.math.abs
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
@ -89,8 +88,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
return true
}
setDirection(Direction.PREV)
//上一页截图
bitmap = prevPage.screenshot()
setBitmap()
}
} else {
if (atBottom) {
@ -103,8 +101,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
return true
}
setDirection(Direction.NEXT)
//下一页截图
bitmap = nextPage.screenshot()
setBitmap()
}
}
isMoved = true

@ -4,6 +4,7 @@ import android.graphics.*
import android.graphics.drawable.GradientDrawable
import android.os.Build
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.screenshot
import kotlin.math.*
@Suppress("DEPRECATION")
@ -87,7 +88,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) {
super.setTouchPoint(x, y, invalidate)
//触摸y中间位置吧y变成屏幕高度
//触摸y中间位置吧y变成屏幕高度
if ((startY > pageView.height / 3.0
&& startY < pageView.height * 2 / 3.0)
|| mDirection == Direction.PREV
@ -123,6 +123,20 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
}
}
override fun setBitmap() {
when (mDirection) {
Direction.PREV -> {
prevBitmap = prevPage.screenshot()
curBitmap = curPage.screenshot()
}
Direction.NEXT -> {
nextBitmap = nextPage.screenshot()
curBitmap = curPage.screenshot()
}
else -> Unit
}
}
override fun onScrollStart() {
val distanceX: Float
when (mDirection) {

Loading…
Cancel
Save