From e7e177fcd4bbd607d50c57d3ba8f83d2d1b3457f Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 11 Nov 2020 19:29:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E7=BF=BB=E9=A1=B5=E6=97=B6,?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=BF=BB=E9=A1=B5=E4=B9=9F=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 16 +++++++++------ .../app/ui/book/read/page/ContentTextView.kt | 20 +++++++++---------- .../app/ui/book/read/page/ContentView.kt | 4 ++-- .../legado/app/ui/book/read/page/PageView.kt | 4 ++-- .../read/page/delegate/ScrollPageDelegate.kt | 2 +- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index ac3521038..792f68154 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -607,14 +607,18 @@ class ReadBookActivity : ReadBookBaseActivity(), private fun autoPagePlus() { mHandler.removeCallbacks(autoPageRunnable) - autoPageProgress++ - if (autoPageProgress >= ReadBookConfig.autoReadSpeed * 10) { - autoPageProgress = 0 - page_view.fillPage(PageDelegate.Direction.NEXT) + if (page_view.isScroll) { + page_view.curPage.scroll(-page_view.height / ReadBookConfig.autoReadSpeed / 50) } else { - page_view.invalidate() + autoPageProgress++ + if (autoPageProgress >= ReadBookConfig.autoReadSpeed * 50) { + autoPageProgress = 0 + page_view.fillPage(PageDelegate.Direction.NEXT) + } else { + page_view.invalidate() + } } - mHandler.postDelayed(autoPageRunnable, 100) + mHandler.postDelayed(autoPageRunnable, 20) } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index c2e80b15c..be7d61348 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -44,7 +44,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory - private var pageOffset = 0f + private var pageOffset = 0 init { callBack = activity as CallBack @@ -173,24 +173,24 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at /** * 滚动事件 */ - fun onScroll(mOffset: Float) { - if (mOffset == 0f) return + fun scroll(mOffset: Int) { + if (mOffset == 0) return pageOffset += mOffset if (!pageFactory.hasPrev() && pageOffset > 0) { - pageOffset = 0f + pageOffset = 0 } else if (!pageFactory.hasNext() && pageOffset < 0 && pageOffset + textPage.height < ChapterProvider.visibleHeight ) { - val offset = ChapterProvider.visibleHeight - textPage.height - pageOffset = min(0f, offset) + val offset = (ChapterProvider.visibleHeight - textPage.height).toInt() + pageOffset = min(0, offset) } else if (pageOffset > 0) { pageFactory.moveToPrev(false) textPage = pageFactory.currentPage - pageOffset -= textPage.height + pageOffset -= textPage.height.toInt() upView?.invoke(textPage) } else if (pageOffset < -textPage.height) { - pageOffset += textPage.height + pageOffset += textPage.height.toInt() pageFactory.moveToNext(false) textPage = pageFactory.currentPage upView?.invoke(textPage) @@ -199,7 +199,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun resetPageOffset() { - pageOffset = 0f + pageOffset = 0 } /** @@ -480,7 +480,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private fun relativeOffset(relativePos: Int): Float { return when (relativePos) { - 0 -> pageOffset + 0 -> pageOffset.toFloat() 1 -> pageOffset + textPage.height else -> pageOffset + textPage.height + pageFactory.nextPage.height } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 2b9d034e8..00e392e18 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -237,8 +237,8 @@ class ContentView(context: Context) : FrameLayout(context) { tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress" } - fun onScroll(offset: Float) { - content_text_view.onScroll(offset) + fun scroll(offset: Int) { + content_text_view.scroll(offset) } fun upSelectAble(selectAble: Boolean) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index c7f1eb4cc..e1fce6de9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -121,10 +121,10 @@ class PageView(context: Context, attrs: AttributeSet) : override fun dispatchDraw(canvas: Canvas) { super.dispatchDraw(canvas) pageDelegate?.onDraw(canvas) - if (callBack.isAutoPage) { + if (callBack.isAutoPage && !isScroll) { nextPage.screenshot()?.let { val bottom = - page_view.height * callBack.autoPageProgress / (ReadBookConfig.autoReadSpeed * 10) + page_view.height * callBack.autoPageProgress / (ReadBookConfig.autoReadSpeed * 50) autoPageRect.set(0, 0, page_view.width, bottom) canvas.drawBitmap(it, autoPageRect, autoPageRect, null) canvas.drawRect( diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 30078de89..90736e081 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -41,7 +41,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } override fun onScroll() { - curPage.onScroll(touchY - lastY) + curPage.scroll((touchY - lastY).toInt()) } override fun onDraw(canvas: Canvas) {