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