mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +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) {
|
open class NoStackTraceException(msg: String) : Exception(msg) {
|
||||||
|
|
||||||
override fun fillInStackTrace(): Throwable {
|
override fun fillInStackTrace(): Throwable {
|
||||||
|
stackTrace = emptyArray()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
|
|
||||||
|
@Suppress("ConstPropertyName")
|
||||||
object ReadTipConfig {
|
object ReadTipConfig {
|
||||||
|
|
||||||
const val none = 0
|
const val none = 0
|
||||||
|
@ -2,4 +2,11 @@ package io.legado.app.help.coroutine
|
|||||||
|
|
||||||
import kotlin.coroutines.cancellation.CancellationException
|
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)
|
job.cancel(cause)
|
||||||
}
|
}
|
||||||
cancel?.let {
|
cancel?.let {
|
||||||
MainScope().launch(executeContext) {
|
DEFAULT.launch(executeContext) {
|
||||||
if (null == it.context) {
|
if (null == it.context) {
|
||||||
it.block.invoke(scope)
|
it.block.invoke(scope)
|
||||||
} else {
|
} 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.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
|
||||||
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.ChapterProvider
|
||||||
import io.legado.app.ui.book.read.page.provider.TextPageFactory
|
import io.legado.app.ui.book.read.page.provider.TextPageFactory
|
||||||
import io.legado.app.ui.widget.dialog.PhotoDialog
|
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
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,23 +128,26 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
*/
|
*/
|
||||||
private fun drawPage(canvas: Canvas) {
|
private fun drawPage(canvas: Canvas) {
|
||||||
var relativeOffset = relativeOffset(0)
|
var relativeOffset = relativeOffset(0)
|
||||||
textPage.lines.forEach { textLine ->
|
var lines = textPage.lines
|
||||||
drawLine(canvas, textPage, textLine, relativeOffset)
|
for (i in lines.indices) {
|
||||||
|
drawLine(canvas, textPage, lines[i], relativeOffset)
|
||||||
}
|
}
|
||||||
if (!callBack.isScroll) return
|
if (!callBack.isScroll) return
|
||||||
//滚动翻页
|
//滚动翻页
|
||||||
if (!pageFactory.hasNext()) return
|
if (!pageFactory.hasNext()) return
|
||||||
val textPage1 = relativePage(1)
|
val textPage1 = relativePage(1)
|
||||||
relativeOffset = relativeOffset(1)
|
relativeOffset = relativeOffset(1)
|
||||||
textPage1.lines.forEach { textLine ->
|
lines = textPage1.lines
|
||||||
drawLine(canvas, textPage1, textLine, relativeOffset)
|
for (i in lines.indices) {
|
||||||
|
drawLine(canvas, textPage1, lines[i], relativeOffset)
|
||||||
}
|
}
|
||||||
if (!pageFactory.hasNextPlus()) return
|
if (!pageFactory.hasNextPlus()) return
|
||||||
relativeOffset = relativeOffset(2)
|
relativeOffset = relativeOffset(2)
|
||||||
if (relativeOffset < ChapterProvider.visibleHeight) {
|
if (relativeOffset < ChapterProvider.visibleHeight) {
|
||||||
val textPage2 = relativePage(2)
|
val textPage2 = relativePage(2)
|
||||||
textPage2.lines.forEach { textLine ->
|
lines = textPage2.lines
|
||||||
drawLine(canvas, textPage2, textLine, relativeOffset)
|
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
|
ChapterProvider.contentPaint
|
||||||
}
|
}
|
||||||
val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor
|
val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor
|
||||||
textLine.columns.forEach {
|
val columns = textLine.columns
|
||||||
when (it) {
|
for (i in columns.indices) {
|
||||||
|
when (val column = columns[i]) {
|
||||||
is TextColumn -> {
|
is TextColumn -> {
|
||||||
textPaint.color = textColor
|
if (column.isSearchResult) {
|
||||||
if (it.isSearchResult) {
|
|
||||||
textPaint.color = context.accentColor
|
textPaint.color = context.accentColor
|
||||||
|
} else if (textPaint.color != textColor) {
|
||||||
|
textPaint.color = textColor
|
||||||
}
|
}
|
||||||
canvas.drawText(it.charData, it.start, lineBase, textPaint)
|
canvas.drawText(column.charData, column.start, lineBase, textPaint)
|
||||||
if (it.selected) {
|
if (column.selected) {
|
||||||
canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint)
|
canvas.drawRect(column.start, lineTop, column.end, lineBottom, selectedPaint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is ImageColumn -> drawImage(canvas, textPage, textLine, it, lineTop, lineBottom)
|
is ImageColumn -> drawImage(canvas, textPage, textLine, column, lineTop, lineBottom)
|
||||||
is ReviewColumn -> it.drawToCanvas(canvas, lineBase, textPaint.textSize)
|
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.entities.TextPos
|
||||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||||
import io.legado.app.ui.widget.BatteryView
|
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 splitties.views.backgroundColor
|
||||||
import java.util.*
|
import java.util.Date
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 页面视图
|
* 页面视图
|
||||||
@ -299,12 +302,40 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
*/
|
*/
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun setProgress(textPage: TextPage) = textPage.apply {
|
fun setProgress(textPage: TextPage) = textPage.apply {
|
||||||
tvBookName?.text = ReadBook.book?.name
|
tvBookName?.apply {
|
||||||
tvTitle?.text = textPage.title
|
if (text != ReadBook.book?.name) {
|
||||||
tvPage?.text = "${index.plus(1)}/$pageSize"
|
text = ReadBook.book?.name
|
||||||
tvTotalProgress?.text = readProgress
|
}
|
||||||
tvTotalProgress1?.text = "${textPage.chapterIndex.plus(1)}/${textPage.chapterSize}"
|
}
|
||||||
tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress"
|
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
|
var leftLineSize: Int = 0
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val readProgressFormatter = DecimalFormat("0.0%")
|
||||||
|
}
|
||||||
|
|
||||||
val lines: List<TextLine> get() = textLines
|
val lines: List<TextLine> get() = textLines
|
||||||
val lineSize: Int get() = textLines.size
|
val lineSize: Int get() = textLines.size
|
||||||
val charSize: Int get() = text.length.coerceAtLeast(1)
|
val charSize: Int get() = text.length.coerceAtLeast(1)
|
||||||
@ -83,9 +87,9 @@ data class TextPage(
|
|||||||
val tj = surplus / (leftLineSize - 1)
|
val tj = surplus / (leftLineSize - 1)
|
||||||
for (i in 1 until leftLineSize) {
|
for (i in 1 until leftLineSize) {
|
||||||
val line = textLines[i]
|
val line = textLines[i]
|
||||||
line.lineTop = line.lineTop + tj * i
|
line.lineTop += tj * i
|
||||||
line.lineBase = line.lineBase + tj * i
|
line.lineBase += tj * i
|
||||||
line.lineBottom = line.lineBottom + tj * i
|
line.lineBottom += tj * i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (leftLineSize == lineSize) return
|
if (leftLineSize == lineSize) return
|
||||||
@ -101,9 +105,9 @@ data class TextPage(
|
|||||||
for (i in leftLineSize + 1 until textLines.size) {
|
for (i in leftLineSize + 1 until textLines.size) {
|
||||||
val line = textLines[i]
|
val line = textLines[i]
|
||||||
val surplusIndex = i - leftLineSize
|
val surplusIndex = i - leftLineSize
|
||||||
line.lineTop = line.lineTop + tj * surplusIndex
|
line.lineTop += tj * surplusIndex
|
||||||
line.lineBase = line.lineBase + tj * surplusIndex
|
line.lineBase += tj * surplusIndex
|
||||||
line.lineBottom = line.lineBottom + tj * surplusIndex
|
line.lineBottom += tj * surplusIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +200,7 @@ data class TextPage(
|
|||||||
*/
|
*/
|
||||||
val readProgress: String
|
val readProgress: String
|
||||||
get() {
|
get() {
|
||||||
val df = DecimalFormat("0.0%")
|
val df = readProgressFormatter
|
||||||
if (chapterSize == 0 || pageSize == 0 && chapterIndex == 0) {
|
if (chapterSize == 0 || pageSize == 0 && chapterIndex == 0) {
|
||||||
return "0.0%"
|
return "0.0%"
|
||||||
} else if (pageSize == 0) {
|
} else if (pageSize == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user