mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 20:38:40 +00:00
Extract subcomposable InitialOrImageAvatar
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 New Vector Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.designsystem.components.avatar
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
internal fun InitialOrImageAvatar(
|
||||||
|
avatarData: AvatarData,
|
||||||
|
hideAvatarImage: Boolean,
|
||||||
|
forcedAvatarSize: Dp?,
|
||||||
|
avatarType: AvatarType,
|
||||||
|
modifier: Modifier,
|
||||||
|
contentDescription: String?
|
||||||
|
) {
|
||||||
|
when {
|
||||||
|
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
||||||
|
avatarData = avatarData,
|
||||||
|
avatarType = avatarType,
|
||||||
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
|
modifier = modifier,
|
||||||
|
contentDescription = contentDescription,
|
||||||
|
)
|
||||||
|
else -> ImageAvatar(
|
||||||
|
avatarData = avatarData,
|
||||||
|
avatarType = avatarType,
|
||||||
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
|
modifier = modifier,
|
||||||
|
contentDescription = contentDescription,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-17
@@ -28,23 +28,14 @@ internal fun RoomAvatar(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
avatarData.url != null || avatarType.heroes.isEmpty() -> {
|
avatarData.url != null || avatarType.heroes.isEmpty() -> {
|
||||||
if (avatarData.url.isNullOrBlank() || hideAvatarImage) {
|
InitialOrImageAvatar(
|
||||||
InitialLetterAvatar(
|
avatarData = avatarData,
|
||||||
avatarData = avatarData,
|
hideAvatarImage = hideAvatarImage,
|
||||||
avatarType = avatarType,
|
avatarType = avatarType,
|
||||||
modifier = modifier,
|
forcedAvatarSize = null,
|
||||||
contentDescription = contentDescription,
|
modifier = modifier,
|
||||||
forcedAvatarSize = null,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
ImageAvatar(
|
|
||||||
avatarData = avatarData,
|
|
||||||
avatarType = avatarType,
|
|
||||||
forcedAvatarSize = null,
|
|
||||||
modifier = modifier,
|
|
||||||
contentDescription = contentDescription,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
AvatarCluster(
|
AvatarCluster(
|
||||||
|
|||||||
+2
-8
@@ -33,15 +33,9 @@ internal fun SpaceAvatar(
|
|||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
else -> InitialOrImageAvatar(
|
||||||
avatarData = avatarData,
|
|
||||||
avatarType = avatarType,
|
|
||||||
modifier = modifier,
|
|
||||||
contentDescription = contentDescription,
|
|
||||||
forcedAvatarSize = null,
|
|
||||||
)
|
|
||||||
else -> ImageAvatar(
|
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
|
hideAvatarImage = hideAvatarImage,
|
||||||
avatarType = avatarType,
|
avatarType = avatarType,
|
||||||
forcedAvatarSize = null,
|
forcedAvatarSize = null,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
|
|||||||
+8
-17
@@ -19,21 +19,12 @@ internal fun UserAvatar(
|
|||||||
forcedAvatarSize: Dp? = null,
|
forcedAvatarSize: Dp? = null,
|
||||||
hideImage: Boolean = false,
|
hideImage: Boolean = false,
|
||||||
) {
|
) {
|
||||||
if (avatarData.url.isNullOrBlank() || hideImage) {
|
InitialOrImageAvatar(
|
||||||
InitialLetterAvatar(
|
avatarData = avatarData,
|
||||||
avatarData = avatarData,
|
hideAvatarImage = hideImage,
|
||||||
avatarType = AvatarType.User,
|
avatarType = AvatarType.User,
|
||||||
forcedAvatarSize = forcedAvatarSize,
|
modifier = modifier,
|
||||||
modifier = modifier,
|
contentDescription = contentDescription,
|
||||||
contentDescription = contentDescription,
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
ImageAvatar(
|
|
||||||
avatarData = avatarData,
|
|
||||||
avatarType = AvatarType.User,
|
|
||||||
forcedAvatarSize = forcedAvatarSize,
|
|
||||||
modifier = modifier,
|
|
||||||
contentDescription = contentDescription,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user