feat: 优化代码

pull/106/head
kunfei 5 years ago
parent ad30cb55e3
commit cc3b58a867
  1. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 11
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  6. 8
      app/src/main/java/io/legado/app/ui/book/read/page/entities/SelectPoint.kt

@ -35,7 +35,7 @@ import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR
import io.legado.app.ui.book.read.page.ChapterProvider
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.ui.book.read.page.delegate.PageDelegate
import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.SelectPoint
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity
@ -390,9 +390,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
}
override fun selectText(textChar: TextChar) {
cursor_left
cursor_right
override fun selectText(selectPoint: SelectPoint) {
cursor_left.x = selectPoint.startX - cursor_left.width
cursor_left.y = selectPoint.startY
cursor_right.x = selectPoint.endX
cursor_right.y = selectPoint.endY
cursor_left.visible()
cursor_right.visible()
}
override fun showReadAloudDialog() {

@ -11,7 +11,7 @@ import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.SelectPoint
import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefBoolean
@ -82,7 +82,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
fun selectText(x: Float, y: Float): TextChar? {
fun selectText(x: Float, y: Float): SelectPoint? {
textPage?.let { textPage ->
for (textLine in textPage.textLines) {
if (y > textLine.lineTop && y < textLine.lineBottom) {
@ -90,7 +90,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) {
textChar.selected = true
invalidate()
return textChar
return SelectPoint(
textChar.leftBottomPosition.x,
textChar.leftBottomPosition.y.toFloat(),
textChar.rightTopPosition.x,
textChar.leftBottomPosition.y.toFloat()
)
}
}
break

@ -10,7 +10,7 @@ import io.legado.app.R
import io.legado.app.constant.AppConst.TIME_FORMAT
import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.SelectPoint
import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.view_book_page.view.*
@ -111,7 +111,7 @@ class ContentView : FrameLayout {
content_text_view.selectAble = selectAble
}
fun selectText(e: MotionEvent): TextChar? {
fun selectText(e: MotionEvent): SelectPoint? {
val y = e.y - headerHeight
return content_text_view.selectText(e.x, y)
}

@ -10,8 +10,8 @@ import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig
import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.page.delegate.*
import io.legado.app.ui.book.read.page.entities.SelectPoint
import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.utils.activity
import io.legado.app.utils.getPrefInt
@ -256,6 +256,6 @@ class PageView(context: Context, attrs: AttributeSet) :
fun screenOffTimerStart()
fun selectText(textChar: TextChar)
fun selectText(selectPoint: SelectPoint)
}
}

@ -266,6 +266,9 @@ abstract class PageDelegate(protected val pageView: PageView) :
return true
}
/**
* 长按选择
*/
override fun onLongPress(e: MotionEvent) {
val textChar = curPage.selectText(e)
textChar?.let {

@ -0,0 +1,8 @@
package io.legado.app.ui.book.read.page.entities
data class SelectPoint(
var startX: Float,
var startY: Float,
var endX: Float,
var endY: Float
)
Loading…
Cancel
Save