Fix test compilation issue (no detected since Olm was not available)
This commit is contained in:
parent
2e95c78f4e
commit
31029e90cc
|
@ -18,6 +18,7 @@ package im.vector.app.features.home.room.detail.timeline.helper
|
||||||
|
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.ColorRes
|
import androidx.annotation.ColorRes
|
||||||
|
import androidx.annotation.VisibleForTesting
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.resources.ColorProvider
|
import im.vector.app.core.resources.ColorProvider
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
|
@ -43,30 +44,33 @@ class MatrixItemColorProvider @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ColorRes
|
companion object {
|
||||||
private fun getColorFromUserId(userId: String?): Int {
|
@ColorRes
|
||||||
var hash = 0
|
@VisibleForTesting
|
||||||
|
fun getColorFromUserId(userId: String?): Int {
|
||||||
|
var hash = 0
|
||||||
|
|
||||||
userId?.toList()?.map { chr -> hash = (hash shl 5) - hash + chr.toInt() }
|
userId?.toList()?.map { chr -> hash = (hash shl 5) - hash + chr.toInt() }
|
||||||
|
|
||||||
return when (abs(hash) % 8) {
|
return when (abs(hash) % 8) {
|
||||||
1 -> R.color.riotx_username_2
|
1 -> R.color.riotx_username_2
|
||||||
2 -> R.color.riotx_username_3
|
2 -> R.color.riotx_username_3
|
||||||
3 -> R.color.riotx_username_4
|
3 -> R.color.riotx_username_4
|
||||||
4 -> R.color.riotx_username_5
|
4 -> R.color.riotx_username_5
|
||||||
5 -> R.color.riotx_username_6
|
5 -> R.color.riotx_username_6
|
||||||
6 -> R.color.riotx_username_7
|
6 -> R.color.riotx_username_7
|
||||||
7 -> R.color.riotx_username_8
|
7 -> R.color.riotx_username_8
|
||||||
else -> R.color.riotx_username_1
|
else -> R.color.riotx_username_1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@ColorRes
|
@ColorRes
|
||||||
private fun getColorFromRoomId(roomId: String?): Int {
|
private fun getColorFromRoomId(roomId: String?): Int {
|
||||||
return when ((roomId?.toList()?.sumBy { it.toInt() } ?: 0) % 3) {
|
return when ((roomId?.toList()?.sumBy { it.toInt() } ?: 0) % 3) {
|
||||||
1 -> R.color.riotx_avatar_fill_2
|
1 -> R.color.riotx_avatar_fill_2
|
||||||
2 -> R.color.riotx_avatar_fill_3
|
2 -> R.color.riotx_avatar_fill_3
|
||||||
else -> R.color.riotx_avatar_fill_1
|
else -> R.color.riotx_avatar_fill_1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package im.vector.app.features.home
|
package im.vector.app.features.home
|
||||||
|
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.utils.getColorFromUserId
|
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider.Companion.getColorFromUserId
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue