From 0b7e210051da8dc2d0a95020b791cd7dfb9c3c4d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 21 Oct 2019 10:13:55 +0800 Subject: [PATCH] up --- .../page/delegate/HorizontalPageDelegate.kt | 3 -- .../ui/widget/page/delegate/PageDelegate.kt | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/HorizontalPageDelegate.kt index 1f0e377a2..1f2b3fa42 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/HorizontalPageDelegate.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.widget.page.delegate import android.view.MotionEvent import io.legado.app.ui.widget.page.PageView import io.legado.app.utils.screenshot -import io.legado.app.utils.snackbar import kotlin.math.abs abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) { @@ -23,7 +22,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie //如果上一页不存在 if (!hasPrev()) { noNext = true - pageView.snackbar("没有上一页") return true } //上一页截图 @@ -32,7 +30,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie //如果不存在表示没有下一页了 if (!hasNext()) { noNext = true - pageView.snackbar("没有下一页") return true } //下一页截图 diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt index b70a1ac6d..d094e4a82 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt @@ -8,9 +8,11 @@ import android.view.MotionEvent import android.widget.Scroller import androidx.annotation.CallSuper 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.PageView import io.legado.app.utils.screenshot +import io.legado.app.utils.snackbar import kotlin.math.abs 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 atBottom: Boolean = false + private var snackbar: Snackbar? = null + private val scroller: Scroller by lazy { Scroller( pageView.context, @@ -285,12 +289,36 @@ abstract class PageDelegate(protected val pageView: PageView) { fun hasPrev(): Boolean { //上一页的参数配置 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 { //进行下一页的配置 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 } } \ No newline at end of file