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. 16
      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 chineseConverterType = "chineseConverterType"
const val launcherIcon = "launcherIcon"
const val selectText = "selectText"
const val textSelectAble = "selectText"
const val lastBackup = "lastBackup"
const val bodyIndent = "textIndent"
}

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

@ -16,6 +16,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.read.Help
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.postEvent
class MoreConfigDialog : DialogFragment() {
@ -54,8 +55,7 @@ class MoreConfigDialog : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
var preferenceFragment = childFragmentManager.findFragmentByTag(readPreferTag)
if (preferenceFragment == null) preferenceFragment =
ReadPreferenceFragment()
if (preferenceFragment == null) preferenceFragment = ReadPreferenceFragment()
childFragmentManager.beginTransaction()
.replace(view.id, preferenceFragment, readPreferTag)
.commit()
@ -94,7 +94,8 @@ class MoreConfigDialog : DialogFragment() {
when (key) {
PreferKey.hideStatusBar -> 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() {
curPage.upStyle()
prevPage.upStyle()

@ -59,7 +59,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
private val detector: GestureDetector by lazy {
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()
}
fun upSelectAble(selectAble: Boolean) {
detector.setIsLongpressEnabled(selectAble)
}
protected fun invalidate() {
pageView.invalidate()
}
@ -187,10 +191,6 @@ abstract class PageDelegate(protected val pageView: PageView) :
open fun onScroll() {//移动contentView, slidePage
}
enum class Direction {
NONE, PREV, NEXT
}
@CallSuper
open fun setDirection(direction: Direction) {
mDirection = direction
@ -307,6 +307,10 @@ abstract class PageDelegate(protected val pageView: PageView) :
return hasNext
}
enum class Direction {
NONE, PREV, NEXT
}
fun MotionEvent.toAction(action: Int): MotionEvent {
return MotionEvent.obtain(
downTime,
@ -323,4 +327,4 @@ abstract class PageDelegate(protected val pageView: PageView) :
edgeFlags
)
}
}
}

Loading…
Cancel
Save