feat: 优化代码

pull/149/head
kunfei 5 years ago
parent 6a6e07a560
commit ef3049c8d3
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 16
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt

@ -349,7 +349,8 @@ 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_MOVE, MotionEvent.ACTION_UP -> { MotionEvent.ACTION_DOWN -> textActionMenu?.dismiss()
MotionEvent.ACTION_MOVE -> {
when (v.id) { when (v.id) {
R.id.cursor_left -> page_view.curPage.selectStartMove( R.id.cursor_left -> page_view.curPage.selectStartMove(
event.rawX + cursor_left.width, event.rawX + cursor_left.width,
@ -361,6 +362,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
) )
} }
} }
MotionEvent.ACTION_UP -> showTextActionMenu()
} }
return true return true
} }
@ -372,7 +374,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
cursor_left.x = x - cursor_left.width cursor_left.x = x - cursor_left.width
cursor_left.y = y cursor_left.y = y
cursor_left.visible(true) cursor_left.visible(true)
showTextActionMenu()
} }
/** /**
@ -382,7 +383,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
cursor_right.x = x cursor_right.x = x
cursor_right.y = y cursor_right.y = y
cursor_right.visible(true) cursor_right.visible(true)
showTextActionMenu()
} }
/** /**
@ -397,7 +397,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
/** /**
* 显示文本操作菜单 * 显示文本操作菜单
*/ */
private fun showTextActionMenu() { override fun showTextActionMenu() {
textActionMenu ?: let { textActionMenu ?: let {
textActionMenu = TextActionMenu(this, this) textActionMenu = TextActionMenu(this, this)
} }

@ -16,25 +16,20 @@ class PageView(context: Context, attrs: AttributeSet) :
FrameLayout(context, attrs), FrameLayout(context, attrs),
DataSource { DataSource {
var callBack: CallBack val callBack: CallBack get() = activity as CallBack
var pageFactory: TextPageFactory var pageFactory: TextPageFactory = TextPageFactory(this)
var pageDelegate: PageDelegate? = null var pageDelegate: PageDelegate? = null
var prevPage: ContentView var prevPage: ContentView = ContentView(context)
var curPage: ContentView var curPage: ContentView = ContentView(context)
var nextPage: ContentView var nextPage: ContentView = ContentView(context)
init { init {
callBack = activity as CallBack
nextPage = ContentView(context)
addView(nextPage) addView(nextPage)
curPage = ContentView(context)
addView(curPage) addView(curPage)
prevPage = ContentView(context)
addView(prevPage) addView(prevPage)
upBg() upBg()
setWillNotDraw(false) setWillNotDraw(false)
pageFactory = TextPageFactory(this)
upPageAnim() upPageAnim()
} }
@ -170,5 +165,6 @@ class PageView(context: Context, attrs: AttributeSet) :
val isInitFinish: Boolean val isInitFinish: Boolean
fun clickCenter() fun clickCenter()
fun screenOffTimerStart() fun screenOffTimerStart()
fun showTextActionMenu()
} }
} }

@ -200,7 +200,11 @@ abstract class PageDelegate(protected val pageView: PageView) :
//GestureDetector.onFling小幅移动不会触发,所以要自己判断 //GestureDetector.onFling小幅移动不会触发,所以要自己判断
when (event.action) { when (event.action) {
MotionEvent.ACTION_UP, MotionEvent.ACTION_UP,
MotionEvent.ACTION_CANCEL -> if (isMoved) { MotionEvent.ACTION_CANCEL -> {
if (isTextSelected) {
pageView.callBack.showTextActionMenu()
}
if (isMoved) {
if (selectedOnDown) { if (selectedOnDown) {
selectedOnDown = false selectedOnDown = false
} }
@ -209,6 +213,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
} }
} }
} }
}
/** /**
* 按下 * 按下

Loading…
Cancel
Save