feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 343f484b13
commit 91612ff127
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 12
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  4. 15
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

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

@ -174,6 +174,10 @@ class PageView(context: Context, attrs: AttributeSet) :
nextPage?.upBattery(battery)
}
fun upSelectAble() {
pageDelegate?.upSelectAble()
}
override val isScrollDelegate: Boolean
get() = pageDelegate is ScrollPageDelegate

@ -1,5 +1,6 @@
package io.legado.app.ui.book.read.page.delegate
import android.text.method.ScrollingMovementMethod
import android.view.MotionEvent
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.PageView
@ -50,8 +51,13 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
}
override fun upSelectAble() {
pageView.curPage
?.contentTextView()
?.isSelected = context.getPrefBoolean(PreferKey.selectText)
pageView.curPage?.contentTextView()?.apply {
if (context.getPrefBoolean(PreferKey.selectText)) {
isSelected = false
} else {
movementMethod = ScrollingMovementMethod.getInstance()
isSelected = true
}
}
}
}

@ -121,13 +121,14 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
}
override fun upSelectAble() {
if (context.getPrefBoolean(PreferKey.selectText)) {
pageView.curPage?.contentTextView()?.isSelected = true
} else {
pageView.curPage?.isSelected = false
pageView.curPage
?.contentTextView()
?.movementMethod = ScrollingMovementMethod.getInstance()
pageView.curPage?.contentTextView()?.apply {
if (context.getPrefBoolean(PreferKey.selectText)) {
isSelected = false
movementMethod = ScrollingMovementMethod.getInstance()
} else {
movementMethod = ScrollingMovementMethod.getInstance()
isSelected = true
}
}
}
}
Loading…
Cancel
Save