|
|
@@ -21,11 +21,20 @@ import io.legado.app.model.ReadBook
|
|
|
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
|
|
|
-import io.legado.app.ui.book.read.page.entities.column.*
|
|
|
+import io.legado.app.ui.book.read.page.entities.column.BaseColumn
|
|
|
+import io.legado.app.ui.book.read.page.entities.column.ButtonColumn
|
|
|
+import io.legado.app.ui.book.read.page.entities.column.ImageColumn
|
|
|
+import io.legado.app.ui.book.read.page.entities.column.ReviewColumn
|
|
|
+import io.legado.app.ui.book.read.page.entities.column.TextColumn
|
|
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
|
|
import io.legado.app.ui.book.read.page.provider.TextPageFactory
|
|
|
import io.legado.app.ui.widget.dialog.PhotoDialog
|
|
|
-import io.legado.app.utils.*
|
|
|
+import io.legado.app.utils.activity
|
|
|
+import io.legado.app.utils.dpToPx
|
|
|
+import io.legado.app.utils.getCompatColor
|
|
|
+import io.legado.app.utils.getPrefBoolean
|
|
|
+import io.legado.app.utils.showDialogFragment
|
|
|
+import io.legado.app.utils.toastOnUi
|
|
|
import kotlin.math.min
|
|
|
|
|
|
/**
|
|
|
@@ -119,23 +128,26 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|
|
*/
|
|
|
private fun drawPage(canvas: Canvas) {
|
|
|
var relativeOffset = relativeOffset(0)
|
|
|
- textPage.lines.forEach { textLine ->
|
|
|
- drawLine(canvas, textPage, textLine, relativeOffset)
|
|
|
+ var lines = textPage.lines
|
|
|
+ for (i in lines.indices) {
|
|
|
+ drawLine(canvas, textPage, lines[i], relativeOffset)
|
|
|
}
|
|
|
if (!callBack.isScroll) return
|
|
|
//滚动翻页
|
|
|
if (!pageFactory.hasNext()) return
|
|
|
val textPage1 = relativePage(1)
|
|
|
relativeOffset = relativeOffset(1)
|
|
|
- textPage1.lines.forEach { textLine ->
|
|
|
- drawLine(canvas, textPage1, textLine, relativeOffset)
|
|
|
+ lines = textPage1.lines
|
|
|
+ for (i in lines.indices) {
|
|
|
+ drawLine(canvas, textPage1, lines[i], relativeOffset)
|
|
|
}
|
|
|
if (!pageFactory.hasNextPlus()) return
|
|
|
relativeOffset = relativeOffset(2)
|
|
|
if (relativeOffset < ChapterProvider.visibleHeight) {
|
|
|
val textPage2 = relativePage(2)
|
|
|
- textPage2.lines.forEach { textLine ->
|
|
|
- drawLine(canvas, textPage2, textLine, relativeOffset)
|
|
|
+ lines = textPage2.lines
|
|
|
+ for (i in lines.indices) {
|
|
|
+ drawLine(canvas, textPage2, lines[i], relativeOffset)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -189,21 +201,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|
|
ChapterProvider.contentPaint
|
|
|
}
|
|
|
val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor
|
|
|
- textLine.columns.forEach {
|
|
|
- when (it) {
|
|
|
+ val columns = textLine.columns
|
|
|
+ for (i in columns.indices) {
|
|
|
+ when (val column = columns[i]) {
|
|
|
is TextColumn -> {
|
|
|
- textPaint.color = textColor
|
|
|
- if (it.isSearchResult) {
|
|
|
+ if (column.isSearchResult) {
|
|
|
textPaint.color = context.accentColor
|
|
|
+ } else if (textPaint.color != textColor) {
|
|
|
+ textPaint.color = textColor
|
|
|
}
|
|
|
- canvas.drawText(it.charData, it.start, lineBase, textPaint)
|
|
|
- if (it.selected) {
|
|
|
- canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint)
|
|
|
+ canvas.drawText(column.charData, column.start, lineBase, textPaint)
|
|
|
+ if (column.selected) {
|
|
|
+ canvas.drawRect(column.start, lineTop, column.end, lineBottom, selectedPaint)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- is ImageColumn -> drawImage(canvas, textPage, textLine, it, lineTop, lineBottom)
|
|
|
- is ReviewColumn -> it.drawToCanvas(canvas, lineBase, textPaint.textSize)
|
|
|
+ is ImageColumn -> drawImage(canvas, textPage, textLine, column, lineTop, lineBottom)
|
|
|
+ is ReviewColumn -> column.drawToCanvas(canvas, lineBase, textPaint.textSize)
|
|
|
}
|
|
|
}
|
|
|
}
|