From 9fd1edcd3f716b158c247235e5d66fa1eb565455 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sun, 9 Jan 2022 23:09:50 +0800 Subject: [PATCH] =?UTF-8?q?isVolume=E4=B8=BAtrue=E6=97=B6=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=AA=81=E5=87=BA=E6=98=BE=E7=A4=BA=EF=BC=9BisVolume?= =?UTF-8?q?=E4=B8=BAtrue=E4=B8=94chapterUrl=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E6=A0=87=E9=A2=98=E4=BB=A3=E6=9B=BFchapterUr?= =?UTF-8?q?l,=E4=B8=8D=E8=A7=A3=E6=9E=90=E6=AD=A3=E6=96=87=E8=A7=84?= =?UTF-8?q?=E5=88=99=EF=BC=8C=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E7=A9=BA?= =?UTF-8?q?=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/lib/theme/ThemeUtils.kt | 11 +++++++++++ .../legado/app/model/webBook/BookChapterList.kt | 15 +++++++++++++-- .../java/io/legado/app/model/webBook/WebBook.kt | 2 ++ .../ui/book/read/page/provider/ChapterProvider.kt | 1 + .../legado/app/ui/book/toc/ChapterListAdapter.kt | 15 +++++++++++++-- app/src/main/res/layout/item_chapter_list.xml | 1 + 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeUtils.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeUtils.kt index fe8b3f988..267c5cc67 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeUtils.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeUtils.kt @@ -2,6 +2,7 @@ package io.legado.app.lib.theme import android.content.Context import androidx.annotation.AttrRes +import android.graphics.drawable.Drawable /** * @author Aidan Follestad (afollestad) @@ -31,4 +32,14 @@ object ThemeUtils { a.recycle() } } + + @JvmOverloads + fun resolveDrawable(context: Context, @AttrRes attr: Int): Drawable? { + val a = context.theme.obtainStyledAttributes(intArrayOf(attr)) + return try { + a.getDrawable(0) + } finally { + a.recycle() + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index db8a7c775..2f250ca1e 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -177,6 +177,7 @@ object BookChapterList { val vipRule = analyzeRule.splitSourceRule(tocRule.isVip) val payRule = analyzeRule.splitSourceRule(tocRule.isPay) val upTimeRule = analyzeRule.splitSourceRule(tocRule.updateTime) + val isVolumeRule = analyzeRule.splitSourceRule(tocRule.isVolume) elements.forEachIndexed { index, item -> scope.ensureActive() analyzeRule.setContent(item) @@ -185,9 +186,19 @@ object BookChapterList { bookChapter.title = analyzeRule.getString(nameRule) bookChapter.url = analyzeRule.getString(urlRule) bookChapter.tag = analyzeRule.getString(upTimeRule) + val isVolume = analyzeRule.getString(isVolumeRule) + bookChapter.isVolume = false + if (isVolume.isNotEmpty() && !isVolume.matches(falseRegex)) { + bookChapter.isVolume = true + } if (bookChapter.url.isEmpty()) { - bookChapter.url = baseUrl - Debug.log(bookSource.bookSourceUrl, "目录${index}未获取到url,使用baseUrl替代") + if (bookChapter.isVolume) { + bookChapter.url = bookChapter.title + Debug.log(bookSource.bookSourceUrl, "目录${index}(Volume)未获取到url,使用章节标题替代") + } else { + bookChapter.url = baseUrl + Debug.log(bookSource.bookSourceUrl, "目录${index}未获取到url,使用baseUrl替代") + } } if (bookChapter.title.isNotEmpty()) { val isVip = analyzeRule.getString(vipRule) diff --git a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt index 708e18b52..c95843c7f 100644 --- a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt @@ -261,6 +261,8 @@ object WebBook { Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}") return bookChapter.url } + //章节名为卷名时 且 章节url没获取到,返回空白 + if(bookChapter.isVolume && bookChapter.url == bookChapter.title) return "" return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) { BookContent.analyzeContent( scope = scope, 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 556f26df1..a91771c38 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 @@ -566,6 +566,7 @@ object ChapterProvider { tPaint.typeface = titleFont tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat() tPaint.isAntiAlias = true + //to do:卷名的标题排版 val cPaint = TextPaint() cPaint.color = ReadBookConfig.textColor cPaint.letterSpacing = ReadBookConfig.letterSpacing diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt index b5f2d8549..6ce266dd3 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt @@ -9,10 +9,12 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemChapterListBinding import io.legado.app.lib.theme.accentColor +import io.legado.app.lib.theme.backgroundColor +import io.legado.app.lib.theme.ThemeUtils +import io.legado.app.help.AppConfig import io.legado.app.utils.getCompatColor import io.legado.app.utils.visible - class ChapterListAdapter(context: Context, val callback: Callback) : RecyclerAdapter(context) { @@ -30,6 +32,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : && oldItem.isPay == newItem.isPay && oldItem.title == newItem.title && oldItem.tag == newItem.tag + && oldItem.isVolume == newItem.isVolume } } @@ -54,7 +57,15 @@ class ChapterListAdapter(context: Context, val callback: Callback) : tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } tvChapterName.text = item.getDisplayTitle() - if (!item.tag.isNullOrEmpty()) { + if (item.isVolume) { + //卷名,如第一卷 突出显示 + tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) + } else { + //普通章节 保持不变 + tvChapterItem.setBackground(ThemeUtils.resolveDrawable(context, android.R.attr.selectableItemBackground)) + } + if (!item.tag.isNullOrEmpty() && !item.isVolume) { + //卷名不显示tag(更新时间规则) tvTag.text = item.tag tvTag.visible() } diff --git a/app/src/main/res/layout/item_chapter_list.xml b/app/src/main/res/layout/item_chapter_list.xml index f51671428..1a8abbfc7 100644 --- a/app/src/main/res/layout/item_chapter_list.xml +++ b/app/src/main/res/layout/item_chapter_list.xml @@ -2,6 +2,7 @@