From 483bf92003b22a0a63fa205b4b0ac8ed93e08b32 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 6 Oct 2019 17:19:30 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/widget/page/PageView.kt | 1 + .../app/ui/widget/page/curl/CurlView.kt | 22 ++++++++----------- .../ui/widget/page/delegate/PageDelegate.kt | 3 +++ .../page/delegate/SimulationPageDelegate.kt | 6 ++++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 894562639..e1e865830 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -122,6 +122,7 @@ class PageView(context: Context, attrs: AttributeSet) : prevPage?.scrollToBottom() } } + pageDelegate?.onPageUp() } fun moveToPrevPage(noAnim: Boolean = true) { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/curl/CurlView.kt b/app/src/main/java/io/legado/app/ui/widget/page/curl/CurlView.kt index 96f15eac9..086894434 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/curl/CurlView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/curl/CurlView.kt @@ -48,8 +48,6 @@ class CurlView : GLSurfaceView, View.OnTouchListener, CurlRenderer.Observer { private var mPageLeft: CurlMesh private var mPageRight: CurlMesh - private var mPageProvider: PageProvider? = null - private val mPointerPos = PointerPosition() private var mRenderer: CurlRenderer = CurlRenderer(this) @@ -59,6 +57,14 @@ class CurlView : GLSurfaceView, View.OnTouchListener, CurlRenderer.Observer { // One page is the default. private var mViewMode = SHOW_ONE_PAGE + var mPageProvider: PageProvider? = null + set(value) { + field = value + mCurrentIndex = 0 + updatePages() + requestRender() + } + /** * Get current page index. Page indices are zero based values presenting * page being shown on right side of the book. @@ -407,16 +413,6 @@ class CurlView : GLSurfaceView, View.OnTouchListener, CurlRenderer.Observer { mRenderer.setMargins(left, top, right, bottom) } - /** - * Update/set page provider. - */ - fun setPageProvider(pageProvider: PageProvider) { - mPageProvider = pageProvider - mCurrentIndex = 0 - updatePages() - requestRender() - } - /** * Setter for whether left side page is rendered. This is useful mostly for * situations where right (main) page is aligned to left side of screen and @@ -645,7 +641,7 @@ class CurlView : GLSurfaceView, View.OnTouchListener, CurlRenderer.Observer { /** * Updates bitmaps for page meshes. */ - private fun updatePages() { + fun updatePages() { if (mPageProvider == null || mPageBitmapWidth <= 0 || mPageBitmapHeight <= 0 ) { 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 93174923d..a59a6a86b 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 @@ -209,6 +209,9 @@ abstract class PageDelegate(protected val pageView: PageView) { open fun onScroll() {//移动contentView, slidePage } + open fun onPageUp() { + } + enum class Direction { NONE, PREV, NEXT } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt index 4b96fb6cd..0c552bb75 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt @@ -13,7 +13,7 @@ class SimulationPageDelegate(pageView: PageView) : PageDelegate(pageView) { pageView.curlView ?: let { pageView.curlView = CurlView(pageView.context) pageView.addView(pageView.curlView) - pageView.curlView?.setPageProvider(PageProvider()) + pageView.curlView?.mPageProvider = PageProvider() pageView.curlView?.setSizeChangedObserver(SizeChangedObserver()) pageView.curlView?.currentIndex = 0 } @@ -33,6 +33,10 @@ class SimulationPageDelegate(pageView: PageView) : PageDelegate(pageView) { override fun onScrollStop() { } + override fun onPageUp() { + pageView.curlView?.updatePages() + } + private inner class PageProvider : CurlView.PageProvider { override val pageCount: Int