From b21659c23a3c1fb496a1a6027cb9ae0ba21cd0b0 Mon Sep 17 00:00:00 2001 From: Seidko Date: Mon, 5 Sep 2022 22:19:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=E4=BA=86?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=9A=84UI=E8=AE=BE=E8=AE=A1=EF=BC=8C?= =?UTF-8?q?=E6=9A=82=E6=9C=AA=E5=AE=9E=E8=A3=85=E6=8C=89=E9=92=AE=E8=A7=A6?= =?UTF-8?q?=E6=91=B8=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/config/ReadBookConfig.kt | 2 +- .../app/ui/book/read/ReadBookActivity.kt | 3 + .../app/ui/book/read/page/ContentTextView.kt | 80 ++++++++++++++++++- .../ui/book/read/page/entities/TextChar.kt | 3 +- .../ui/book/read/page/entities/TextLine.kt | 1 + .../ui/book/read/page/entities/TextPage.kt | 7 +- .../read/page/provider/ChapterProvider.kt | 37 ++++++--- .../source/edit/BookSourceEditActivity.kt | 2 +- app/src/main/res/menu/book_read.xml | 7 ++ 9 files changed, 127 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt index 605070c0e..4b500e078 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt @@ -449,7 +449,7 @@ object ReadBookConfig { var letterSpacing: Float = 0.1f,//字间距 var lineSpacingExtra: Int = 12,//行间距 var paragraphSpacing: Int = 2,//段距 - var titleMode: Int = 0,//标题居中 + var titleMode: Int = 0,//标题位置 0:居左 1:居中 2:隐藏 var titleSize: Int = 0, var titleTopSpacing: Int = 0, var titleBottomSpacing: Int = 0, diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index c4a97a1ce..930ccf0c2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -355,6 +355,9 @@ class ReadBookActivity : BaseReadBookActivity(), menu?.findItem(R.id.menu_re_segment)?.isChecked = it.getReSegment() ReadBook.loadContent(false) } + R.id.menu_enable_review -> ReadBook.book?.let { + // TODO + } R.id.menu_page_anim -> showPageAnimConfig { binding.readView.upPageAnim() ReadBook.loadContent(false) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 232e90959..71712c180 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -4,6 +4,8 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.graphics.RectF +import android.text.StaticLayout +import android.text.TextPaint import android.util.AttributeSet import android.view.View import io.legado.app.R @@ -150,6 +152,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ChapterProvider.contentPaint } val textColor = if (textLine.isReadAloud) context.accentColor else ReadBookConfig.textColor + val linePaint = Paint() + linePaint.strokeWidth = textPaint.textSize / 21 + linePaint.color = textColor + val reviewCountPaint = TextPaint() + reviewCountPaint.textSize = textPaint.textSize * 0.6F + reviewCountPaint.color = textColor textLine.textChars.forEach { if (it.isImage) { drawImage(canvas, textPage, textLine, it, lineTop, lineBottom) @@ -158,7 +166,74 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (it.isSearchResult) { textPaint.color = context.accentColor } - canvas.drawText(it.charData, it.start, lineBase, textPaint) + if (it.charData == "\uD83D\uDCAC" && it.isLineEnd) { + if (textLine.reviewCount <= 0) return@forEach + canvas.drawLine( + it.start, + lineBase - textPaint.textSize * 2 / 5, + it.start + textPaint.textSize / 6, + lineBase - textPaint.textSize / 4, + linePaint + ) + canvas.drawLine( + it.start, + lineBase - textPaint.textSize * 0.38F, + it.start + textPaint.textSize / 6, + lineBase - textPaint.textSize * 0.55F, + linePaint + ) + canvas.drawLine( + it.start + textPaint.textSize / 6, + lineBase - textPaint.textSize / 4, + it.start + textPaint.textSize / 6, + lineBase, + linePaint + ) + canvas.drawLine( + it.start + textPaint.textSize / 6, + lineBase - textPaint.textSize * 0.55F, + it.start + textPaint.textSize / 6, + lineBase - textPaint.textSize * 0.8F, + linePaint + ) + canvas.drawLine( + it.start + textPaint.textSize / 6, + lineBase, + it.start + textPaint.textSize * 1.6F, + lineBase, + linePaint + ) + canvas.drawLine( + it.start + textPaint.textSize / 6, + lineBase - textPaint.textSize * 0.8F, + it.start + textPaint.textSize * 1.6F, + lineBase - textPaint.textSize * 0.8F, + linePaint + ) + canvas.drawLine( + it.start + textPaint.textSize * 1.6F, + lineBase - textPaint.textSize * 0.8F, + it.start + textPaint.textSize * 1.6F, + lineBase, + linePaint + ) + if (textLine.reviewCount < 100) canvas.drawText( + textLine.reviewCount.toString(), + it.start + textPaint.textSize * 0.87F - + StaticLayout.getDesiredWidth( + textLine.reviewCount.toString(), + reviewCountPaint + ) / 2, + lineBase - textPaint.textSize / 6, + reviewCountPaint + ) + else canvas.drawText( + "99+", + it.start + textPaint.textSize * 0.35F, + lineBase - textPaint.textSize / 6, + reviewCountPaint + ) + } else canvas.drawText(it.charData, it.start, lineBase, textPaint) } if (it.selected) { canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) @@ -276,6 +351,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at callBack.onImageLongPress(x, y, textChar.charData) } else { if (!selectAble) return@touch + if (textChar.charData == "\uD83D\uDCAC" && textChar.isLineEnd) return@touch textChar.selected = true invalidate() select(relativePos, lineIndex, charIndex) @@ -292,6 +368,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit, ) { touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar -> + if (textChar.charData == "\uD83D\uDCAC" && textChar.isLineEnd) return@touch textChar.selected = true invalidate() select(relativePos, lineIndex, charIndex) @@ -415,6 +492,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textPos.lineIndex = lineIndex for ((charIndex, textChar) in textLine.textChars.withIndex()) { textPos.charIndex = charIndex + if (textChar.charData == "\uD83D\uDCAC" && textChar.isLineEnd) continue textChar.selected = textPos.compare(selectStart) >= 0 && textPos.compare(selectEnd) <= 0 textChar.isSearchResult = textChar.selected && callBack.isSelectingSearchResult diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt index 518067182..77442194f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt @@ -6,7 +6,8 @@ data class TextChar( var end: Float, var selected: Boolean = false, var isImage: Boolean = false, - var isSearchResult: Boolean = false + var isSearchResult: Boolean = false, + var isLineEnd: Boolean = false ) { fun isTouch(x: Float): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 3ec66b3ca..56225b2ee 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -8,6 +8,7 @@ import io.legado.app.utils.textHeight data class TextLine( var text: String = "", val textChars: ArrayList = arrayListOf(), + val reviewCount: Int = 0, var lineTop: Float = 0f, var lineBase: Float = 0f, var lineBottom: Float = 0f, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 3997b1ead..94cf56748 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -111,7 +111,12 @@ data class TextPage( val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint) val x1 = x + cw textLine.textChars.add( - TextChar(char, start = x, end = x1) + TextChar( + char, + start = x, + end = x1, + isLineEnd = textLine.text.length - 1 == i + ) ) x = x1 } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 5ae48f727..f86ee6e66 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -116,7 +116,13 @@ object ChapterProvider { if (ReadBookConfig.titleMode != 2) { displayTitle.splitNotBlank("\n").forEach { text -> setTypeText( - book, absStartX, durY, text, textPages, stringBuilder, titlePaint, + book, + absStartX, + durY, + text + "\ud83d\udcac", + textPages, + stringBuilder, + titlePaint, isTitle = true, isTitleWithNoContent = contents.isEmpty(), isVolumeTitle = bookChapter.isVolume @@ -171,7 +177,13 @@ object ChapterProvider { val text = content.substring(start, content.length) if (text.isNotBlank()) { setTypeText( - book, absStartX, durY, text, textPages, stringBuilder, contentPaint + book, + absStartX, + durY, + text + "\ud83d\udcac", + textPages, + stringBuilder, + contentPaint ).let { absStartX = it.first durY = it.second @@ -276,9 +288,8 @@ object ChapterProvider { srcList: LinkedList? = null ): Pair { var absStartX = x - val layout = if (ReadBookConfig.useZhLayout) { - ZhLayout(text, textPaint, visibleWidth) - } else StaticLayout( + val layout = if (ReadBookConfig.useZhLayout) ZhLayout(text, textPaint, visibleWidth) + else StaticLayout( text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true ) var durY = when { @@ -398,10 +409,15 @@ object ChapterProvider { } val bodyIndent = ReadBookConfig.paragraphIndent val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length - bodyIndent.toStringArray().forEach { char -> + for ((index, char) in bodyIndent.toStringArray().withIndex()) { val x1 = x + icw textLine.textChars.add( - TextChar(charData = char, start = absStartX + x, end = absStartX + x1) + TextChar( + charData = char, + start = absStartX + x, + end = absStartX + x1, + isLineEnd = bodyIndent.length - 1 == index + ) ) x = x1 } @@ -492,7 +508,8 @@ object ChapterProvider { TextChar( charData = char, start = absStartX + xStart, - end = absStartX + xEnd + end = absStartX + xEnd, + isLineEnd = true ) ) } @@ -612,12 +629,12 @@ object ChapterProvider { * 更新绘制尺寸 */ fun upLayout() { - when(AppConfig.doublePageHorizontal){ + when (AppConfig.doublePageHorizontal) { "0" -> doublePage = false "1" -> doublePage = true "2" -> { doublePage = (viewWidth > viewHeight) - && ReadBook.pageAnim() != 3 + && ReadBook.pageAnim() != 3 } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index d733ca71e..b1e799e51 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -299,7 +299,7 @@ class BookSourceEditActivity : reviewEntities.clear() reviewEntities.apply { add(EditEntity("reviewUrl", rr?.reviewUrl, R.string.rule_review_url)) - add(EditEntity("avatarRule", rr?.reviewUrl, R.string.rule_avatar)) + add(EditEntity("avatarRule", rr?.avatarRule, R.string.rule_avatar)) add(EditEntity("contentRule", rr?.contentRule, R.string.rule_review_content)) add(EditEntity("postTimeRule", rr?.postTimeRule, R.string.rule_post_time)) add(EditEntity("reviewQuoteUrl", rr?.reviewQuoteUrl, R.string.rule_review_quote)) diff --git a/app/src/main/res/menu/book_read.xml b/app/src/main/res/menu/book_read.xml index 3f2b0b563..32915270e 100644 --- a/app/src/main/res/menu/book_read.xml +++ b/app/src/main/res/menu/book_read.xml @@ -84,6 +84,13 @@ android:checked="false" app:showAsAction="never" /> + +