准备在正文添加按钮

pull/2250/head
kunfei 2 years ago
parent 949cdb3a90
commit 1523f1ca95
  1. 10
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextColumn.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt
  5. 12
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -14,7 +14,7 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextColumn
import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.book.read.page.entities.TextPos import io.legado.app.ui.book.read.page.entities.TextPos
@ -160,7 +160,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor
textLine.textChars.forEach { textLine.textChars.forEach {
if (it.isImage) { if (it.style == 1) {
drawImage(canvas, textPage, textLine, it, lineTop, lineBottom) drawImage(canvas, textPage, textLine, it, lineTop, lineBottom)
} else { } else {
textPaint.color = textColor textPaint.color = textColor
@ -183,7 +183,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
canvas: Canvas, canvas: Canvas,
textPage: TextPage, textPage: TextPage,
textLine: TextLine, textLine: TextLine,
textChar: TextChar, textChar: TextColumn,
lineTop: Float, lineTop: Float,
lineBottom: Float lineBottom: Float
) { ) {
@ -284,7 +284,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
select: (textPos: TextPos) -> Unit, select: (textPos: TextPos) -> Unit,
) { ) {
touch(x, y) { _, textPos, _, _, textChar -> touch(x, y) { _, textPos, _, _, textChar ->
if (textChar.isImage) { if (textChar.style == 1) {
callBack.onImageLongPress(x, y, textChar.charData) callBack.onImageLongPress(x, y, textChar.charData)
} else { } else {
if (!selectAble) return@touch if (!selectAble) return@touch
@ -367,7 +367,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
textPos: TextPos, textPos: TextPos,
textPage: TextPage, textPage: TextPage,
textLine: TextLine, textLine: TextLine,
textChar: TextChar textColumn: TextColumn
) -> Unit ) -> Unit
) { ) {
if (!visibleRect.contains(x, y)) return if (!visibleRect.contains(x, y)) return

@ -3,12 +3,12 @@ package io.legado.app.ui.book.read.page.entities
/** /**
* 字符信息 * 字符信息
*/ */
data class TextChar( data class TextColumn(
val charData: String, val charData: String,
var start: Float, var start: Float,
var end: Float, var end: Float,
val style: Int = 0, //0:文字,1:图片,2:按钮
var selected: Boolean = false, var selected: Boolean = false,
var isImage: Boolean = false,
var isSearchResult: Boolean = false var isSearchResult: Boolean = false
) { ) {

@ -10,7 +10,7 @@ import io.legado.app.utils.textHeight
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
data class TextLine( data class TextLine(
var text: String = "", var text: String = "",
val textChars: ArrayList<TextChar> = arrayListOf(), val textChars: ArrayList<TextColumn> = arrayListOf(),
var lineTop: Float = 0f, var lineTop: Float = 0f,
var lineBase: Float = 0f, var lineBase: Float = 0f,
var lineBottom: Float = 0f, var lineBottom: Float = 0f,
@ -30,13 +30,13 @@ data class TextLine(
lineBase = lineBottom - textPaint.fontMetrics.descent lineBase = lineBottom - textPaint.fontMetrics.descent
} }
fun getTextChar(index: Int): TextChar { fun getTextChar(index: Int): TextColumn {
return textChars.getOrElse(index) { return textChars.getOrElse(index) {
textChars.last() textChars.last()
} }
} }
fun getTextCharReverseAt(index: Int): TextChar { fun getTextCharReverseAt(index: Int): TextColumn {
return textChars[textChars.lastIndex - index] return textChars[textChars.lastIndex - index]
} }

@ -114,7 +114,7 @@ data class TextPage(
val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint) val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint)
val x1 = x + cw val x1 = x + cw
textLine.textChars.add( textLine.textChars.add(
TextChar(char, start = x, end = x1) TextColumn(char, start = x, end = x1)
) )
x = x1 x = x1
} }

@ -14,7 +14,7 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextColumn
import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.utils.* import io.legado.app.utils.*
@ -252,7 +252,7 @@ object ChapterProvider {
Pair(0f, width.toFloat()) Pair(0f, width.toFloat())
} }
textLine.textChars.add( textLine.textChars.add(
TextChar(charData = src, start = x + start, end = x + end, isImage = true) TextColumn(charData = src, start = x + start, end = x + end, style = 1)
) )
textPages.last().textLines.add(textLine) textPages.last().textLines.add(textLine)
} }
@ -401,7 +401,7 @@ object ChapterProvider {
bodyIndent.toStringArray().forEach { char -> bodyIndent.toStringArray().forEach { char ->
val x1 = x + icw val x1 = x + icw
textLine.textChars.add( textLine.textChars.add(
TextChar(charData = char, start = absStartX + x, end = absStartX + x1) TextColumn(charData = char, start = absStartX + x, end = absStartX + x1)
) )
x = x1 x = x1
} }
@ -480,16 +480,16 @@ object ChapterProvider {
val src = srcList.removeFirst() val src = srcList.removeFirst()
ImageProvider.cacheImage(book, src, ReadBook.bookSource) ImageProvider.cacheImage(book, src, ReadBook.bookSource)
textLine.textChars.add( textLine.textChars.add(
TextChar( TextColumn(
charData = src, charData = src,
start = absStartX + xStart, start = absStartX + xStart,
end = absStartX + xEnd, end = absStartX + xEnd,
isImage = true style = 1
) )
) )
} else { } else {
textLine.textChars.add( textLine.textChars.add(
TextChar( TextColumn(
charData = char, charData = char,
start = absStartX + xStart, start = absStartX + xStart,
end = absStartX + xEnd end = absStartX + xEnd

Loading…
Cancel
Save