diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 07533d34e..8c7576df5 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -70,9 +70,7 @@ object PreferKey { const val transparentStatusBar = "transparentStatusBar" const val immNavigationBar = "immNavigationBar" const val defaultCover = "defaultCover" - const val defaultCoverShowName = "defaultCoverShowName" const val defaultCoverDark = "defaultCoverDark" - const val defaultCoverDarkShowName = "defaultCoverDarkShowName" const val replaceEnableDefault = "replaceEnableDefault" const val showBrightnessView = "showBrightnessView" const val autoClearExpired = "autoClearExpired" diff --git a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt index c50b39133..9e6e36853 100644 --- a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt @@ -12,6 +12,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH import io.legado.app.ui.widget.image.CoverImageView +import io.legado.app.ui.widget.prefs.SwitchPreference import io.legado.app.utils.* class CoverConfigFragment : BasePreferenceFragment(), @@ -57,10 +58,18 @@ class CoverConfigFragment : BasePreferenceFragment(), PreferKey.defaultCoverDark -> { upPreferenceSummary(key, getPrefString(key)) } - PreferKey.coverShowName, + PreferKey.coverShowName -> { + findPreference(PreferKey.coverShowAuthor) + ?.isEnabled = getPrefBoolean(key) + CoverImageView.upDefaultCover() + } + PreferKey.coverShowNameN -> { + findPreference(PreferKey.coverShowAuthorN) + ?.isEnabled = getPrefBoolean(key) + CoverImageView.upDefaultCover() + } PreferKey.coverShowAuthor, - PreferKey.coverShowNameN, - PreferKey.coverShowAuthorN -> listView.post { + PreferKey.coverShowAuthorN -> { CoverImageView.upDefaultCover() } } diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 3fe8a704f..aadc96e8d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -92,12 +92,13 @@ class CoverImageView @JvmOverloads constructor( canvas.clipPath(filletPath) } super.onDraw(canvas) - if (defaultCover && drawBookName && !isInEditMode) { - drawName(canvas) + if (defaultCover && !isInEditMode) { + drawNameAuthor(canvas) } } - private fun drawName(canvas: Canvas) { + private fun drawNameAuthor(canvas: Canvas) { + if (!drawBookName) return var startX = width * 0.2f var startY = height * 0.2f name?.toStringArray()?.let { name -> @@ -116,6 +117,7 @@ class CoverImageView @JvmOverloads constructor( } } } + if (!drawBookAuthor) return author?.toStringArray()?.let { author -> startX = width * 0.8f startY = height * 0.7f @@ -188,6 +190,7 @@ class CoverImageView @JvmOverloads constructor( companion object { private var drawBookName = true + private var drawBookAuthor = true lateinit var defaultDrawable: Drawable init { @@ -197,17 +200,20 @@ class CoverImageView @JvmOverloads constructor( @SuppressLint("UseCompatLoadingForDrawables") fun upDefaultCover() { val isNightTheme = AppConfig.isNightTheme + drawBookName = if (isNightTheme) { + appCtx.getPrefBoolean(PreferKey.coverShowNameN, true) + } else { + appCtx.getPrefBoolean(PreferKey.coverShowName, true) + } + drawBookAuthor = if (isNightTheme) { + appCtx.getPrefBoolean(PreferKey.coverShowAuthorN, true) + } else { + appCtx.getPrefBoolean(PreferKey.coverShowAuthor, true) + } val key = if (isNightTheme) PreferKey.defaultCoverDark else PreferKey.defaultCover val path = appCtx.getPrefString(key) - defaultDrawable = Drawable.createFromPath(path)?.let { - val showNameKey = if (isNightTheme) PreferKey.defaultCoverDarkShowName - else PreferKey.defaultCoverShowName - drawBookName = appCtx.getPrefBoolean(showNameKey) - return@let it - } ?: let { - drawBookName = true - return@let appCtx.resources.getDrawable(R.drawable.image_cover_default, null) - } + defaultDrawable = Drawable.createFromPath(path) + ?: appCtx.resources.getDrawable(R.drawable.image_cover_default, null) } } diff --git a/app/src/main/res/xml/pref_config_cover.xml b/app/src/main/res/xml/pref_config_cover.xml index 4a36fc642..c48c27d8f 100644 --- a/app/src/main/res/xml/pref_config_cover.xml +++ b/app/src/main/res/xml/pref_config_cover.xml @@ -27,7 +27,7 @@ app:iconSpaceReserved="false" />