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

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

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

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

Loading…
Cancel
Save