From d41d48d072ba75b8bd7080a48aa90a27ffee9ceb Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 21 Sep 2021 21:12:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=85=E8=AF=BB=E7=95=8C=E9=9D=A2=E5=B0=8F?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E4=BD=BF=E7=94=A8=E6=9B=BF=E6=8D=A2=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookChapter.kt | 13 +++++++++++-- .../main/java/io/legado/app/model/ReadBook.kt | 16 +++++++--------- .../book/read/page/provider/ChapterProvider.kt | 9 ++++++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index f9ea25c0f..104b19085 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -5,7 +5,9 @@ import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.Ignore import androidx.room.Index +import com.github.liuyueyi.quick.transfer.ChineseUtils import io.legado.app.R +import io.legado.app.help.AppConfig import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.RuleDataInterface import io.legado.app.utils.* @@ -71,8 +73,9 @@ data class BookChapter( @Suppress("unused") fun getDisplayTitle( - replaceRules: List? = null, - useReplace: Boolean = true + replaceRules: Array? = null, + useReplace: Boolean = true, + chineseConvert: Boolean = true, ): String { var displayTitle = title if (useReplace && replaceRules != null) { @@ -90,6 +93,12 @@ data class BookChapter( } } } + if (chineseConvert) { + when (AppConfig.chineseConverterType) { + 1 -> displayTitle = ChineseUtils.t2s(displayTitle) + 2 -> displayTitle = ChineseUtils.s2t(displayTitle) + } + } return when { !isVip -> displayTitle isPay -> appCtx.getString(R.string.payed_title, displayTitle) diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 3143296d6..219ac30b3 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -1,7 +1,6 @@ package io.legado.app.model import androidx.lifecycle.MutableLiveData -import com.github.liuyueyi.quick.transfer.ChineseUtils import io.legado.app.constant.AppLog import io.legado.app.constant.BookType import io.legado.app.data.appDb @@ -338,15 +337,14 @@ object ReadBook : CoroutineScope by MainScope() { Coroutine.async { removeLoading(chapter.index) if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { - chapter.title = when (AppConfig.chineseConverterType) { - 1 -> ChineseUtils.t2s(chapter.title) - 2 -> ChineseUtils.s2t(chapter.title) - else -> chapter.title - } - val contents = ContentProcessor.get(book.name, book.origin) - .getContent(book, chapter, content) + val contentProcessor = ContentProcessor.get(book.name, book.origin) + val displayTitle = chapter.getDisplayTitle( + contentProcessor.getReplaceRules(), + book.getUseReplaceRule() + ) + val contents = contentProcessor.getContent(book, chapter, content) val textChapter = ChapterProvider - .getTextChapter(book, chapter, contents, chapterSize) + .getTextChapter(book, chapter, displayTitle, contents, chapterSize) when (val offset = chapter.index - durChapterIndex) { 0 -> { curTextChapter = textChapter 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 80daeb7a8..c3ad21735 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 @@ -21,7 +21,9 @@ import io.legado.app.utils.* import splitties.init.appCtx import java.util.* - +/** + * 解析内容生成章节和页面 + */ @Suppress("DEPRECATION") object ChapterProvider { @JvmStatic @@ -81,6 +83,7 @@ object ChapterProvider { fun getTextChapter( book: Book, bookChapter: BookChapter, + displayTitle: String, contents: List, chapterSize: Int, ): TextChapter { @@ -154,12 +157,12 @@ object ChapterProvider { item.pageSize = textPages.size item.chapterIndex = bookChapter.index item.chapterSize = chapterSize - item.title = bookChapter.getDisplayTitle() + item.title = displayTitle item.upLinesPosition() } return TextChapter( - bookChapter.index, bookChapter.getDisplayTitle(), + bookChapter.index, displayTitle, bookChapter.getAbsoluteURL().substringBefore(",{"), //getAbsoluteURL已经格式过 textPages, chapterSize )