添加通用封面规则

pull/1705/head
kunfei 3 years ago
parent 36941ecb3f
commit 1fef8cb9ca
  1. 1
      app/src/main/assets/defaultData/coverRuleConfig.json
  2. 3
      app/src/main/java/io/legado/app/model/BookCover.kt
  3. 3
      app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt
  4. 6
      app/src/main/res/layout/dialog_cover_rule_config.xml

@ -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\")"
}

@ -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,

@ -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()

@ -26,6 +26,12 @@
android:orientation="vertical"
android:padding="16dp">
<io.legado.app.lib.theme.view.ThemeCheckBox
android:id="@+id/cb_enable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/enable" />
<io.legado.app.ui.widget.text.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

Loading…
Cancel
Save