From 31029e90cc94526592c6b9638496e6bc00a32168 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 24 Sep 2020 12:46:14 +0200 Subject: [PATCH] Fix test compilation issue (no detected since Olm was not available) --- .../helper/MatrixItemColorProvider.kt | 44 ++++++++++--------- .../vector/app/features/home/UserColorTest.kt | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MatrixItemColorProvider.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MatrixItemColorProvider.kt index adefb33801..6a590206cb 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MatrixItemColorProvider.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MatrixItemColorProvider.kt @@ -18,6 +18,7 @@ package im.vector.app.features.home.room.detail.timeline.helper import androidx.annotation.ColorInt import androidx.annotation.ColorRes +import androidx.annotation.VisibleForTesting import im.vector.app.R import im.vector.app.core.resources.ColorProvider import org.matrix.android.sdk.api.util.MatrixItem @@ -43,30 +44,33 @@ class MatrixItemColorProvider @Inject constructor( } } - @ColorRes - private fun getColorFromUserId(userId: String?): Int { - var hash = 0 + companion object { + @ColorRes + @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) { - 1 -> R.color.riotx_username_2 - 2 -> R.color.riotx_username_3 - 3 -> R.color.riotx_username_4 - 4 -> R.color.riotx_username_5 - 5 -> R.color.riotx_username_6 - 6 -> R.color.riotx_username_7 - 7 -> R.color.riotx_username_8 - else -> R.color.riotx_username_1 + return when (abs(hash) % 8) { + 1 -> R.color.riotx_username_2 + 2 -> R.color.riotx_username_3 + 3 -> R.color.riotx_username_4 + 4 -> R.color.riotx_username_5 + 5 -> R.color.riotx_username_6 + 6 -> R.color.riotx_username_7 + 7 -> R.color.riotx_username_8 + else -> R.color.riotx_username_1 + } } - } - @ColorRes - private fun getColorFromRoomId(roomId: String?): Int { - return when ((roomId?.toList()?.sumBy { it.toInt() } ?: 0) % 3) { - 1 -> R.color.riotx_avatar_fill_2 - 2 -> R.color.riotx_avatar_fill_3 - else -> R.color.riotx_avatar_fill_1 + @ColorRes + private fun getColorFromRoomId(roomId: String?): Int { + return when ((roomId?.toList()?.sumBy { it.toInt() } ?: 0) % 3) { + 1 -> R.color.riotx_avatar_fill_2 + 2 -> R.color.riotx_avatar_fill_3 + else -> R.color.riotx_avatar_fill_1 + } } } } diff --git a/vector/src/test/java/im/vector/app/features/home/UserColorTest.kt b/vector/src/test/java/im/vector/app/features/home/UserColorTest.kt index 0ae2d694ba..0bcce30d34 100644 --- a/vector/src/test/java/im/vector/app/features/home/UserColorTest.kt +++ b/vector/src/test/java/im/vector/app/features/home/UserColorTest.kt @@ -17,7 +17,7 @@ package im.vector.app.features.home 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.Test