准备在正文添加按钮
This commit is contained in:
@@ -14,7 +14,7 @@ import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.lib.theme.accentColor
|
||||
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.TextPage
|
||||
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
|
||||
textLine.textChars.forEach {
|
||||
if (it.isImage) {
|
||||
if (it.style == 1) {
|
||||
drawImage(canvas, textPage, textLine, it, lineTop, lineBottom)
|
||||
} else {
|
||||
textPaint.color = textColor
|
||||
@@ -183,7 +183,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
canvas: Canvas,
|
||||
textPage: TextPage,
|
||||
textLine: TextLine,
|
||||
textChar: TextChar,
|
||||
textChar: TextColumn,
|
||||
lineTop: Float,
|
||||
lineBottom: Float
|
||||
) {
|
||||
@@ -284,7 +284,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
select: (textPos: TextPos) -> Unit,
|
||||
) {
|
||||
touch(x, y) { _, textPos, _, _, textChar ->
|
||||
if (textChar.isImage) {
|
||||
if (textChar.style == 1) {
|
||||
callBack.onImageLongPress(x, y, textChar.charData)
|
||||
} else {
|
||||
if (!selectAble) return@touch
|
||||
@@ -367,7 +367,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
textPos: TextPos,
|
||||
textPage: TextPage,
|
||||
textLine: TextLine,
|
||||
textChar: TextChar
|
||||
textColumn: TextColumn
|
||||
) -> Unit
|
||||
) {
|
||||
if (!visibleRect.contains(x, y)) return
|
||||
|
||||
+2
-2
@@ -3,12 +3,12 @@ package io.legado.app.ui.book.read.page.entities
|
||||
/**
|
||||
* 字符信息
|
||||
*/
|
||||
data class TextChar(
|
||||
data class TextColumn(
|
||||
val charData: String,
|
||||
var start: Float,
|
||||
var end: Float,
|
||||
val style: Int = 0, //0:文字,1:图片,2:按钮
|
||||
var selected: Boolean = false,
|
||||
var isImage: Boolean = false,
|
||||
var isSearchResult: Boolean = false
|
||||
) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import io.legado.app.utils.textHeight
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
data class TextLine(
|
||||
var text: String = "",
|
||||
val textChars: ArrayList<TextChar> = arrayListOf(),
|
||||
val textChars: ArrayList<TextColumn> = arrayListOf(),
|
||||
var lineTop: Float = 0f,
|
||||
var lineBase: Float = 0f,
|
||||
var lineBottom: Float = 0f,
|
||||
@@ -30,13 +30,13 @@ data class TextLine(
|
||||
lineBase = lineBottom - textPaint.fontMetrics.descent
|
||||
}
|
||||
|
||||
fun getTextChar(index: Int): TextChar {
|
||||
fun getTextChar(index: Int): TextColumn {
|
||||
return textChars.getOrElse(index) {
|
||||
textChars.last()
|
||||
}
|
||||
}
|
||||
|
||||
fun getTextCharReverseAt(index: Int): TextChar {
|
||||
fun getTextCharReverseAt(index: Int): TextColumn {
|
||||
return textChars[textChars.lastIndex - index]
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ data class TextPage(
|
||||
val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint)
|
||||
val x1 = x + cw
|
||||
textLine.textChars.add(
|
||||
TextChar(char, start = x, end = x1)
|
||||
TextColumn(char, start = x, end = 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.model.ReadBook
|
||||
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.TextPage
|
||||
import io.legado.app.utils.*
|
||||
@@ -252,7 +252,7 @@ object ChapterProvider {
|
||||
Pair(0f, width.toFloat())
|
||||
}
|
||||
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)
|
||||
}
|
||||
@@ -401,7 +401,7 @@ object ChapterProvider {
|
||||
bodyIndent.toStringArray().forEach { char ->
|
||||
val x1 = x + icw
|
||||
textLine.textChars.add(
|
||||
TextChar(charData = char, start = absStartX + x, end = absStartX + x1)
|
||||
TextColumn(charData = char, start = absStartX + x, end = absStartX + x1)
|
||||
)
|
||||
x = x1
|
||||
}
|
||||
@@ -480,16 +480,16 @@ object ChapterProvider {
|
||||
val src = srcList.removeFirst()
|
||||
ImageProvider.cacheImage(book, src, ReadBook.bookSource)
|
||||
textLine.textChars.add(
|
||||
TextChar(
|
||||
TextColumn(
|
||||
charData = src,
|
||||
start = absStartX + xStart,
|
||||
end = absStartX + xEnd,
|
||||
isImage = true
|
||||
style = 1
|
||||
)
|
||||
)
|
||||
} else {
|
||||
textLine.textChars.add(
|
||||
TextChar(
|
||||
TextColumn(
|
||||
charData = char,
|
||||
start = absStartX + xStart,
|
||||
end = absStartX + xEnd
|
||||
|
||||
Reference in New Issue
Block a user