添加通用封面规则
This commit is contained in:
@@ -80,7 +80,7 @@ object BookCover {
|
|||||||
)
|
)
|
||||||
val res = analyzeUrl.getStrResponseAwait()
|
val res = analyzeUrl.getStrResponseAwait()
|
||||||
val analyzeRule = AnalyzeRule(book)
|
val analyzeRule = AnalyzeRule(book)
|
||||||
analyzeRule.setContent(res.body, config.searchUrl)
|
analyzeRule.setContent(res.body)
|
||||||
analyzeRule.setRedirectUrl(res.url)
|
analyzeRule.setRedirectUrl(res.url)
|
||||||
return analyzeRule.getString(config.coverRule, isUrl = true)
|
return analyzeRule.getString(config.coverRule, isUrl = true)
|
||||||
}
|
}
|
||||||
@@ -91,6 +91,11 @@ object BookCover {
|
|||||||
CacheManager.put(coverRuleConfigKey, json)
|
CacheManager.put(coverRuleConfigKey, json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun delCoverRuleConfig() {
|
||||||
|
CacheManager.delete(coverRuleConfigKey)
|
||||||
|
coverRuleConfig = DefaultData.coverRuleConfig
|
||||||
|
}
|
||||||
|
|
||||||
data class CoverRuleConfig(
|
data class CoverRuleConfig(
|
||||||
var searchUrl: String,
|
var searchUrl: String,
|
||||||
var coverRule: String,
|
var coverRule: String,
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class CoverConfigFragment : BasePreferenceFragment(),
|
|||||||
@SuppressLint("PrivateResource")
|
@SuppressLint("PrivateResource")
|
||||||
override fun onPreferenceTreeClick(preference: Preference): Boolean {
|
override fun onPreferenceTreeClick(preference: Preference): Boolean {
|
||||||
when (preference.key) {
|
when (preference.key) {
|
||||||
|
"coverRule" -> showDialogFragment(CoverRuleConfigDialog())
|
||||||
PreferKey.defaultCover ->
|
PreferKey.defaultCover ->
|
||||||
if (getPrefString(preference.key).isNullOrEmpty()) {
|
if (getPrefString(preference.key).isNullOrEmpty()) {
|
||||||
selectImage.launch(requestCodeCover)
|
selectImage.launch(requestCodeCover)
|
||||||
|
|||||||
@@ -2,13 +2,47 @@ package io.legado.app.ui.config
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
|
import io.legado.app.databinding.DialogCoverRuleConfigBinding
|
||||||
|
import io.legado.app.model.BookCover
|
||||||
|
import io.legado.app.utils.setLayout
|
||||||
|
import io.legado.app.utils.toastOnUi
|
||||||
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
import splitties.views.onClick
|
||||||
|
|
||||||
class CoverRuleConfigDialog : BaseDialogFragment(R.layout.dialog_cover_rule_config) {
|
class CoverRuleConfigDialog : BaseDialogFragment(R.layout.dialog_cover_rule_config) {
|
||||||
|
|
||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
val binding by viewBinding(DialogCoverRuleConfigBinding::bind)
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
binding.editSearchUrl.setText(BookCover.coverRuleConfig.searchUrl)
|
||||||
|
binding.editCoverUrlRule.setText(BookCover.coverRuleConfig.coverRule)
|
||||||
|
binding.tvCancel.onClick {
|
||||||
|
dismissAllowingStateLoss()
|
||||||
|
}
|
||||||
|
binding.tvOk.onClick {
|
||||||
|
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.saveCoverRuleConfig(config)
|
||||||
|
}
|
||||||
|
dismissAllowingStateLoss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.tvFooterLeft.onClick {
|
||||||
|
BookCover.delCoverRuleConfig()
|
||||||
|
dismissAllowingStateLoss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ class DirectLinkUploadConfig : BaseDialogFragment(R.layout.dialog_direct_link_up
|
|||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
setLayout(0.9f, ViewGroup.LayoutParams.WRAP_CONTENT)
|
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|||||||
@@ -1,6 +1,102 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/tool_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:theme="?attr/actionBarStyle"
|
||||||
|
app:title="@string/cover_config"
|
||||||
|
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||||
|
app:titleTextAppearance="@style/ToolbarTitle" />
|
||||||
|
|
||||||
|
<androidx.core.widget.NestedScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<io.legado.app.ui.widget.text.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="3dp">
|
||||||
|
|
||||||
|
<io.legado.app.lib.theme.view.ThemeEditText
|
||||||
|
android:id="@+id/edit_search_url"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/r_search_url"
|
||||||
|
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||||
|
|
||||||
|
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||||
|
|
||||||
|
<io.legado.app.ui.widget.text.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="3dp">
|
||||||
|
|
||||||
|
<io.legado.app.lib.theme.view.ThemeEditText
|
||||||
|
android:id="@+id/edit_cover_url_rule"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/rule_cover_url"
|
||||||
|
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||||
|
|
||||||
|
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
|
<com.google.android.flexbox.FlexboxLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingRight="12dp"
|
||||||
|
app:flexWrap="wrap"
|
||||||
|
app:justifyContent="space_between">
|
||||||
|
|
||||||
|
<io.legado.app.ui.widget.text.AccentTextView
|
||||||
|
android:id="@+id/tv_footer_left"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:text="@string/btn_default_s"
|
||||||
|
tools:ignore="RtlHardcoded" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<io.legado.app.ui.widget.text.AccentTextView
|
||||||
|
android:id="@+id/tv_cancel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:text="@string/cancel"
|
||||||
|
tools:ignore="RtlHardcoded" />
|
||||||
|
|
||||||
|
<io.legado.app.ui.widget.text.AccentTextView
|
||||||
|
android:id="@+id/tv_ok"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:text="@string/ok"
|
||||||
|
tools:ignore="RtlHardcoded" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.flexbox.FlexboxLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
android:text="@string/delete"
|
android:text="@string/btn_default_s"
|
||||||
tools:ignore="RtlHardcoded" />
|
tools:ignore="RtlHardcoded" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
android:textColor="@color/primaryText"
|
android:textColor="@color/primaryText"
|
||||||
android:textCursorDrawable="@drawable/shape_text_cursor"
|
android:textCursorDrawable="@drawable/shape_text_cursor"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
tools:ignore="TouchTargetSizeCheck" />
|
tools:ignore="TouchTargetSizeCheck,TextContrastCheck" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
android:textColor="@color/primaryText"
|
android:textColor="@color/primaryText"
|
||||||
android:textCursorDrawable="@drawable/shape_text_cursor"
|
android:textCursorDrawable="@drawable/shape_text_cursor"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
tools:ignore="TouchTargetSizeCheck,SpeakableTextPresentCheck" />
|
tools:ignore="TouchTargetSizeCheck,SpeakableTextPresentCheck,TextContrastCheck" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<io.legado.app.ui.widget.prefs.Preference
|
||||||
|
android:key="coverRule"
|
||||||
|
android:title="封面规则"
|
||||||
|
android:summary="进入详情页时使用封面规则重新获取封面"
|
||||||
|
app:allowDividerAbove="false"
|
||||||
|
app:allowDividerBelow="false"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<io.legado.app.ui.widget.prefs.SwitchPreference
|
<io.legado.app.ui.widget.prefs.SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="useDefaultCover"
|
android:key="useDefaultCover"
|
||||||
|
|||||||
Reference in New Issue
Block a user