Show checkmark on reading indicator if full

pull/181/head
Koitharu 4 years ago
parent d9459dc8fa
commit 1044d7a8d1
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -4,9 +4,11 @@ import android.content.Context
import android.graphics.* import android.graphics.*
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import androidx.annotation.StyleRes import androidx.annotation.StyleRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
import kotlin.math.roundToInt
class ReadingProgressDrawable( class ReadingProgressDrawable(
context: Context, context: Context,
@ -14,6 +16,7 @@ class ReadingProgressDrawable(
) : Drawable() { ) : Drawable() {
private val paint = Paint(Paint.ANTI_ALIAS_FLAG) private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
private val checkDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_check)
private val lineColor: Int private val lineColor: Int
private val outlineColor: Int private val outlineColor: Int
private val backgroundColor: Int private val backgroundColor: Int
@ -53,10 +56,11 @@ class ReadingProgressDrawable(
paint.textAlign = Paint.Align.CENTER paint.textAlign = Paint.Align.CENTER
paint.textSize = ta.getDimension(R.styleable.ProgressDrawable_android_textSize, paint.textSize) paint.textSize = ta.getDimension(R.styleable.ProgressDrawable_android_textSize, paint.textSize)
paint.strokeWidth = ta.getDimension(R.styleable.ProgressDrawable_strokeWidth, 1f) paint.strokeWidth = ta.getDimension(R.styleable.ProgressDrawable_strokeWidth, 1f)
ta.recycle()
hasBackground = Color.alpha(backgroundColor) != 0 hasBackground = Color.alpha(backgroundColor) != 0
hasOutline = Color.alpha(outlineColor) != 0 hasOutline = Color.alpha(outlineColor) != 0
hasText = Color.alpha(textColor) != 0 && paint.textSize > 0 hasText = Color.alpha(textColor) != 0 && paint.textSize > 0
ta.recycle() checkDrawable?.setTint(textColor)
} }
override fun onBoundsChange(bounds: Rect) { override fun onBoundsChange(bounds: Rect) {
@ -99,10 +103,17 @@ class ReadingProgressDrawable(
paint, paint,
) )
if (hasText) { if (hasText) {
paint.style = Paint.Style.FILL if (checkDrawable != null && progress >= 1f - Math.ulp(progress)) {
paint.color = textColor tempRect.set(bounds)
val ty = bounds.height() / 2f + textBounds.height() / 2f - textBounds.bottom tempRect *= 0.6
canvas.drawText(text, cx, ty, paint) checkDrawable.bounds = tempRect
checkDrawable.draw(canvas)
} else {
paint.style = Paint.Style.FILL
paint.color = textColor
val ty = bounds.height() / 2f + textBounds.height() / 2f - textBounds.bottom
canvas.drawText(text, cx, ty, paint)
}
} }
} }
@ -128,4 +139,13 @@ class ReadingProgressDrawable(
paint.getTextBounds(text, 0, text.length, tempRect) paint.getTextBounds(text, 0, text.length, tempRect)
return testTextSize * width / tempRect.width() return testTextSize * width / tempRect.width()
} }
private operator fun Rect.timesAssign(factor: Double) {
val newWidth = (width() * factor).roundToInt()
val newHeight = (height() * factor).roundToInt()
inset(
(width() - newWidth) / 2,
(height() - newHeight) / 2,
)
}
} }
Loading…
Cancel
Save