Timeline: copy getInitial method from EA to avoid showing @ as avatar.
This commit is contained in:
parent
b6179b9760
commit
57a879e835
2 changed files with 32 additions and 4 deletions
|
|
@ -93,7 +93,7 @@ private fun InitialsAvatar(
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center),
|
||||||
text = avatarData.getInitial(),
|
text = avatarData.initial,
|
||||||
fontSize = (avatarData.size.dp / 2).value.sp,
|
fontSize = (avatarData.size.dp / 2).value.sp,
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,36 @@ data class AvatarData(
|
||||||
@IgnoredOnParcel
|
@IgnoredOnParcel
|
||||||
val size: AvatarSize = AvatarSize.MEDIUM
|
val size: AvatarSize = AvatarSize.MEDIUM
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
fun getInitial(): String {
|
|
||||||
val firstChar = name?.firstOrNull() ?: id.getOrNull(1) ?: '?'
|
val initial by lazy {
|
||||||
return firstChar.uppercase()
|
(name?.takeIf { it.isNotBlank() } ?: id)
|
||||||
|
.let { dn ->
|
||||||
|
var startIndex = 0
|
||||||
|
val initial = dn[startIndex]
|
||||||
|
|
||||||
|
if (initial in listOf('@', '#', '+') && dn.length > 1) {
|
||||||
|
startIndex++
|
||||||
|
}
|
||||||
|
|
||||||
|
var length = 1
|
||||||
|
var first = dn[startIndex]
|
||||||
|
|
||||||
|
// LEFT-TO-RIGHT MARK
|
||||||
|
if (dn.length >= 2 && 0x200e == first.code) {
|
||||||
|
startIndex++
|
||||||
|
first = dn[startIndex]
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if it’s the start of a surrogate pair
|
||||||
|
if (first.code in 0xD800..0xDBFF && dn.length > startIndex + 1) {
|
||||||
|
val second = dn[startIndex + 1]
|
||||||
|
if (second.code in 0xDC00..0xDFFF) {
|
||||||
|
length++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dn.substring(startIndex, startIndex + length)
|
||||||
|
}
|
||||||
|
.uppercase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue