Horis 2 年之前
父節點
當前提交
dccc5b9b29

+ 1 - 0
app/src/main/java/io/legado/app/exception/NoStackTraceException.kt

@@ -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
     }
     }
 
 

+ 1 - 0
app/src/main/java/io/legado/app/help/config/ReadTipConfig.kt

@@ -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

+ 8 - 1
app/src/main/java/io/legado/app/help/coroutine/ActivelyCancelException.kt

@@ -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
+    }
+
+}

+ 1 - 1
app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt

@@ -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 {

+ 31 - 17
app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@@ -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 ->
-            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 (!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 ->
-            drawLine(canvas, textPage1, textLine, relativeOffset)
+        lines = textPage1.lines
+        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 ->
-                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
             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 {
-            when (it) {
+        val columns = textLine.columns
+        for (i in columns.indices) {
+            when (val column = columns[i]) {
                 is TextColumn -> {
                 is TextColumn -> {
-                    textPaint.color = textColor
-                    if (it.isSearchResult) {
+                    if (column.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)
-                    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)
             }
             }
         }
         }
     }
     }

+ 39 - 8
app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@@ -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
-        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
+            }
+        }
     }
     }
 
 
     /**
     /**

+ 11 - 7
app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt

@@ -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.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
         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.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
     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) {