From 535001acc0cbfef1bd5a4f99004809126f3805ae Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 21 Sep 2021 20:49:29 +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 --- app/src/main/assets/updateLog.md | 2 + .../legado/app/data/entities/BookChapter.kt | 42 ++++++++++++++----- .../read/page/provider/ChapterProvider.kt | 4 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index c32efc3a3..dc61ffa17 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -16,6 +16,8 @@ 1. 阅读界面区域设置添加朗读上一段和朗读下一段 2. 在线朗读采用平均速度计算及时翻页 +3. 修复听书定时问题 +4. 阅读小标题也使用替换 **2021/09/20** 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 ba0380472..f9ea25c0f 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 @@ -8,14 +8,12 @@ import androidx.room.Index import io.legado.app.R import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.RuleDataInterface -import io.legado.app.utils.GSON -import io.legado.app.utils.MD5Utils -import io.legado.app.utils.NetworkUtils -import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.* import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import splitties.init.appCtx +@Suppress("unused") @Parcelize @Entity( tableName = "chapters", @@ -71,11 +69,31 @@ data class BookChapter( return false } - fun getDisplayTitle(): String { + @Suppress("unused") + fun getDisplayTitle( + replaceRules: List? = null, + useReplace: Boolean = true + ): String { + var displayTitle = title + if (useReplace && replaceRules != null) { + replaceRules.forEach { item -> + if (item.pattern.isNotEmpty()) { + try { + displayTitle = if (item.isRegex) { + displayTitle.replace(item.pattern.toRegex(), item.replacement) + } else { + displayTitle.replace(item.pattern, item.replacement) + } + } catch (e: Exception) { + appCtx.toastOnUi("${item.name}替换出错") + } + } + } + } return when { - !isVip -> title - isPay -> appCtx.getString(R.string.payed_title, title) - else -> appCtx.getString(R.string.vip_title, title) + !isVip -> displayTitle + isPay -> appCtx.getString(R.string.payed_title, displayTitle) + else -> appCtx.getString(R.string.vip_title, displayTitle) } } @@ -83,9 +101,11 @@ data class BookChapter( val urlMatcher = AnalyzeUrl.paramPattern.matcher(url) val urlBefore = if (urlMatcher.find()) url.substring(0, urlMatcher.start()) else url val urlAbsoluteBefore = NetworkUtils.getAbsoluteURL(baseUrl, urlBefore) - return if (urlBefore.length == url.length) urlAbsoluteBefore else urlAbsoluteBefore + ',' + url.substring( - urlMatcher.end() - ) + return if (urlBefore.length == url.length) { + urlAbsoluteBefore + } else { + "$urlAbsoluteBefore," + url.substring(urlMatcher.end()) + } } fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title)) 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 aabab2cb7..80daeb7a8 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 @@ -154,12 +154,12 @@ object ChapterProvider { item.pageSize = textPages.size item.chapterIndex = bookChapter.index item.chapterSize = chapterSize - item.title = bookChapter.title + item.title = bookChapter.getDisplayTitle() item.upLinesPosition() } return TextChapter( - bookChapter.index, bookChapter.title, + bookChapter.index, bookChapter.getDisplayTitle(), bookChapter.getAbsoluteURL().substringBefore(",{"), //getAbsoluteURL已经格式过 textPages, chapterSize )