Theme mxid-based username colors
TODO for follow-up commit: same for mxid-based room colors (maybe with an extra setting?) Change-Id: I827bd967e615f20e12f205c0ae5b24a777e90d45
This commit is contained in:
parent
fbfacc68a4
commit
d87c03c505
|
@ -28,6 +28,18 @@
|
|||
<attr name="user_color_pl_1" format="color" />
|
||||
<attr name="user_color_pl_0" format="color" />
|
||||
|
||||
<attr name="user_color_hash_01" format="color" />
|
||||
<attr name="user_color_hash_02" format="color" />
|
||||
<attr name="user_color_hash_03" format="color" />
|
||||
<attr name="user_color_hash_04" format="color" />
|
||||
<attr name="user_color_hash_05" format="color" />
|
||||
<attr name="user_color_hash_06" format="color" />
|
||||
<attr name="user_color_hash_07" format="color" />
|
||||
<attr name="user_color_hash_08" format="color" />
|
||||
<attr name="room_color_hash_01" format="color" />
|
||||
<attr name="room_color_hash_02" format="color" />
|
||||
<attr name="room_color_hash_03" format="color" />
|
||||
|
||||
<attr name="verification_request_background" format="color" />
|
||||
<attr name="conference_animation_from" format="color" />
|
||||
<attr name="conference_animation_to" format="color" />
|
||||
|
|
|
@ -75,6 +75,14 @@
|
|||
<color name="user_color_sc_pl_1">#03A9F4</color>
|
||||
<color name="user_color_sc_pl_0">#8bc34a</color>
|
||||
-->
|
||||
<color name="user_color_sc_mxid_1">#4189c9</color>
|
||||
<color name="user_color_sc_mxid_2">#aa43a7</color>
|
||||
<color name="user_color_sc_mxid_3">#48a188</color>
|
||||
<color name="user_color_sc_mxid_4">#b3526d</color>
|
||||
<color name="user_color_sc_mxid_5">#be6a31</color>
|
||||
<color name="user_color_sc_mxid_6">#299ea0</color>
|
||||
<color name="user_color_sc_mxid_7">#5c57df</color>
|
||||
<color name="user_color_sc_mxid_8">#69a011</color>
|
||||
|
||||
<!-- Code background colors -->
|
||||
<color name="code_background_sc">#121212</color>
|
||||
|
|
|
@ -138,6 +138,17 @@
|
|||
<item name="backgroundColorLight">@color/element_background_light</item>
|
||||
<item name="conference_animation_from">@color/palette_element_green</item>
|
||||
<item name="conference_animation_to">@color/join_conference_animated_color</item>
|
||||
<item name="user_color_hash_01">@color/element_name_01</item>
|
||||
<item name="user_color_hash_02">@color/element_name_02</item>
|
||||
<item name="user_color_hash_03">@color/element_name_03</item>
|
||||
<item name="user_color_hash_04">@color/element_name_04</item>
|
||||
<item name="user_color_hash_05">@color/element_name_05</item>
|
||||
<item name="user_color_hash_06">@color/element_name_06</item>
|
||||
<item name="user_color_hash_07">@color/element_name_07</item>
|
||||
<item name="user_color_hash_08">@color/element_name_08</item>
|
||||
<item name="room_color_hash_01">@color/element_room_01</item>
|
||||
<item name="room_color_hash_02">@color/element_room_02</item>
|
||||
<item name="room_color_hash_03">@color/element_room_03</item>
|
||||
|
||||
<item name="android:statusBarColor">@color/android_status_bar_background_dark</item>
|
||||
<item name="android:navigationBarColor">@color/android_navigation_bar_background_dark</item>
|
||||
|
|
|
@ -138,6 +138,17 @@
|
|||
<item name="backgroundColorLight">@color/element_background_light</item>
|
||||
<item name="conference_animation_from">@color/palette_element_green</item>
|
||||
<item name="conference_animation_to">@color/join_conference_animated_color</item>
|
||||
<item name="user_color_hash_01">@color/element_name_01</item>
|
||||
<item name="user_color_hash_02">@color/element_name_02</item>
|
||||
<item name="user_color_hash_03">@color/element_name_03</item>
|
||||
<item name="user_color_hash_04">@color/element_name_04</item>
|
||||
<item name="user_color_hash_05">@color/element_name_05</item>
|
||||
<item name="user_color_hash_06">@color/element_name_06</item>
|
||||
<item name="user_color_hash_07">@color/element_name_07</item>
|
||||
<item name="user_color_hash_08">@color/element_name_08</item>
|
||||
<item name="room_color_hash_01">@color/element_room_01</item>
|
||||
<item name="room_color_hash_02">@color/element_room_02</item>
|
||||
<item name="room_color_hash_03">@color/element_room_03</item>
|
||||
|
||||
<!-- Use dark color, to have enough contrast with icons color. windowLightStatusBar is only available in API 23+ -->
|
||||
<item name="android:statusBarColor">@color/android_status_bar_background_dark</item>
|
||||
|
|
|
@ -100,6 +100,14 @@
|
|||
<item name="backgroundColorLight">@color/background_sc_light</item>
|
||||
<item name="conference_animation_from">?colorAccent</item>
|
||||
<item name="conference_animation_to">?colorAccentPale</item>
|
||||
<item name="user_color_hash_01">@color/user_color_sc_mxid_1</item>
|
||||
<item name="user_color_hash_02">@color/user_color_sc_mxid_2</item>
|
||||
<item name="user_color_hash_03">@color/user_color_sc_mxid_3</item>
|
||||
<item name="user_color_hash_04">@color/user_color_sc_mxid_4</item>
|
||||
<item name="user_color_hash_05">@color/user_color_sc_mxid_5</item>
|
||||
<item name="user_color_hash_06">@color/user_color_sc_mxid_6</item>
|
||||
<item name="user_color_hash_07">@color/user_color_sc_mxid_7</item>
|
||||
<item name="user_color_hash_08">@color/user_color_sc_mxid_8</item>
|
||||
|
||||
<item name="android:statusBarColor">@color/background_black_sc</item>
|
||||
<item name="android:navigationBarColor">@color/background_black_sc</item>
|
||||
|
|
|
@ -99,6 +99,14 @@
|
|||
<item name="backgroundColorLight">@color/background_sc_light</item>
|
||||
<item name="conference_animation_from">?colorAccent</item>
|
||||
<item name="conference_animation_to">?colorAccentPale</item>
|
||||
<item name="user_color_hash_01">@color/user_color_sc_mxid_1</item>
|
||||
<item name="user_color_hash_02">@color/user_color_sc_mxid_2</item>
|
||||
<item name="user_color_hash_03">@color/user_color_sc_mxid_3</item>
|
||||
<item name="user_color_hash_04">@color/user_color_sc_mxid_4</item>
|
||||
<item name="user_color_hash_05">@color/user_color_sc_mxid_5</item>
|
||||
<item name="user_color_hash_06">@color/user_color_sc_mxid_6</item>
|
||||
<item name="user_color_hash_07">@color/user_color_sc_mxid_7</item>
|
||||
<item name="user_color_hash_08">@color/user_color_sc_mxid_8</item>
|
||||
|
||||
<item name="android:statusBarColor">@color/background_black_sc</item>
|
||||
<item name="android:navigationBarColor">@color/background_black_sc</item>
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
package im.vector.app.features.home.room.detail.timeline.helper
|
||||
|
||||
import androidx.annotation.AttrRes
|
||||
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 im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -55,10 +55,10 @@ class MatrixItemColorProvider @Inject constructor(
|
|||
}
|
||||
USER_COLORING_FROM_ID -> {
|
||||
return cache.getOrPut(matrixItem.id) {
|
||||
colorProvider.getColor(
|
||||
colorProvider.getColorFromAttribute(
|
||||
when (matrixItem) {
|
||||
is MatrixItem.UserItem -> getColorFromUserId(matrixItem.id)
|
||||
else -> getColorFromRoomId(matrixItem.id)
|
||||
is MatrixItem.UserItem -> getColorAttrFromUserId(matrixItem.id)
|
||||
else -> getColorAttrFromRoomId(matrixItem.id)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -69,9 +69,37 @@ class MatrixItemColorProvider @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@AttrRes
|
||||
fun getColorAttrFromUserId(userId: String?): Int {
|
||||
var hash = 0
|
||||
|
||||
userId?.toList()?.map { chr -> hash = (hash shl 5) - hash + chr.code }
|
||||
|
||||
return when (abs(hash) % 8) {
|
||||
1 -> R.attr.user_color_hash_02
|
||||
2 -> R.attr.user_color_hash_03
|
||||
3 -> R.attr.user_color_hash_04
|
||||
4 -> R.attr.user_color_hash_05
|
||||
5 -> R.attr.user_color_hash_06
|
||||
6 -> R.attr.user_color_hash_07
|
||||
7 -> R.attr.user_color_hash_08
|
||||
else -> R.attr.user_color_hash_01
|
||||
}
|
||||
}
|
||||
|
||||
@AttrRes
|
||||
private fun getColorAttrFromRoomId(roomId: String?): Int {
|
||||
return when ((roomId?.toList()?.sumOf { it.code } ?: 0) % 3) {
|
||||
1 -> R.attr.room_color_hash_02
|
||||
2 -> R.attr.room_color_hash_03
|
||||
else -> R.attr.room_color_hash_01
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ColorRes
|
||||
@VisibleForTesting
|
||||
@Deprecated("Use getColorAttrFromUserId")
|
||||
fun getColorFromUserId(userId: String?): Int {
|
||||
var hash = 0
|
||||
|
||||
|
@ -90,6 +118,7 @@ class MatrixItemColorProvider @Inject constructor(
|
|||
}
|
||||
|
||||
@ColorRes
|
||||
@Deprecated("Use getColorAttrFromRoomId")
|
||||
private fun getColorFromRoomId(roomId: String?): Int {
|
||||
return when ((roomId?.toList()?.sumOf { it.code } ?: 0) % 3) {
|
||||
1 -> R.color.element_room_02
|
||||
|
|
Loading…
Reference in New Issue