From 1fef8cb9cac820296ce438cef52de8f5af0b7df5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 8 Mar 2022 23:25:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=9A=E7=94=A8=E5=B0=81?= =?UTF-8?q?=E9=9D=A2=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/defaultData/coverRuleConfig.json | 1 + app/src/main/java/io/legado/app/model/BookCover.kt | 3 ++- .../java/io/legado/app/ui/config/CoverRuleConfigDialog.kt | 3 ++- app/src/main/res/layout/dialog_cover_rule_config.xml | 6 ++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/defaultData/coverRuleConfig.json b/app/src/main/assets/defaultData/coverRuleConfig.json index 9f086cd65..63ecb5ad6 100644 --- a/app/src/main/assets/defaultData/coverRuleConfig.json +++ b/app/src/main/assets/defaultData/coverRuleConfig.json @@ -1,4 +1,5 @@ { + "enable": true, "searchUrl": "https://api.yousuu.com/api/search?type=title&value={{key}}&page=1&highlight=0&from=search", "coverRule": "@js:java.getString(\"$..books[?(@.author == '\" + book.author + \"')].cover\")" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/BookCover.kt b/app/src/main/java/io/legado/app/model/BookCover.kt index 2306fad79..5eac81a1a 100644 --- a/app/src/main/java/io/legado/app/model/BookCover.kt +++ b/app/src/main/java/io/legado/app/model/BookCover.kt @@ -68,7 +68,7 @@ object BookCover { suspend fun searchCover(book: Book): String? { val config = coverRuleConfig - if (config.searchUrl.isBlank() || config.coverRule.isBlank()) { + if (!config.enable || config.searchUrl.isBlank() || config.coverRule.isBlank()) { return null } val analyzeUrl = @@ -97,6 +97,7 @@ object BookCover { } data class CoverRuleConfig( + var enable: Boolean = true, var searchUrl: String, var coverRule: String, override var concurrentRate: String? = null, diff --git a/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt b/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt index c92385eaf..ae392358a 100644 --- a/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt @@ -28,12 +28,13 @@ class CoverRuleConfigDialog : BaseDialogFragment(R.layout.dialog_cover_rule_conf dismissAllowingStateLoss() } binding.tvOk.onClick { + val enable = binding.cbEnable.isChecked val searchUrl = binding.editSearchUrl.text?.toString() val coverRule = binding.editCoverUrlRule.text?.toString() if (searchUrl.isNullOrBlank() || coverRule.isNullOrBlank()) { toastOnUi("搜索url和cover规则不能为空") } else { - BookCover.CoverRuleConfig(searchUrl, coverRule).let { config -> + BookCover.CoverRuleConfig(enable, searchUrl, coverRule).let { config -> BookCover.saveCoverRuleConfig(config) } dismissAllowingStateLoss() diff --git a/app/src/main/res/layout/dialog_cover_rule_config.xml b/app/src/main/res/layout/dialog_cover_rule_config.xml index 1538b85b2..9d8082502 100644 --- a/app/src/main/res/layout/dialog_cover_rule_config.xml +++ b/app/src/main/res/layout/dialog_cover_rule_config.xml @@ -26,6 +26,12 @@ android:orientation="vertical" android:padding="16dp"> + +