pull/38/head
kunfei 5 years ago
parent 6038d2cb56
commit 0b7e210051
  1. 3
      app/src/main/java/io/legado/app/ui/widget/page/delegate/HorizontalPageDelegate.kt
  2. 32
      app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt

@ -3,7 +3,6 @@ package io.legado.app.ui.widget.page.delegate
import android.view.MotionEvent import android.view.MotionEvent
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import io.legado.app.utils.snackbar
import kotlin.math.abs import kotlin.math.abs
abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) { abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) {
@ -23,7 +22,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
//如果上一页不存在 //如果上一页不存在
if (!hasPrev()) { if (!hasPrev()) {
noNext = true noNext = true
pageView.snackbar("没有上一页")
return true return true
} }
//上一页截图 //上一页截图
@ -32,7 +30,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
//如果不存在表示没有下一页了 //如果不存在表示没有下一页了
if (!hasNext()) { if (!hasNext()) {
noNext = true noNext = true
pageView.snackbar("没有下一页")
return true return true
} }
//下一页截图 //下一页截图

@ -8,9 +8,11 @@ import android.view.MotionEvent
import android.widget.Scroller 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 io.legado.app.ui.widget.page.ContentView import io.legado.app.ui.widget.page.ContentView
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import io.legado.app.utils.snackbar
import kotlin.math.abs import kotlin.math.abs
abstract class PageDelegate(protected val pageView: PageView) { abstract class PageDelegate(protected val pageView: PageView) {
@ -42,6 +44,8 @@ abstract class PageDelegate(protected val pageView: PageView) {
protected var atTop: Boolean = false protected var atTop: Boolean = false
protected var atBottom: Boolean = false protected var atBottom: Boolean = false
private var snackbar: Snackbar? = null
private val scroller: Scroller by lazy { private val scroller: Scroller by lazy {
Scroller( Scroller(
pageView.context, pageView.context,
@ -285,12 +289,36 @@ abstract class PageDelegate(protected val pageView: PageView) {
fun hasPrev(): Boolean { fun hasPrev(): Boolean {
//上一页的参数配置 //上一页的参数配置
direction = Direction.PREV direction = Direction.PREV
return pageView.pageFactory?.hasPrev() == true val hasPrev = pageView.pageFactory?.hasPrev() == true
if (!hasPrev) {
snackbar ?: let {
snackbar = pageView.snackbar("没有上一页")
}
snackbar?.let {
if (!it.isShown) {
it.setText("没有上一页")
it.show()
}
}
}
return hasPrev
} }
fun hasNext(): Boolean { fun hasNext(): Boolean {
//进行下一页的配置 //进行下一页的配置
direction = Direction.NEXT direction = Direction.NEXT
return pageView.pageFactory?.hasNext() == true val hasNext = pageView.pageFactory?.hasNext() == true
if (!hasNext) {
snackbar ?: let {
snackbar = pageView.snackbar("没有下一页")
}
snackbar?.let {
if (!it.isShown) {
it.setText("没有下一页")
it.show()
}
}
}
return hasNext
} }
} }
Loading…
Cancel
Save