mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
ab0a4b78d7
commit
dae49821ac
@ -6,6 +6,7 @@ package io.legado.app.exception
|
||||
open class NoStackTraceException(msg: String) : Exception(msg) {
|
||||
|
||||
override fun fillInStackTrace(): Throwable {
|
||||
stackTrace = emptyArray()
|
||||
return this
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import io.legado.app.R
|
||||
import splitties.init.appCtx
|
||||
|
||||
@Suppress("ConstPropertyName")
|
||||
object ReadTipConfig {
|
||||
|
||||
const val none = 0
|
||||
|
@ -2,4 +2,11 @@ package io.legado.app.help.coroutine
|
||||
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
|
||||
class ActivelyCancelException : CancellationException()
|
||||
class ActivelyCancelException : CancellationException() {
|
||||
|
||||
override fun fillInStackTrace(): Throwable {
|
||||
stackTrace = emptyArray()
|
||||
return this
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class Coroutine<T>(
|
||||
job.cancel(cause)
|
||||
}
|
||||
cancel?.let {
|
||||
MainScope().launch(executeContext) {
|
||||
DEFAULT.launch(executeContext) {
|
||||
if (null == it.context) {
|
||||
it.block.invoke(scope)
|
||||
} else {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,12 @@ 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.provider.ChapterProvider
|
||||
import io.legado.app.ui.widget.BatteryView
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.activity
|
||||
import io.legado.app.utils.dpToPx
|
||||
import io.legado.app.utils.gone
|
||||
import io.legado.app.utils.statusBarHeight
|
||||
import splitties.views.backgroundColor
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
/**
|
||||
* 页面视图
|
||||
@ -299,12 +302,40 @@ class PageView(context: Context) : FrameLayout(context) {
|
||||
*/
|
||||
@SuppressLint("SetTextI18n")
|
||||
fun setProgress(textPage: TextPage) = textPage.apply {
|
||||
tvBookName?.text = ReadBook.book?.name
|
||||
tvTitle?.text = textPage.title
|
||||
tvPage?.text = "${index.plus(1)}/$pageSize"
|
||||
tvTotalProgress?.text = readProgress
|
||||
tvTotalProgress1?.text = "${textPage.chapterIndex.plus(1)}/${textPage.chapterSize}"
|
||||
tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress"
|
||||
tvBookName?.apply {
|
||||
if (text != ReadBook.book?.name) {
|
||||
text = ReadBook.book?.name
|
||||
}
|
||||
}
|
||||
tvTitle?.apply {
|
||||
if (text != textPage.title) {
|
||||
text = textPage.title
|
||||
}
|
||||
}
|
||||
tvPage?.apply {
|
||||
val page = "${index.plus(1)}/$pageSize"
|
||||
if (text != page) {
|
||||
text = page
|
||||
}
|
||||
}
|
||||
val readProgress = readProgress
|
||||
tvTotalProgress?.apply {
|
||||
if (text != readProgress) {
|
||||
text = readProgress
|
||||
}
|
||||
}
|
||||
tvTotalProgress1?.apply {
|
||||
val progress = "${chapterIndex.plus(1)}/${chapterSize}"
|
||||
if (text != progress) {
|
||||
text = progress
|
||||
}
|
||||
}
|
||||
tvPageAndTotal?.apply {
|
||||
val pageAndTotal = "${index.plus(1)}/$pageSize $readProgress"
|
||||
if (text != pageAndTotal) {
|
||||
text = pageAndTotal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,10 @@ data class TextPage(
|
||||
var leftLineSize: Int = 0
|
||||
) {
|
||||
|
||||
companion object {
|
||||
val readProgressFormatter = DecimalFormat("0.0%")
|
||||
}
|
||||
|
||||
val lines: List<TextLine> get() = textLines
|
||||
val lineSize: Int get() = textLines.size
|
||||
val charSize: Int get() = text.length.coerceAtLeast(1)
|
||||
@ -83,9 +87,9 @@ data class TextPage(
|
||||
val tj = surplus / (leftLineSize - 1)
|
||||
for (i in 1 until leftLineSize) {
|
||||
val line = textLines[i]
|
||||
line.lineTop = line.lineTop + tj * i
|
||||
line.lineBase = line.lineBase + tj * i
|
||||
line.lineBottom = line.lineBottom + tj * i
|
||||
line.lineTop += tj * i
|
||||
line.lineBase += tj * i
|
||||
line.lineBottom += tj * i
|
||||
}
|
||||
}
|
||||
if (leftLineSize == lineSize) return
|
||||
@ -101,9 +105,9 @@ data class TextPage(
|
||||
for (i in leftLineSize + 1 until textLines.size) {
|
||||
val line = textLines[i]
|
||||
val surplusIndex = i - leftLineSize
|
||||
line.lineTop = line.lineTop + tj * surplusIndex
|
||||
line.lineBase = line.lineBase + tj * surplusIndex
|
||||
line.lineBottom = line.lineBottom + tj * surplusIndex
|
||||
line.lineTop += tj * surplusIndex
|
||||
line.lineBase += tj * surplusIndex
|
||||
line.lineBottom += tj * surplusIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -196,7 +200,7 @@ data class TextPage(
|
||||
*/
|
||||
val readProgress: String
|
||||
get() {
|
||||
val df = DecimalFormat("0.0%")
|
||||
val df = readProgressFormatter
|
||||
if (chapterSize == 0 || pageSize == 0 && chapterIndex == 0) {
|
||||
return "0.0%"
|
||||
} else if (pageSize == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user