feat: 修复vip标识引起的bug

pull/274/head
gedoor 4 years ago
parent cc97b48a69
commit 6c606deb9a
  1. 4
      app/src/main/java/io/legado/app/service/DownloadService.kt
  2. 38
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt

@ -150,7 +150,7 @@ class DownloadService : BaseService() {
} }
private fun download() { private fun download() {
++downloadingCount downloadingCount += 1
tasks.add(Coroutine.async(this, context = searchPool) { tasks.add(Coroutine.async(this, context = searchPool) {
if (!isActive) return@async if (!isActive) return@async
val bookChapter: BookChapter? = synchronized(this@DownloadService) { val bookChapter: BookChapter? = synchronized(this@DownloadService) {
@ -223,7 +223,7 @@ class DownloadService : BaseService() {
} }
private fun postDownloading(hasChapter: Boolean) { private fun postDownloading(hasChapter: Boolean) {
--downloadingCount downloadingCount -= 1
if (hasChapter) { if (hasChapter) {
download() download()
} else { } else {

@ -112,22 +112,24 @@ object ChapterProvider {
val textLine = TextLine(isTitle = isTitle) val textLine = TextLine(isTitle = isTitle)
val words = val words =
text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex))
textLine.text = words
val desiredWidth = layout.getLineWidth(lineIndex) val desiredWidth = layout.getLineWidth(lineIndex)
var isLastLine = false var isLastLine = false
if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) {
//第一行 //第一行
addCharsToLineFirst(textLine, words, textPaint, desiredWidth) textLine.text = words
addCharsToLineFirst(textLine, words.toStringArray(), textPaint, desiredWidth)
} else if (lineIndex == layout.lineCount - 1) { } else if (lineIndex == layout.lineCount - 1) {
//最后一行 //最后一行
textLine.text = "$words\n"
isLastLine = true isLastLine = true
val x = if (isTitle && ReadBookConfig.titleMode == 1) val x = if (isTitle && ReadBookConfig.titleMode == 1)
(visibleWidth - layout.getLineWidth(lineIndex)) / 2 (visibleWidth - layout.getLineWidth(lineIndex)) / 2
else 0f else 0f
addCharsToLineLast(textLine, words, textPaint, x, true) addCharsToLineLast(textLine, words.toStringArray(), textPaint, x)
} else { } else {
//中间行 //中间行
addCharsToLineMiddle(textLine, words, textPaint, desiredWidth, 0f) textLine.text = words
addCharsToLineMiddle(textLine, words.toStringArray(), textPaint, desiredWidth, 0f)
} }
if (durY + textPaint.textHeight > visibleHeight) { if (durY + textPaint.textHeight > visibleHeight) {
//当前页面结束,设置各种值 //当前页面结束,设置各种值
@ -157,13 +159,13 @@ object ChapterProvider {
*/ */
private fun addCharsToLineFirst( private fun addCharsToLineFirst(
textLine: TextLine, textLine: TextLine,
words: String, words: Array<String>,
textPaint: TextPaint, textPaint: TextPaint,
desiredWidth: Float desiredWidth: Float
) { ) {
var x = 0f var x = 0f
if (!ReadBookConfig.textFullJustify) { if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, x, false) addCharsToLineLast(textLine, words, textPaint, x)
return return
} }
val bodyIndent = ReadBookConfig.bodyIndent val bodyIndent = ReadBookConfig.bodyIndent
@ -177,7 +179,7 @@ object ChapterProvider {
) )
x = x1 x = x1
} }
val words1 = words.replaceFirst(bodyIndent, "") val words1 = words.copyOfRange(bodyIndent.length, words.size)
addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x) addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x)
} }
@ -186,19 +188,19 @@ object ChapterProvider {
*/ */
private fun addCharsToLineMiddle( private fun addCharsToLineMiddle(
textLine: TextLine, textLine: TextLine,
words: String, words: Array<String>,
textPaint: TextPaint, textPaint: TextPaint,
desiredWidth: Float, desiredWidth: Float,
startX: Float startX: Float
) { ) {
if (!ReadBookConfig.textFullJustify) { if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, startX, false) addCharsToLineLast(textLine, words, textPaint, startX)
return return
} }
val gapCount: Int = words.length - 1 val gapCount: Int = words.lastIndex
val d = (visibleWidth - desiredWidth) / gapCount val d = (visibleWidth - desiredWidth) / gapCount
var x = startX var x = startX
words.toStringArray().forEachIndexed { index, s -> words.forEachIndexed { index, s ->
val cw = StaticLayout.getDesiredWidth(s, textPaint) val cw = StaticLayout.getDesiredWidth(s, textPaint)
val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw)
textLine.addTextChar( textLine.addTextChar(
@ -216,14 +218,12 @@ object ChapterProvider {
*/ */
private fun addCharsToLineLast( private fun addCharsToLineLast(
textLine: TextLine, textLine: TextLine,
words: String, words: Array<String>,
textPaint: TextPaint, textPaint: TextPaint,
startX: Float, startX: Float
isLast: Boolean
) { ) {
textLine.text = if (isLast) "$words\n" else words
var x = startX var x = startX
words.toStringArray().forEach { words.forEach {
val cw = StaticLayout.getDesiredWidth(it, textPaint) val cw = StaticLayout.getDesiredWidth(it, textPaint)
val x1 = x + cw val x1 = x + cw
textLine.addTextChar( textLine.addTextChar(
@ -239,13 +239,13 @@ object ChapterProvider {
/** /**
* 超出边界处理 * 超出边界处理
*/ */
private fun exceed(textLine: TextLine, words: String) { private fun exceed(textLine: TextLine, words: Array<String>) {
val endX = textLine.textChars.last().end val endX = textLine.textChars.last().end
if (endX > visibleRight) { if (endX > visibleRight) {
val cc = (endX - visibleRight) / words.length val cc = (endX - visibleRight) / words.size
for (i in 0..words.lastIndex) { for (i in 0..words.lastIndex) {
textLine.getTextCharReverseAt(i).let { textLine.getTextCharReverseAt(i).let {
val py = cc * (words.length - i) val py = cc * (words.size - i)
it.start = it.start - py it.start = it.start - py
it.end = it.end - py it.end = it.end - py
} }

Loading…
Cancel
Save