|
|
@ -10,13 +10,16 @@ import android.widget.Scroller |
|
|
|
import androidx.annotation.CallSuper |
|
|
|
import androidx.annotation.CallSuper |
|
|
|
import androidx.interpolator.view.animation.FastOutLinearInInterpolator |
|
|
|
import androidx.interpolator.view.animation.FastOutLinearInInterpolator |
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
import com.google.android.material.snackbar.Snackbar |
|
|
|
|
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.ui.book.read.page.ContentView |
|
|
|
import io.legado.app.ui.book.read.page.ContentView |
|
|
|
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.screenshot |
|
|
|
import io.legado.app.utils.screenshot |
|
|
|
import kotlin.math.abs |
|
|
|
import kotlin.math.abs |
|
|
|
|
|
|
|
|
|
|
|
abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
abstract class PageDelegate(protected val pageView: PageView) : |
|
|
|
|
|
|
|
GestureDetector.SimpleOnGestureListener() { |
|
|
|
val centerRectF = RectF( |
|
|
|
val centerRectF = RectF( |
|
|
|
pageView.width * 0.33f, pageView.height * 0.33f, |
|
|
|
pageView.width * 0.33f, pageView.height * 0.33f, |
|
|
|
pageView.width * 0.66f, pageView.height * 0.66f |
|
|
|
pageView.width * 0.66f, pageView.height * 0.66f |
|
|
@ -51,17 +54,13 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val scroller: Scroller by lazy { |
|
|
|
private val scroller: Scroller by lazy { |
|
|
|
Scroller( |
|
|
|
Scroller(pageView.context, FastOutLinearInInterpolator()) |
|
|
|
pageView.context, |
|
|
|
|
|
|
|
FastOutLinearInInterpolator() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val detector: GestureDetector by lazy { |
|
|
|
private val detector: GestureDetector by lazy { |
|
|
|
GestureDetector( |
|
|
|
GestureDetector(pageView.context, this).apply { |
|
|
|
pageView.context, |
|
|
|
setIsLongpressEnabled(context.getPrefBoolean(PreferKey.selectText)) |
|
|
|
GestureListener() |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var isMoved = false |
|
|
|
var isMoved = false |
|
|
@ -188,13 +187,6 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
open fun onScroll() {//移动contentView, slidePage |
|
|
|
open fun onScroll() {//移动contentView, slidePage |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
abstract fun onScroll( |
|
|
|
|
|
|
|
e1: MotionEvent, |
|
|
|
|
|
|
|
e2: MotionEvent, |
|
|
|
|
|
|
|
distanceX: Float, |
|
|
|
|
|
|
|
distanceY: Float |
|
|
|
|
|
|
|
): Boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class Direction { |
|
|
|
enum class Direction { |
|
|
|
NONE, PREV, NEXT |
|
|
|
NONE, PREV, NEXT |
|
|
|
} |
|
|
|
} |
|
|
@ -223,10 +215,8 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 触摸事件处理 |
|
|
|
* 按下 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDown(e: MotionEvent): Boolean { |
|
|
|
override fun onDown(e: MotionEvent): Boolean { |
|
|
|
// abort() |
|
|
|
// abort() |
|
|
|
//是否移动 |
|
|
|
//是否移动 |
|
|
@ -244,6 +234,9 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 单击 |
|
|
|
|
|
|
|
*/ |
|
|
|
override fun onSingleTapUp(e: MotionEvent): Boolean { |
|
|
|
override fun onSingleTapUp(e: MotionEvent): Boolean { |
|
|
|
val x = e.x |
|
|
|
val x = e.x |
|
|
|
val y = e.y |
|
|
|
val y = e.y |
|
|
@ -273,15 +266,9 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onScroll( |
|
|
|
/** |
|
|
|
e1: MotionEvent, |
|
|
|
* 移动结束 |
|
|
|
e2: MotionEvent, |
|
|
|
*/ |
|
|
|
distanceX: Float, |
|
|
|
|
|
|
|
distanceY: Float |
|
|
|
|
|
|
|
): Boolean { |
|
|
|
|
|
|
|
return this@PageDelegate.onScroll(e1, e2, distanceX, distanceY) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onFling( |
|
|
|
override fun onFling( |
|
|
|
e1: MotionEvent?, |
|
|
|
e1: MotionEvent?, |
|
|
|
e2: MotionEvent?, |
|
|
|
e2: MotionEvent?, |
|
|
@ -291,10 +278,11 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
if (!noNext) onAnimStart() |
|
|
|
if (!noNext) onAnimStart() |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 判断是否有上一页 |
|
|
|
|
|
|
|
*/ |
|
|
|
fun hasPrev(): Boolean { |
|
|
|
fun hasPrev(): Boolean { |
|
|
|
//上一页的参数配置 |
|
|
|
|
|
|
|
val hasPrev = pageView.pageFactory?.hasPrev() == true |
|
|
|
val hasPrev = pageView.pageFactory?.hasPrev() == true |
|
|
|
if (!hasPrev) { |
|
|
|
if (!hasPrev) { |
|
|
|
if (!snackBar.isShown) { |
|
|
|
if (!snackBar.isShown) { |
|
|
@ -305,8 +293,10 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
return hasPrev |
|
|
|
return hasPrev |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 判断是否有下一页 |
|
|
|
|
|
|
|
*/ |
|
|
|
fun hasNext(): Boolean { |
|
|
|
fun hasNext(): Boolean { |
|
|
|
//进行下一页的配置 |
|
|
|
|
|
|
|
val hasNext = pageView.pageFactory?.hasNext() == true |
|
|
|
val hasNext = pageView.pageFactory?.hasNext() == true |
|
|
|
if (!hasNext) { |
|
|
|
if (!hasNext) { |
|
|
|
if (!snackBar.isShown) { |
|
|
|
if (!snackBar.isShown) { |
|
|
|