feat: 优化代码

pull/106/head
kunfei 5 years ago
parent a7eefac6a0
commit 1b0488c509
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 14
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  4. 18
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  5. 12
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -16,9 +16,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.Help
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.activity_book_read.*
class MoreConfigDialog : DialogFragment() { class MoreConfigDialog : DialogFragment() {
private val readPreferTag = "readPreferenceFragment" private val readPreferTag = "readPreferenceFragment"
@ -97,12 +95,6 @@ class MoreConfigDialog : DialogFragment() {
PreferKey.hideStatusBar -> postEvent(EventBus.UP_CONFIG, true) PreferKey.hideStatusBar -> postEvent(EventBus.UP_CONFIG, true)
PreferKey.hideNavigationBar -> postEvent(EventBus.UP_CONFIG, true) PreferKey.hideNavigationBar -> postEvent(EventBus.UP_CONFIG, true)
PreferKey.keepLight -> postEvent(PreferKey.keepLight, true) PreferKey.keepLight -> postEvent(PreferKey.keepLight, true)
PreferKey.selectText -> {
val activity = activity
if (activity is ReadBookActivity) {
activity.page_view.upSelectAble()
}
}
} }
} }

@ -99,7 +99,6 @@ class PageView(context: Context, attrs: AttributeSet) :
3 -> ScrollPageDelegate(this) 3 -> ScrollPageDelegate(this)
else -> NoAnimPageDelegate(this) else -> NoAnimPageDelegate(this)
} }
pageDelegate?.upSelectAble()
upContent() upContent()
} }
@ -175,10 +174,6 @@ class PageView(context: Context, attrs: AttributeSet) :
nextPage.upBattery(battery) nextPage.upBattery(battery)
} }
fun upSelectAble() {
pageDelegate?.upSelectAble()
}
override val isScrollDelegate: Boolean override val isScrollDelegate: Boolean
get() = pageDelegate is ScrollPageDelegate get() = pageDelegate is ScrollPageDelegate

@ -1,9 +1,7 @@
package io.legado.app.ui.book.read.page.delegate package io.legado.app.ui.book.read.page.delegate
import android.view.MotionEvent import android.view.MotionEvent
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.getPrefBoolean
import kotlin.math.abs import kotlin.math.abs
abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) { abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) {
@ -15,9 +13,6 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
distanceY: Float distanceY: Float
): Boolean { ): Boolean {
if (!isMoved) { if (!isMoved) {
val event = e1.toAction(MotionEvent.ACTION_UP)
curPage.dispatchTouchEvent(event)
event.recycle()
if (abs(distanceX) > abs(distanceY)) { if (abs(distanceX) > abs(distanceY)) {
if (distanceX < 0) { if (distanceX < 0) {
//如果上一页不存在 //如果上一页不存在
@ -48,13 +43,4 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
return isMoved return isMoved
} }
override fun upSelectAble() {
pageView.curPage.contentTextView()?.apply {
if (context.getPrefBoolean(PreferKey.selectText)) {
// setTextIsSelectable(true)
} else {
// setTextIsSelectable(false)
}
}
}
} }

@ -185,20 +185,8 @@ abstract class PageDelegate(protected val pageView: PageView) {
@CallSuper @CallSuper
open fun onTouch(event: MotionEvent): Boolean { open fun onTouch(event: MotionEvent): Boolean {
if (isStarted) return false if (isStarted) return false
if (curPage.isTextSelected()) { curPage.dispatchTouchEvent(event)
curPage.dispatchTouchEvent(event) if (event.action == MotionEvent.ACTION_UP) {
return true
}
if (event.action == MotionEvent.ACTION_DOWN) {
curPage.let {
it.contentTextView()?.let { contentTextView ->
// atTop = contentTextView.atTop()
// atBottom = contentTextView.atBottom()
}
it.dispatchTouchEvent(event)
}
} else if (event.action == MotionEvent.ACTION_UP) {
curPage.dispatchTouchEvent(event)
if (isMoved) { if (isMoved) {
// 开启翻页效果 // 开启翻页效果
if (!noNext) onScrollStart() if (!noNext) onScrollStart()
@ -208,8 +196,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
return detector.onTouchEvent(event) return detector.onTouchEvent(event)
} }
abstract fun upSelectAble()
abstract fun onScrollStart()//scroller start abstract fun onScrollStart()//scroller start
abstract fun onDraw(canvas: Canvas)//绘制 abstract fun onDraw(canvas: Canvas)//绘制

@ -3,9 +3,7 @@ package io.legado.app.ui.book.read.page.delegate
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Matrix import android.graphics.Matrix
import android.view.MotionEvent import android.view.MotionEvent
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.getPrefBoolean
import kotlin.math.abs import kotlin.math.abs
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
@ -118,14 +116,4 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
return isMoved return isMoved
} }
override fun upSelectAble() {
pageView.curPage.contentTextView()?.apply {
if (context.getPrefBoolean(PreferKey.selectText)) {
// setTextIsSelectable(true)
} else {
// setTextIsSelectable(false)
// movementMethod = ScrollingMovementMethod.getInstance()
}
}
}
} }
Loading…
Cancel
Save