滚动翻页时,自动翻页也滚动

pull/475/head
gedoor 4 years ago
parent 17be301e27
commit e7e177fcd4
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 20
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -607,14 +607,18 @@ class ReadBookActivity : ReadBookBaseActivity(),
private fun autoPagePlus() { private fun autoPagePlus() {
mHandler.removeCallbacks(autoPageRunnable) mHandler.removeCallbacks(autoPageRunnable)
if (page_view.isScroll) {
page_view.curPage.scroll(-page_view.height / ReadBookConfig.autoReadSpeed / 50)
} else {
autoPageProgress++ autoPageProgress++
if (autoPageProgress >= ReadBookConfig.autoReadSpeed * 10) { if (autoPageProgress >= ReadBookConfig.autoReadSpeed * 50) {
autoPageProgress = 0 autoPageProgress = 0
page_view.fillPage(PageDelegate.Direction.NEXT) page_view.fillPage(PageDelegate.Direction.NEXT)
} else { } else {
page_view.invalidate() page_view.invalidate()
} }
mHandler.postDelayed(autoPageRunnable, 100) }
mHandler.postDelayed(autoPageRunnable, 20)
} }
/** /**

@ -44,7 +44,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
//滚动参数 //滚动参数
private val pageFactory: TextPageFactory get() = callBack.pageFactory private val pageFactory: TextPageFactory get() = callBack.pageFactory
private var pageOffset = 0f private var pageOffset = 0
init { init {
callBack = activity as CallBack callBack = activity as CallBack
@ -173,24 +173,24 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
/** /**
* 滚动事件 * 滚动事件
*/ */
fun onScroll(mOffset: Float) { fun scroll(mOffset: Int) {
if (mOffset == 0f) return if (mOffset == 0) return
pageOffset += mOffset pageOffset += mOffset
if (!pageFactory.hasPrev() && pageOffset > 0) { if (!pageFactory.hasPrev() && pageOffset > 0) {
pageOffset = 0f pageOffset = 0
} else if (!pageFactory.hasNext() } else if (!pageFactory.hasNext()
&& pageOffset < 0 && pageOffset < 0
&& pageOffset + textPage.height < ChapterProvider.visibleHeight && pageOffset + textPage.height < ChapterProvider.visibleHeight
) { ) {
val offset = ChapterProvider.visibleHeight - textPage.height val offset = (ChapterProvider.visibleHeight - textPage.height).toInt()
pageOffset = min(0f, offset) pageOffset = min(0, offset)
} else if (pageOffset > 0) { } else if (pageOffset > 0) {
pageFactory.moveToPrev(false) pageFactory.moveToPrev(false)
textPage = pageFactory.currentPage textPage = pageFactory.currentPage
pageOffset -= textPage.height pageOffset -= textPage.height.toInt()
upView?.invoke(textPage) upView?.invoke(textPage)
} else if (pageOffset < -textPage.height) { } else if (pageOffset < -textPage.height) {
pageOffset += textPage.height pageOffset += textPage.height.toInt()
pageFactory.moveToNext(false) pageFactory.moveToNext(false)
textPage = pageFactory.currentPage textPage = pageFactory.currentPage
upView?.invoke(textPage) upView?.invoke(textPage)
@ -199,7 +199,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
fun resetPageOffset() { 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 { private fun relativeOffset(relativePos: Int): Float {
return when (relativePos) { return when (relativePos) {
0 -> pageOffset 0 -> pageOffset.toFloat()
1 -> pageOffset + textPage.height 1 -> pageOffset + textPage.height
else -> pageOffset + textPage.height + pageFactory.nextPage.height else -> pageOffset + textPage.height + pageFactory.nextPage.height
} }

@ -237,8 +237,8 @@ class ContentView(context: Context) : FrameLayout(context) {
tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress" tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress"
} }
fun onScroll(offset: Float) { fun scroll(offset: Int) {
content_text_view.onScroll(offset) content_text_view.scroll(offset)
} }
fun upSelectAble(selectAble: Boolean) { fun upSelectAble(selectAble: Boolean) {

@ -121,10 +121,10 @@ class PageView(context: Context, attrs: AttributeSet) :
override fun dispatchDraw(canvas: Canvas) { override fun dispatchDraw(canvas: Canvas) {
super.dispatchDraw(canvas) super.dispatchDraw(canvas)
pageDelegate?.onDraw(canvas) pageDelegate?.onDraw(canvas)
if (callBack.isAutoPage) { if (callBack.isAutoPage && !isScroll) {
nextPage.screenshot()?.let { nextPage.screenshot()?.let {
val bottom = 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) autoPageRect.set(0, 0, page_view.width, bottom)
canvas.drawBitmap(it, autoPageRect, autoPageRect, null) canvas.drawBitmap(it, autoPageRect, autoPageRect, null)
canvas.drawRect( canvas.drawRect(

@ -41,7 +41,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
} }
override fun onScroll() { override fun onScroll() {
curPage.onScroll(touchY - lastY) curPage.scroll((touchY - lastY).toInt())
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {

Loading…
Cancel
Save