feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 948e87a3e7
commit 4e5f16dae5
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  5. 13
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -33,4 +33,5 @@ object PreferKey {
const val changeSourceLoadToc = "changeSourceLoadToc"
const val chineseConverterType = "chineseConverterType"
const val launcherIcon = "launcherIcon"
const val selectText = "selectText"
}

@ -98,6 +98,7 @@ class PageView(context: Context, attrs: AttributeSet) :
3 -> ScrollPageDelegate(this)
else -> NoAnimPageDelegate(this)
}
pageDelegate?.upSelectAble()
upContent()
}

@ -1,7 +1,9 @@
package io.legado.app.ui.book.read.page.delegate
import android.view.MotionEvent
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.screenshot
import kotlin.math.abs
@ -46,4 +48,10 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
}
return isMoved
}
override fun upSelectAble() {
pageView.curPage
?.contentTextView()
?.isSelected = context.getPrefBoolean(PreferKey.selectText)
}
}

@ -1,5 +1,6 @@
package io.legado.app.ui.book.read.page.delegate
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.RectF
@ -21,6 +22,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
pageView.width * 0.33f, pageView.height * 0.33f,
pageView.width * 0.66f, pageView.height * 0.66f
)
protected val context: Context = pageView.context
//起始点
protected var startX: Float = 0.toFloat()
protected var startY: Float = 0.toFloat()
@ -205,6 +207,8 @@ abstract class PageDelegate(protected val pageView: PageView) {
return detector.onTouchEvent(event)
}
abstract fun upSelectAble()
abstract fun onScrollStart()//scroller start
abstract fun onDraw(canvas: Canvas)//绘制

@ -2,8 +2,11 @@ package io.legado.app.ui.book.read.page.delegate
import android.graphics.Canvas
import android.graphics.Matrix
import android.text.method.ScrollingMovementMethod
import android.view.MotionEvent
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.screenshot
import kotlin.math.abs
@ -117,4 +120,14 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
return isMoved
}
override fun upSelectAble() {
if (context.getPrefBoolean(PreferKey.selectText)) {
pageView.curPage?.contentTextView()?.isSelected = true
} else {
pageView.curPage?.isSelected = false
pageView.curPage
?.contentTextView()
?.movementMethod = ScrollingMovementMethod.getInstance()
}
}
}
Loading…
Cancel
Save