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 a494f9ca9..014280a7a 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 @@ -17,8 +17,10 @@ import io.legado.app.help.ImageLoader class CoverImageView : androidx.appcompat.widget.AppCompatImageView { internal var width: Float = 0.toFloat() internal var height: Float = 0.toFloat() - - private val textPaint = TextPaint() + private var nameHeight = 0f + private var authorHeight = 0f + private val namePaint = TextPaint() + private val authorPaint = TextPaint() private var name: String? = null private var author: String? = null @@ -33,10 +35,14 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { ) init { - textPaint.typeface = Typeface.DEFAULT_BOLD - textPaint.isAntiAlias = true - textPaint.textAlign = Paint.Align.CENTER - textPaint.textSkewX = -0.2f + namePaint.typeface = Typeface.DEFAULT_BOLD + namePaint.isAntiAlias = true + namePaint.textAlign = Paint.Align.CENTER + namePaint.textSkewX = -0.2f + authorPaint.typeface = Typeface.DEFAULT + authorPaint.isAntiAlias = true + authorPaint.textAlign = Paint.Align.CENTER + authorPaint.textSkewX = -0.1f } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { @@ -52,8 +58,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { super.onLayout(changed, left, top, right, bottom) width = getWidth().toFloat() height = getHeight().toFloat() - textPaint.textSize = width / 6 - textPaint.strokeWidth = textPaint.textSize / 10 + namePaint.textSize = width / 6 + namePaint.strokeWidth = namePaint.textSize / 10 + authorPaint.textSize = width / 9 + authorPaint.strokeWidth = authorPaint.textSize / 10 + nameHeight = height * 3 / 5 + authorHeight = nameHeight + authorPaint.fontSpacing } override fun onDraw(canvas: Canvas) { @@ -75,12 +85,20 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } super.onDraw(canvas) name?.let { - textPaint.color = Color.WHITE - textPaint.style = Paint.Style.STROKE - canvas.drawText(it, width / 2, height * 3 / 5, textPaint) - textPaint.color = Color.BLACK - textPaint.style = Paint.Style.FILL - canvas.drawText(it, width / 2, height * 3 / 5, textPaint) + namePaint.color = Color.WHITE + namePaint.style = Paint.Style.STROKE + canvas.drawText(it, width / 2, nameHeight, namePaint) + namePaint.color = Color.BLACK + namePaint.style = Paint.Style.FILL + canvas.drawText(it, width / 2, nameHeight, namePaint) + } + author?.let { + authorPaint.color = Color.WHITE + authorPaint.style = Paint.Style.STROKE + canvas.drawText(it, width / 2, authorHeight, authorPaint) + authorPaint.color = Color.BLACK + authorPaint.style = Paint.Style.FILL + canvas.drawText(it, width / 2, authorHeight, authorPaint) } } @@ -91,7 +109,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { name.length > 5 -> name.substring(0, 4) + "…" else -> name } - this.author = author + this.author = + when { + author == null -> null + author.length > 8 -> author.substring(0, 7) + "…" + else -> author + } invalidate() }