Skip to content

Commit

Permalink
Fix drawables state
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Jan 5, 2025
1 parent dc2e603 commit 8dea483
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AnimatedFaviconDrawable(

init {
timeAnimator.setTimeListener(this)
updateColor()
onStateChange(state)
}

override fun draw(canvas: Canvas) {
Expand All @@ -44,11 +44,11 @@ class AnimatedFaviconDrawable(
super.draw(canvas)
}

override fun setAlpha(alpha: Int) = Unit

override fun getAlpha(): Int = 255

override fun isOpaque(): Boolean = false
// override fun setAlpha(alpha: Int) = Unit
//
// override fun getAlpha(): Int = 255
//
// override fun isOpaque(): Boolean = false

override fun onTimeUpdate(animation: TimeAnimator?, totalTime: Long, deltaTime: Long) {
callback?.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.graphics.ColorFilter
import android.graphics.PixelFormat
import android.graphics.drawable.Animatable
import android.graphics.drawable.Drawable
import androidx.core.graphics.ColorUtils
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import com.google.android.material.animation.ArgbEvaluatorCompat
import org.koitharu.kotatsu.R
Expand All @@ -23,6 +24,7 @@ class AnimatedPlaceholderDrawable(context: Context) : Drawable(), Animatable, Ti
private val interpolator = FastOutSlowInInterpolator()
private val period = context.getAnimationDuration(R.integer.config_longAnimTime) * 2
private val timeAnimator = TimeAnimator()
private var currentAlpha: Int = 255

init {
timeAnimator.setTimeListener(this)
Expand All @@ -38,14 +40,15 @@ class AnimatedPlaceholderDrawable(context: Context) : Drawable(), Animatable, Ti
}

override fun setAlpha(alpha: Int) {
// this.alpha = alpha FIXME coil's crossfade
currentAlpha = alpha
updateColor()
}

@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated in Java")
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT

override fun getAlpha(): Int = 255
override fun getAlpha(): Int = currentAlpha

override fun setColorFilter(colorFilter: ColorFilter?) = Unit

Expand All @@ -72,7 +75,10 @@ class AnimatedPlaceholderDrawable(context: Context) : Drawable(), Animatable, Ti
}
val ph = period / 2
val fraction = abs((System.currentTimeMillis() % period) - ph) / ph.toFloat()
currentColor = ArgbEvaluatorCompat.getInstance()
.evaluate(interpolator.getInterpolation(fraction), colorLow, colorHigh)
currentColor = ColorUtils.setAlphaComponent(
ArgbEvaluatorCompat.getInstance()
.evaluate(interpolator.getInterpolation(fraction), colorLow, colorHigh),
currentAlpha
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ open class FaviconDrawable(
paint.isFakeBoldText = true
colorForeground = KotatsuColors.random(name)
currentForegroundColor = MaterialColors.harmonize(colorForeground, colorBackground.defaultColor)
onStateChange(state)
}

override fun draw(canvas: Canvas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TextDrawable(
}

init {
onStateChange(state)
measureTextBounds()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DotsIndicator @JvmOverloads constructor(
dotsColor = getColorStateList(R.styleable.DotsIndicator_dotColor)
?: context.getThemeColorStateList(materialR.attr.colorOnBackground)
?: dotsColor
paint.color = dotsColor.defaultColor
paint.color = dotsColor.getColorForState(drawableState, dotsColor.defaultColor)
indicatorSize = getDimension(R.styleable.DotsIndicator_dotSize, indicatorSize)
dotSpacing = getDimension(R.styleable.DotsIndicator_dotSpacing, dotSpacing)
smallDotScale = getFloat(R.styleable.DotsIndicator_dotScale, smallDotScale).coerceIn(0f, 1f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ReadingProgressDrawable(
paint.strokeWidth = ta.getDimension(R.styleable.ProgressDrawable_strokeWidth, 1f)
ta.recycle()
checkDrawable?.setTintList(textColor)
onStateChange(state)
}

override fun onBoundsChange(bounds: Rect) {
Expand Down

0 comments on commit 8dea483

Please sign in to comment.