feat: 优化代码

pull/106/head
kunfei 5 years ago
parent 4c34c6e7f2
commit 714dcdac23
  1. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  5. 14
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt

@ -33,7 +33,7 @@ object PreferKey {
const val changeSourceLoadToc = "changeSourceLoadToc" const val changeSourceLoadToc = "changeSourceLoadToc"
const val chineseConverterType = "chineseConverterType" const val chineseConverterType = "chineseConverterType"
const val launcherIcon = "launcherIcon" const val launcherIcon = "launcherIcon"
const val selectText = "selectText" const val textSelectAble = "selectText"
const val lastBackup = "lastBackup" const val lastBackup = "lastBackup"
const val bodyIndent = "textIndent" const val bodyIndent = "textIndent"
} }

@ -554,6 +554,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
observeEvent<Boolean>(PreferKey.keepLight) { observeEvent<Boolean>(PreferKey.keepLight) {
upScreenTimeOut() upScreenTimeOut()
} }
observeEvent<Boolean>(PreferKey.textSelectAble) {
page_view.upSelectAble(it)
}
} }
private fun upScreenTimeOut() { private fun upScreenTimeOut() {

@ -16,6 +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.utils.getPrefBoolean
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
class MoreConfigDialog : DialogFragment() { class MoreConfigDialog : DialogFragment() {
@ -54,8 +55,7 @@ class MoreConfigDialog : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
var preferenceFragment = childFragmentManager.findFragmentByTag(readPreferTag) var preferenceFragment = childFragmentManager.findFragmentByTag(readPreferTag)
if (preferenceFragment == null) preferenceFragment = if (preferenceFragment == null) preferenceFragment = ReadPreferenceFragment()
ReadPreferenceFragment()
childFragmentManager.beginTransaction() childFragmentManager.beginTransaction()
.replace(view.id, preferenceFragment, readPreferTag) .replace(view.id, preferenceFragment, readPreferTag)
.commit() .commit()
@ -94,7 +94,8 @@ class MoreConfigDialog : DialogFragment() {
when (key) { when (key) {
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(key, true)
PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key))
} }
} }

@ -151,6 +151,10 @@ class PageView(context: Context, attrs: AttributeSet) :
} }
} }
fun upSelectAble(selectAble: Boolean) {
pageDelegate?.upSelectAble(selectAble)
}
fun upStyle() { fun upStyle() {
curPage.upStyle() curPage.upStyle()
prevPage.upStyle() prevPage.upStyle()

@ -59,7 +59,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
private val detector: GestureDetector by lazy { private val detector: GestureDetector by lazy {
GestureDetector(pageView.context, this).apply { GestureDetector(pageView.context, this).apply {
setIsLongpressEnabled(context.getPrefBoolean(PreferKey.selectText)) setIsLongpressEnabled(context.getPrefBoolean(PreferKey.textSelectAble))
} }
} }
@ -92,6 +92,10 @@ abstract class PageDelegate(protected val pageView: PageView) :
onScroll() onScroll()
} }
fun upSelectAble(selectAble: Boolean) {
detector.setIsLongpressEnabled(selectAble)
}
protected fun invalidate() { protected fun invalidate() {
pageView.invalidate() pageView.invalidate()
} }
@ -187,10 +191,6 @@ abstract class PageDelegate(protected val pageView: PageView) :
open fun onScroll() {//移动contentView, slidePage open fun onScroll() {//移动contentView, slidePage
} }
enum class Direction {
NONE, PREV, NEXT
}
@CallSuper @CallSuper
open fun setDirection(direction: Direction) { open fun setDirection(direction: Direction) {
mDirection = direction mDirection = direction
@ -307,6 +307,10 @@ abstract class PageDelegate(protected val pageView: PageView) :
return hasNext return hasNext
} }
enum class Direction {
NONE, PREV, NEXT
}
fun MotionEvent.toAction(action: Int): MotionEvent { fun MotionEvent.toAction(action: Int): MotionEvent {
return MotionEvent.obtain( return MotionEvent.obtain(
downTime, downTime,

Loading…
Cancel
Save