feat: 优化代码

pull/111/head
kunfei 5 years ago
parent d0dd584893
commit d30235043d
  1. 24
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 11
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@ -317,24 +317,16 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean { override fun onTouch(v: View, event: MotionEvent): Boolean {
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> {
when (v.id) {
R.id.cursor_left -> {
val startX = v.x + 10.dp
val startY = v.y - 10.dp
page_view.setSelectMoveStart(startX, startY)
}
R.id.cursor_right -> {
val startX = v.x - 10.dp
val startY = v.y - 10.dp
page_view.setSelectMoveStart(startX, startY)
}
}
}
MotionEvent.ACTION_MOVE, MotionEvent.ACTION_UP -> { MotionEvent.ACTION_MOVE, MotionEvent.ACTION_UP -> {
when (v.id) { when (v.id) {
R.id.cursor_left -> page_view.selectStartMove(event.x, event.y) R.id.cursor_left -> page_view.selectStartMove(
R.id.cursor_right -> page_view.selectEndMove(event.x, event.y) event.rawX + cursor_left.width,
event.rawY - cursor_left.height
)
R.id.cursor_right -> page_view.selectEndMove(
event.rawX - cursor_right.width,
event.rawY - cursor_right.height
)
} }
} }
} }

@ -18,8 +18,6 @@ import java.util.*
class ContentView(context: Context) : FrameLayout(context) { class ContentView(context: Context) : FrameLayout(context) {
var callBack: CallBack? = null var callBack: CallBack? = null
private var pageSize: Int = 0 private var pageSize: Int = 0
private var textSelectMoveStartX = 0f
private var textSelectMoveStartY = 0f
init { init {
//设置背景防止切换背景时文字重叠 //设置背景防止切换背景时文字重叠
@ -111,17 +109,12 @@ class ContentView(context: Context) : FrameLayout(context) {
return content_text_view.selectText(e.x, y) return content_text_view.selectText(e.x, y)
} }
fun setSelectMoveStart(x: Float, y: Float) {
textSelectMoveStartX = x
textSelectMoveStartY = y - content_text_view.headerHeight
}
fun selectStartMove(x: Float, y: Float) { fun selectStartMove(x: Float, y: Float) {
content_text_view.selectStartMove(textSelectMoveStartX + x, textSelectMoveStartY + y) content_text_view.selectStartMove(x, y - content_text_view.headerHeight)
} }
fun selectEndMove(x: Float, y: Float) { fun selectEndMove(x: Float, y: Float) {
content_text_view.selectEndMove(textSelectMoveStartX + x, textSelectMoveStartY + y) content_text_view.selectEndMove(x, y - content_text_view.headerHeight)
} }
fun cancelSelect() { fun cancelSelect() {

@ -183,10 +183,6 @@ class PageView(context: Context, attrs: AttributeSet) :
nextPage.upBattery(battery) nextPage.upBattery(battery)
} }
fun setSelectMoveStart(x: Float, y: Float) {
curPage.setSelectMoveStart(x, y)
}
fun selectStartMove(x: Float, y: Float) { fun selectStartMove(x: Float, y: Float) {
curPage.selectStartMove(x, y) curPage.selectStartMove(x, y)
} }

Loading…
Cancel
Save