feat: 优化代码

pull/115/head
kunfei 5 years ago
parent 2864bc28ea
commit 3c8def787d
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  4. 9
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -35,7 +35,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
private val maxScrollOffset = 100f private val maxScrollOffset = 100f
private var pageOffset = 0f private var pageOffset = 0f
private var linePos = 0 private var linePos = 0
private var isLastPage = false
init { init {
callBack = activity as CallBack callBack = activity as CallBack
@ -163,7 +162,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun resetPageOffset() { fun resetPageOffset() {
pageOffset = 0f pageOffset = 0f
linePos = 0 linePos = 0
isLastPage = false
} }
fun selectText(x: Float, y: Float): Boolean { fun selectText(x: Float, y: Float): Boolean {

@ -111,6 +111,10 @@ class ContentView(context: Context) : FrameLayout(context) {
content_text_view.onScroll(offset) content_text_view.onScroll(offset)
} }
fun resetPageOffset() {
content_text_view.resetPageOffset()
}
fun upSelectAble(selectAble: Boolean) { fun upSelectAble(selectAble: Boolean) {
content_text_view.selectAble = selectAble content_text_view.selectAble = selectAble
} }

@ -100,6 +100,7 @@ class PageView(context: Context, attrs: AttributeSet) :
fun upContent(position: Int = 0) { fun upContent(position: Int = 0) {
if (ReadBookConfig.isScroll) { if (ReadBookConfig.isScroll) {
curPage.resetPageOffset()
curPage.setContent(pageFactory.currentPage) curPage.setContent(pageFactory.currentPage)
} else { } else {
when (position) { when (position) {

@ -31,11 +31,14 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
} }
} }
override fun onDown(e: MotionEvent): Boolean { override fun onTouch(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN) {
setStartPoint(event.x, event.y)
abort() abort()
mVelocity.clear() mVelocity.clear()
mVelocity.addMovement(e) mVelocity.addMovement(event)
return super.onDown(e) }
return super.onTouch(event)
} }
override fun onScroll( override fun onScroll(

Loading…
Cancel
Save