Make caching of mxid-based colors theme-friendly
Change-Id: I09b811c2cf1131914ab025c4a4fb5d4da74e3d88
This commit is contained in:
parent
8005f44768
commit
d4a3e3828c
|
@ -33,6 +33,7 @@ class MatrixItemColorProvider @Inject constructor(
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val colorProvider: ColorProvider
|
private val colorProvider: ColorProvider
|
||||||
) {
|
) {
|
||||||
|
// Note: compared to Element, we do not cache the actual color, but the color-attr, to remain theme-safe
|
||||||
private val cache = mutableMapOf<String, Int>()
|
private val cache = mutableMapOf<String, Int>()
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
|
@ -54,14 +55,14 @@ class MatrixItemColorProvider @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
USER_COLORING_FROM_ID -> {
|
USER_COLORING_FROM_ID -> {
|
||||||
return cache.getOrPut(matrixItem.id) {
|
return colorProvider.getColorFromAttribute(
|
||||||
colorProvider.getColorFromAttribute(
|
cache.getOrPut(matrixItem.id) {
|
||||||
when (matrixItem) {
|
when (matrixItem) {
|
||||||
is MatrixItem.UserItem -> getColorAttrFromUserId(matrixItem.id)
|
is MatrixItem.UserItem -> getColorAttrFromUserId(matrixItem.id)
|
||||||
else -> getColorAttrFromRoomId(matrixItem.id)
|
else -> getColorAttrFromRoomId(matrixItem.id)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
colorProvider.getColorFromAttribute(android.R.attr.colorAccent)
|
colorProvider.getColorFromAttribute(android.R.attr.colorAccent)
|
||||||
|
|
Loading…
Reference in New Issue