Use user color for pin background
This commit is contained in:
parent
8f362d83cd
commit
7cad30e6bb
|
@ -19,7 +19,9 @@ package im.vector.app.features.home.room.detail.timeline.helper
|
|||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import com.bumptech.glide.request.target.CustomTarget
|
||||
import com.bumptech.glide.request.transition.Transition
|
||||
import im.vector.app.R
|
||||
|
@ -37,7 +39,8 @@ class LocationPinProvider @Inject constructor(
|
|||
private val context: Context,
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val dimensionConverter: DimensionConverter,
|
||||
private val avatarRenderer: AvatarRenderer
|
||||
private val avatarRenderer: AvatarRenderer,
|
||||
private val matrixItemColorProvider: MatrixItemColorProvider
|
||||
) {
|
||||
private val cache = mutableMapOf<String, Drawable>()
|
||||
|
||||
|
@ -61,12 +64,17 @@ class LocationPinProvider @Inject constructor(
|
|||
return
|
||||
}
|
||||
|
||||
activeSessionHolder.getActiveSession().getUser(userId)?.toMatrixItem()?.let {
|
||||
activeSessionHolder
|
||||
.getActiveSession()
|
||||
.getUser(userId)
|
||||
?.toMatrixItem()
|
||||
?.let { userItem ->
|
||||
val size = dimensionConverter.dpToPx(44)
|
||||
avatarRenderer.render(glideRequests, it, object : CustomTarget<Drawable>(size, size) {
|
||||
val bgTintColor = matrixItemColorProvider.getColor(userItem)
|
||||
avatarRenderer.render(glideRequests, userItem, object : CustomTarget<Drawable>(size, size) {
|
||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
||||
Timber.d("## Location: onResourceReady")
|
||||
val pinDrawable = createPinDrawable(resource)
|
||||
val pinDrawable = createPinDrawable(resource, bgTintColor)
|
||||
cache[userId] = pinDrawable
|
||||
callback(pinDrawable)
|
||||
}
|
||||
|
@ -80,7 +88,7 @@ class LocationPinProvider @Inject constructor(
|
|||
override fun onLoadFailed(errorDrawable: Drawable?) {
|
||||
Timber.w("## Location: onLoadFailed")
|
||||
errorDrawable ?: return
|
||||
val pinDrawable = createPinDrawable(errorDrawable)
|
||||
val pinDrawable = createPinDrawable(errorDrawable, bgTintColor)
|
||||
cache[userId] = pinDrawable
|
||||
callback(pinDrawable)
|
||||
}
|
||||
|
@ -88,8 +96,10 @@ class LocationPinProvider @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createPinDrawable(drawable: Drawable): Drawable {
|
||||
private fun createPinDrawable(drawable: Drawable, @ColorInt bgTintColor: Int): Drawable {
|
||||
val bgUserPin = ContextCompat.getDrawable(context, R.drawable.bg_map_user_pin)!!
|
||||
// use mutate on drawable to avoid sharing the color when we have multiple different user pins
|
||||
DrawableCompat.setTint(bgUserPin.mutate(), bgTintColor)
|
||||
val layerDrawable = LayerDrawable(arrayOf(bgUserPin, drawable))
|
||||
val horizontalInset = dimensionConverter.dpToPx(4)
|
||||
val topInset = dimensionConverter.dpToPx(4)
|
||||
|
|
Loading…
Reference in New Issue