优化默认封面

pull/1336/head
gedoor 3 years ago
parent a98140b0c4
commit e5dcaf87d3
  1. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 15
      app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt
  3. 30
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt
  4. 8
      app/src/main/res/xml/pref_config_cover.xml

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

@ -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<SwitchPreference>(PreferKey.coverShowAuthor)
?.isEnabled = getPrefBoolean(key)
CoverImageView.upDefaultCover()
}
PreferKey.coverShowNameN -> {
findPreference<SwitchPreference>(PreferKey.coverShowAuthorN)
?.isEnabled = getPrefBoolean(key)
CoverImageView.upDefaultCover()
}
PreferKey.coverShowAuthor,
PreferKey.coverShowNameN,
PreferKey.coverShowAuthorN -> listView.post {
PreferKey.coverShowAuthorN -> {
CoverImageView.upDefaultCover()
}
}

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

@ -27,7 +27,7 @@
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:defaultValue="true"
android:key="coverShowName"
android:title="@string/cover_show_name"
android:summary="@string/cover_show_name_summary"
@ -36,7 +36,7 @@
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:defaultValue="true"
android:key="coverShowAuthor"
android:title="@string/cover_show_author"
android:summary="@string/cover_show_author_summary"
@ -62,7 +62,7 @@
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:defaultValue="true"
android:key="coverShowNameN"
android:title="@string/cover_show_name"
android:summary="@string/cover_show_name_summary"
@ -71,7 +71,7 @@
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:defaultValue="true"
android:key="coverShowAuthorN"
android:title="@string/cover_show_author"
android:summary="@string/cover_show_author_summary"

Loading…
Cancel
Save