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

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() {
mHandler.removeCallbacks(autoPageRunnable)
if (page_view.isScroll) {
page_view.curPage.scroll(-page_view.height / ReadBookConfig.autoReadSpeed / 50)
} else {
autoPageProgress++
if (autoPageProgress >= ReadBookConfig.autoReadSpeed * 10) {
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)
}
/**

@ -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
}

@ -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) {

@ -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(

@ -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) {

Loading…
Cancel
Save