Change model and create MatrixBadgeRowMolecule

This commit is contained in:
Benoit Marty 2024-10-16 18:30:16 +02:00 committed by Benoit Marty
parent 86a839ea73
commit 75caeaaec2
3 changed files with 104 additions and 54 deletions

View file

@ -45,6 +45,7 @@ import io.element.android.features.userprofile.shared.blockuser.BlockUserDialogs
import io.element.android.features.userprofile.shared.blockuser.BlockUserSection import io.element.android.features.userprofile.shared.blockuser.BlockUserSection
import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage import io.element.android.libraries.architecture.coverage.ExcludeFromCoverage
import io.element.android.libraries.designsystem.atomic.atoms.MatrixBadgeAtom import io.element.android.libraries.designsystem.atomic.atoms.MatrixBadgeAtom
import io.element.android.libraries.designsystem.atomic.molecules.MatrixBadgeRowMolecule
import io.element.android.libraries.designsystem.components.ClickableLinkText import io.element.android.libraries.designsystem.components.ClickableLinkText
import io.element.android.libraries.designsystem.components.avatar.AvatarData import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.designsystem.components.avatar.AvatarSize import io.element.android.libraries.designsystem.components.avatar.AvatarSize
@ -84,6 +85,7 @@ import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.services.analytics.compose.LocalAnalyticsService import io.element.android.services.analytics.compose.LocalAnalyticsService
import io.element.android.services.analyticsproviders.api.trackers.captureInteraction import io.element.android.services.analyticsproviders.api.trackers.captureInteraction
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toPersistentList import kotlinx.collections.immutable.toPersistentList
@Composable @Composable
@ -114,9 +116,9 @@ fun RoomDetailsView(
) { padding -> ) { padding ->
Column( Column(
modifier = Modifier modifier = Modifier
.padding(padding) .padding(padding)
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
.consumeWindowInsets(padding) .consumeWindowInsets(padding)
) { ) {
LeaveRoomView(state = state.leaveRoomState) LeaveRoomView(state = state.leaveRoomState)
@ -273,8 +275,8 @@ private fun MainActionsSection(
) { ) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
horizontalArrangement = Arrangement.SpaceEvenly, horizontalArrangement = Arrangement.SpaceEvenly,
) { ) {
val roomNotificationSettings = state.roomNotificationSettings val roomNotificationSettings = state.roomNotificationSettings
@ -333,8 +335,8 @@ private fun RoomHeaderSection(
) { ) {
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
CompositeAvatar( CompositeAvatar(
@ -343,8 +345,8 @@ private fun RoomHeaderSection(
user.getAvatarData(size = AvatarSize.RoomHeader) user.getAvatarData(size = AvatarSize.RoomHeader)
}.toPersistentList(), }.toPersistentList(),
modifier = Modifier modifier = Modifier
.clickable(enabled = avatarUrl != null) { openAvatarPreview(avatarUrl!!) } .clickable(enabled = avatarUrl != null) { openAvatarPreview(avatarUrl!!) }
.testTag(TestTags.roomDetailAvatar) .testTag(TestTags.roomDetailAvatar)
) )
TitleAndSubtitle(title = roomName, subtitle = roomAlias?.value) TitleAndSubtitle(title = roomName, subtitle = roomAlias?.value)
} }
@ -360,8 +362,8 @@ private fun DmHeaderSection(
) { ) {
Column( Column(
modifier = modifier modifier = modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
DmAvatars( DmAvatars(
@ -406,32 +408,37 @@ private fun BadgeList(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
if (isEncrypted || isPublic) { if (isEncrypted || isPublic) {
Row( MatrixBadgeRowMolecule(
modifier = modifier modifier = modifier,
.padding(start = 16.dp, end = 16.dp, top = 8.dp), data = buildList {
horizontalArrangement = Arrangement.spacedBy(8.dp), if (isEncrypted) {
) { add(
if (isEncrypted) { MatrixBadgeAtom.MatrixBadgeData(
MatrixBadgeAtom.View( text = stringResource(R.string.screen_room_details_badge_encrypted),
text = stringResource(R.string.screen_room_details_badge_encrypted), icon = CompoundIcons.LockSolid(),
icon = CompoundIcons.LockSolid(), type = MatrixBadgeAtom.Type.Positive,
type = MatrixBadgeAtom.Type.Positive, )
) )
} else { } else {
MatrixBadgeAtom.View( add(
text = stringResource(R.string.screen_room_details_badge_not_encrypted), MatrixBadgeAtom.MatrixBadgeData(
icon = CompoundIcons.LockOff(), text = stringResource(R.string.screen_room_details_badge_not_encrypted),
type = MatrixBadgeAtom.Type.Neutral, icon = CompoundIcons.LockOff(),
) type = MatrixBadgeAtom.Type.Neutral,
} )
if (isPublic) { )
MatrixBadgeAtom.View( }
text = stringResource(R.string.screen_room_details_badge_public), if (isPublic) {
icon = CompoundIcons.Public(), add(
type = MatrixBadgeAtom.Type.Neutral, MatrixBadgeAtom.MatrixBadgeData(
) text = stringResource(R.string.screen_room_details_badge_public),
} icon = CompoundIcons.Public(),
} type = MatrixBadgeAtom.Type.Neutral,
)
)
}
}.toImmutableList(),
)
} }
} }

View file

@ -22,6 +22,12 @@ import io.element.android.libraries.designsystem.theme.badgePositiveBackgroundCo
import io.element.android.libraries.designsystem.theme.badgePositiveContentColor import io.element.android.libraries.designsystem.theme.badgePositiveContentColor
object MatrixBadgeAtom { object MatrixBadgeAtom {
data class MatrixBadgeData(
val text: String,
val icon: ImageVector,
val type: Type,
)
enum class Type { enum class Type {
Positive, Positive,
Neutral, Neutral,
@ -30,28 +36,26 @@ object MatrixBadgeAtom {
@Composable @Composable
fun View( fun View(
text: String, data: MatrixBadgeData,
icon: ImageVector,
type: Type,
) { ) {
val backgroundColor = when (type) { val backgroundColor = when (data.type) {
Type.Positive -> ElementTheme.colors.badgePositiveBackgroundColor Type.Positive -> ElementTheme.colors.badgePositiveBackgroundColor
Type.Neutral -> ElementTheme.colors.badgeNeutralBackgroundColor Type.Neutral -> ElementTheme.colors.badgeNeutralBackgroundColor
Type.Negative -> ElementTheme.colors.badgeNegativeBackgroundColor Type.Negative -> ElementTheme.colors.badgeNegativeBackgroundColor
} }
val textColor = when (type) { val textColor = when (data.type) {
Type.Positive -> ElementTheme.colors.badgePositiveContentColor Type.Positive -> ElementTheme.colors.badgePositiveContentColor
Type.Neutral -> ElementTheme.colors.badgeNeutralContentColor Type.Neutral -> ElementTheme.colors.badgeNeutralContentColor
Type.Negative -> ElementTheme.colors.badgeNegativeContentColor Type.Negative -> ElementTheme.colors.badgeNegativeContentColor
} }
val iconColor = when (type) { val iconColor = when (data.type) {
Type.Positive -> ElementTheme.colors.iconSuccessPrimary Type.Positive -> ElementTheme.colors.iconSuccessPrimary
Type.Neutral -> ElementTheme.colors.iconSecondary Type.Neutral -> ElementTheme.colors.iconSecondary
Type.Negative -> ElementTheme.colors.iconCriticalPrimary Type.Negative -> ElementTheme.colors.iconCriticalPrimary
} }
Badge( Badge(
text = text, text = data.text,
icon = icon, icon = data.icon,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
iconColor = iconColor, iconColor = iconColor,
textColor = textColor, textColor = textColor,
@ -63,9 +67,11 @@ object MatrixBadgeAtom {
@Composable @Composable
internal fun MatrixBadgeAtomPositivePreview() = ElementPreview { internal fun MatrixBadgeAtomPositivePreview() = ElementPreview {
MatrixBadgeAtom.View( MatrixBadgeAtom.View(
text = "Trusted", MatrixBadgeAtom.MatrixBadgeData(
icon = CompoundIcons.Verified(), text = "Trusted",
type = MatrixBadgeAtom.Type.Positive, icon = CompoundIcons.Verified(),
type = MatrixBadgeAtom.Type.Positive,
)
) )
} }
@ -73,9 +79,11 @@ internal fun MatrixBadgeAtomPositivePreview() = ElementPreview {
@Composable @Composable
internal fun MatrixBadgeAtomNeutralPreview() = ElementPreview { internal fun MatrixBadgeAtomNeutralPreview() = ElementPreview {
MatrixBadgeAtom.View( MatrixBadgeAtom.View(
text = "Public room", MatrixBadgeAtom.MatrixBadgeData(
icon = CompoundIcons.Public(), text = "Public room",
type = MatrixBadgeAtom.Type.Neutral, icon = CompoundIcons.Public(),
type = MatrixBadgeAtom.Type.Neutral,
)
) )
} }
@ -83,8 +91,10 @@ internal fun MatrixBadgeAtomNeutralPreview() = ElementPreview {
@Composable @Composable
internal fun MatrixBadgeAtomNegativePreview() = ElementPreview { internal fun MatrixBadgeAtomNegativePreview() = ElementPreview {
MatrixBadgeAtom.View( MatrixBadgeAtom.View(
text = "Not trusted", MatrixBadgeAtom.MatrixBadgeData(
icon = CompoundIcons.Error(), text = "Not trusted",
type = MatrixBadgeAtom.Type.Negative, icon = CompoundIcons.Error(),
type = MatrixBadgeAtom.Type.Negative,
)
) )
} }

View file

@ -0,0 +1,33 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only
* Please see LICENSE in the repository root for full details.
*/
package io.element.android.libraries.designsystem.atomic.molecules
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.atomic.atoms.MatrixBadgeAtom
import kotlinx.collections.immutable.ImmutableList
@Composable
fun MatrixBadgeRowMolecule(
data: ImmutableList<MatrixBadgeAtom.MatrixBadgeData>,
modifier: Modifier = Modifier,
) {
Row(
modifier = modifier
.padding(start = 16.dp, end = 16.dp, top = 8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
for (badge in data) {
MatrixBadgeAtom.View(badge)
}
}
}