mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 18:05:59 +03:00
avoiding nullable param and supplying a range for the tint alpha
This commit is contained in:
parent
3866cfeabc
commit
f8e65f5872
1 changed files with 4 additions and 3 deletions
|
@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable
|
|||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.core.content.ContextCompat
|
||||
import dagger.hilt.EntryPoints
|
||||
import im.vector.app.core.di.SingletonEntryPoint
|
||||
|
@ -30,15 +31,15 @@ fun Context.singletonEntryPoint(): SingletonEntryPoint {
|
|||
return EntryPoints.get(applicationContext, SingletonEntryPoint::class.java)
|
||||
}
|
||||
|
||||
fun Context.getResTintedDrawable(@DrawableRes drawableRes: Int, @ColorRes tint: Int, alpha: Float? = null): Drawable? {
|
||||
fun Context.getResTintedDrawable(@DrawableRes drawableRes: Int, @ColorRes tint: Int, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1f): Drawable? {
|
||||
return getTintedDrawable(drawableRes, ContextCompat.getColor(this, tint), alpha)
|
||||
}
|
||||
|
||||
fun Context.getTintedDrawable(@DrawableRes drawableRes: Int, @ColorInt tint: Int, alpha: Float? = null) = ContextCompat.getDrawable(this, drawableRes)
|
||||
fun Context.getTintedDrawable(@DrawableRes drawableRes: Int, @ColorInt tint: Int, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1f) = ContextCompat.getDrawable(this, drawableRes)
|
||||
?.mutate()
|
||||
?.also { drawable ->
|
||||
drawable.setTint(tint)
|
||||
alpha?.let {
|
||||
alpha.let {
|
||||
drawable.alpha = it.toAndroidAlpha()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue