[修复] 书籍封面作者显示不足
[新增] 书籍封面字体颜色自定义、描边选择开关、阴影颜色自定义与开关
This commit is contained in:
@@ -13,6 +13,13 @@ object PreferKey {
|
||||
const val loadCoverOnlyWifi = "loadCoverOnlyWifi"
|
||||
const val coverShowName = "coverShowName"
|
||||
const val coverShowAuthor = "coverShowAuthor"
|
||||
const val coverShowShadow = "coverShowShadow"
|
||||
const val coverShowStroke = "coverShowStroke"
|
||||
const val coverTextColor = "coverTextColor"
|
||||
const val coverTextColorN = "coverTextColorN"
|
||||
const val coverShadowColor = "coverShadowColor"
|
||||
const val coverShadowColorN = "coverShadowColorN"
|
||||
const val coverDefaultColor = "coverDefaultColor"
|
||||
const val coverShowNameN = "coverShowNameN"
|
||||
const val coverShowAuthorN = "coverShowAuthorN"
|
||||
const val remoteServerId = "remoteServerId"
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.legado.app.model
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.annotation.Keep
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
@@ -35,10 +36,11 @@ import io.legado.app.utils.BitmapUtils
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
import io.legado.app.utils.getPrefBoolean
|
||||
import io.legado.app.utils.getPrefInt
|
||||
import io.legado.app.utils.getPrefString
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
@Keep
|
||||
object BookCover {
|
||||
@@ -48,6 +50,20 @@ object BookCover {
|
||||
private set
|
||||
var drawBookAuthor = true
|
||||
private set
|
||||
var drawBookShadow = true
|
||||
private set
|
||||
var drawBookStroke = true
|
||||
private set
|
||||
var coverTextColor: Int = Color.WHITE
|
||||
private set
|
||||
var coverShadowColor: Int = Color.WHITE
|
||||
private set
|
||||
var coverTextColorN: Int = Color.WHITE
|
||||
private set
|
||||
var coverShadowColorN: Int = Color.WHITE
|
||||
private set
|
||||
var coverDefaultColor = true
|
||||
private set
|
||||
lateinit var defaultDrawable: Drawable
|
||||
private set
|
||||
|
||||
@@ -69,6 +85,21 @@ object BookCover {
|
||||
} else {
|
||||
appCtx.getPrefBoolean(PreferKey.coverShowAuthor, true)
|
||||
}
|
||||
drawBookShadow =
|
||||
appCtx.getPrefBoolean(PreferKey.coverShowShadow, false)
|
||||
drawBookStroke =
|
||||
appCtx.getPrefBoolean(PreferKey.coverShowStroke, true)
|
||||
coverDefaultColor =
|
||||
appCtx.getPrefBoolean(PreferKey.coverDefaultColor, true)
|
||||
coverTextColor =
|
||||
appCtx.getPrefInt(PreferKey.coverTextColor, Color.WHITE)
|
||||
coverTextColorN =
|
||||
appCtx.getPrefInt(PreferKey.coverTextColorN, Color.BLACK)
|
||||
coverShadowColor =
|
||||
appCtx.getPrefInt(PreferKey.coverShadowColor, Color.WHITE)
|
||||
coverShadowColorN =
|
||||
appCtx.getPrefInt(PreferKey.coverShadowColorN, Color.BLACK)
|
||||
|
||||
val key = if (isNightTheme) PreferKey.defaultCoverDark else PreferKey.defaultCover
|
||||
val path = appCtx.getPrefString(key)
|
||||
if (path.isNullOrBlank()) {
|
||||
@@ -222,12 +253,12 @@ object BookCover {
|
||||
config.searchUrl,
|
||||
book.name,
|
||||
source = config,
|
||||
coroutineContext = coroutineContext,
|
||||
coroutineContext = currentCoroutineContext(),
|
||||
hasLoginHeader = false
|
||||
)
|
||||
val res = analyzeUrl.getStrResponseAwait()
|
||||
val analyzeRule = AnalyzeRule(book)
|
||||
analyzeRule.setCoroutineContext(coroutineContext)
|
||||
analyzeRule.setCoroutineContext(currentCoroutineContext())
|
||||
analyzeRule.setContent(res.body)
|
||||
analyzeRule.setRedirectUrl(res.url)
|
||||
return analyzeRule.getString(config.coverRule, isUrl = true)
|
||||
|
||||
@@ -74,6 +74,13 @@ class CoverConfigFragment : PreferenceFragment(),
|
||||
?.isEnabled = getPrefBoolean(key)
|
||||
BookCover.upDefaultCover()
|
||||
}
|
||||
PreferKey.coverTextColor,
|
||||
PreferKey.coverTextColorN,
|
||||
PreferKey.coverShadowColor,
|
||||
PreferKey.coverShadowColorN,
|
||||
PreferKey.coverDefaultColor,
|
||||
PreferKey.coverShowShadow,
|
||||
PreferKey.coverShowStroke,
|
||||
PreferKey.coverShowAuthor,
|
||||
PreferKey.coverShowAuthorN -> {
|
||||
BookCover.upDefaultCover()
|
||||
|
||||
@@ -22,7 +22,6 @@ import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.glide.ImageLoader
|
||||
import io.legado.app.help.glide.OkHttpModelLoader
|
||||
//import io.legado.app.lib.theme.accentColor
|
||||
import io.legado.app.model.BookCover
|
||||
import io.legado.app.utils.spToPx
|
||||
import io.legado.app.utils.textHeight
|
||||
@@ -47,6 +46,9 @@ class CoverImageView @JvmOverloads constructor(
|
||||
private var author: String? = null
|
||||
private var nameHeight = 0f
|
||||
private var authorHeight = 0f
|
||||
private val isNightTheme = AppConfig.isNightTheme
|
||||
val colorKey = if (isNightTheme) BookCover.coverTextColorN else BookCover.coverTextColor
|
||||
val shadowKey = if (isNightTheme) BookCover.coverShadowColorN else BookCover.coverShadowColor
|
||||
private val namePaint by lazy {
|
||||
val textPaint = TextPaint()
|
||||
textPaint.typeface = Typeface.DEFAULT_BOLD
|
||||
@@ -119,21 +121,35 @@ class CoverImageView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun drawNameAuthor(canvas: Canvas) {
|
||||
var startX = width * 0.2f
|
||||
var startY = viewHeight * 0.2f
|
||||
if (BookCover.drawBookName) {
|
||||
var startX = width * 0.2f
|
||||
var startY = viewHeight * 0.2f
|
||||
|
||||
name?.toStringArray()?.let { nameChars ->
|
||||
val textSize = viewWidth / 8
|
||||
namePaint.textSize = textSize
|
||||
namePaint.strokeWidth = textSize / 8
|
||||
|
||||
nameChars.forEach { char ->
|
||||
namePaint.color = Color.WHITE
|
||||
namePaint.style = Paint.Style.STROKE
|
||||
canvas.drawText(char, startX, startY, namePaint)
|
||||
if (BookCover.drawBookShadow) {
|
||||
namePaint.setShadowLayer(
|
||||
4f,
|
||||
0f,
|
||||
0f,
|
||||
shadowKey
|
||||
)
|
||||
} else {
|
||||
namePaint.clearShadowLayer()
|
||||
}
|
||||
|
||||
namePaint.color = context.themeColor(androidx.appcompat.R.attr.colorPrimary)
|
||||
nameChars.forEach { char ->
|
||||
if (BookCover.drawBookStroke) {
|
||||
namePaint.color = Color.WHITE
|
||||
namePaint.style = Paint.Style.STROKE
|
||||
canvas.drawText(char, startX, startY, namePaint)
|
||||
}
|
||||
if (BookCover.coverDefaultColor)
|
||||
namePaint.color = context.themeColor(com.google.android.material.R.attr.colorSecondary)
|
||||
else
|
||||
namePaint.color = colorKey
|
||||
namePaint.style = Paint.Style.FILL
|
||||
canvas.drawText(char, startX, startY, namePaint)
|
||||
|
||||
@@ -144,33 +160,48 @@ class CoverImageView @JvmOverloads constructor(
|
||||
startY = viewHeight * 0.2f
|
||||
}
|
||||
}
|
||||
namePaint.clearShadowLayer()
|
||||
}
|
||||
}
|
||||
|
||||
if (BookCover.drawBookAuthor) {
|
||||
author?.toStringArray()?.let { authorChars ->
|
||||
val textSize = viewWidth / 10
|
||||
authorPaint.textSize = textSize
|
||||
authorPaint.strokeWidth = textSize / 5
|
||||
author?.toStringArray()?.let { author ->
|
||||
authorPaint.textSize = viewWidth / 10
|
||||
authorPaint.strokeWidth = authorPaint.textSize / 5
|
||||
startX = width * 0.8f
|
||||
startY = viewHeight * 0.95f - author.size * authorPaint.textHeight
|
||||
startY = maxOf(startY, viewHeight * 0.2f)
|
||||
if (BookCover.drawBookShadow) {
|
||||
authorPaint.setShadowLayer(
|
||||
4f,
|
||||
0f,
|
||||
0f,
|
||||
shadowKey
|
||||
)
|
||||
} else {
|
||||
authorPaint.clearShadowLayer()
|
||||
}
|
||||
|
||||
var startX = width * 0.8f
|
||||
var startY = viewHeight * 0.8f
|
||||
|
||||
authorChars.forEach { char ->
|
||||
|
||||
authorPaint.color = Color.WHITE
|
||||
authorPaint.style = Paint.Style.STROKE
|
||||
canvas.drawText(char, startX, startY, authorPaint)
|
||||
|
||||
authorPaint.color =
|
||||
context.themeColor(com.google.android.material.R.attr.colorSecondary)
|
||||
author.forEach {
|
||||
if (BookCover.drawBookStroke) {
|
||||
authorPaint.color = Color.WHITE
|
||||
authorPaint.style = Paint.Style.STROKE
|
||||
canvas.drawText(it, startX, startY, authorPaint)
|
||||
}
|
||||
if (BookCover.coverDefaultColor)
|
||||
authorPaint.color = context.themeColor(com.google.android.material.R.attr.colorSecondary)
|
||||
else
|
||||
authorPaint.color = colorKey
|
||||
authorPaint.style = Paint.Style.FILL
|
||||
canvas.drawText(char, startX, startY, authorPaint)
|
||||
canvas.drawText(it, startX, startY, authorPaint)
|
||||
|
||||
startY += authorPaint.textHeight
|
||||
|
||||
if (startY > viewHeight * 0.95f) return@let
|
||||
if (startY > viewHeight * 0.95) {
|
||||
return@let
|
||||
}
|
||||
}
|
||||
authorPaint.clearShadowLayer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user