Merge pull request #2382 from 821938089/little-fix

一些优化
pull/2385/head
Horis 2 years ago committed by GitHub
commit d9fff77ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 56
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt

@ -191,6 +191,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
upSystemUiVisibility()
binding.readView.upStatusBar() binding.readView.upStatusBar()
} }

@ -332,7 +332,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
y: Float, y: Float,
select: (textPos: TextPos) -> Unit, select: (textPos: TextPos) -> Unit,
) { ) {
touch(x, y) { _, textPos, _, _, column -> touchRough(x, y) { _, textPos, _, _, column ->
if (column is TextColumn) { if (column is TextColumn) {
column.selected = true column.selected = true
invalidate() invalidate()
@ -345,7 +345,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
* 开始选择符移动 * 开始选择符移动
*/ */
fun selectStartMove(x: Float, y: Float) { fun selectStartMove(x: Float, y: Float) {
touch(x, y) { relativeOffset, textPos, _, textLine, textColumn -> touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn ->
if (selectStart.compare(textPos) != 0) { if (selectStart.compare(textPos) != 0) {
if (textPos.compare(selectEnd) <= 0) { if (textPos.compare(selectEnd) <= 0) {
selectStart.upData(pos = textPos) selectStart.upData(pos = textPos)
@ -364,7 +364,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
* 结束选择符移动 * 结束选择符移动
*/ */
fun selectEndMove(x: Float, y: Float) { fun selectEndMove(x: Float, y: Float) {
touch(x, y) { relativeOffset, textPos, _, textLine, textColumn -> touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn ->
if (textPos.compare(selectEnd) != 0) { if (textPos.compare(selectEnd) != 0) {
if (textPos.compare(selectStart) >= 0) { if (textPos.compare(selectStart) >= 0) {
selectEnd.upData(textPos) selectEnd.upData(textPos)
@ -418,6 +418,56 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
} }
/**
* 触碰位置信息
* 文本选择专用
* @param touched 回调
*/
private fun touchRough(
x: Float,
y: Float,
touched: (
relativeOffset: Float,
textPos: TextPos,
textPage: TextPage,
textLine: TextLine,
column: BaseColumn
) -> Unit
) {
if (!visibleRect.contains(x, y)) return
var relativeOffset: Float
for (relativePos in 0..2) {
relativeOffset = relativeOffset(relativePos)
if (relativePos > 0) {
//滚动翻页
if (!callBack.isScroll) return
if (relativeOffset >= ChapterProvider.visibleHeight) return
}
val textPage = relativePage(relativePos)
for ((lineIndex, textLine) in textPage.lines.withIndex()) {
if (textLine.isTouchY(y, relativeOffset)) {
for ((charIndex, textColumn) in textLine.columns.withIndex()) {
if (textColumn.isTouch(x)) {
touched.invoke(
relativeOffset,
TextPos(relativePos, lineIndex, charIndex),
textPage, textLine, textColumn
)
return
}
}
val (charIndex, textColumn) = textLine.columns.withIndex().last()
touched.invoke(
relativeOffset,
TextPos(relativePos, lineIndex, charIndex),
textPage, textLine, textColumn
)
return
}
}
}
}
/** /**
* 选择开始文字 * 选择开始文字
*/ */

@ -56,4 +56,9 @@ data class TextLine(
&& x >= lineStart && x >= lineStart
&& x <= lineEnd && x <= lineEnd
} }
fun isTouchY(y: Float, relativeOffset: Float): Boolean {
return y > lineTop + relativeOffset
&& y < lineBottom + relativeOffset
}
} }

Loading…
Cancel
Save