Change model and create MatrixBadgeRowMolecule
This commit is contained in:
committed by
Benoit Marty
parent
86a839ea73
commit
75caeaaec2
@@ -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.libraries.architecture.coverage.ExcludeFromCoverage
|
||||
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.avatar.AvatarData
|
||||
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.analyticsproviders.api.trackers.captureInteraction
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
@Composable
|
||||
@@ -114,9 +116,9 @@ fun RoomDetailsView(
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.consumeWindowInsets(padding)
|
||||
.padding(padding)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.consumeWindowInsets(padding)
|
||||
) {
|
||||
LeaveRoomView(state = state.leaveRoomState)
|
||||
|
||||
@@ -273,8 +275,8 @@ private fun MainActionsSection(
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||
) {
|
||||
val roomNotificationSettings = state.roomNotificationSettings
|
||||
@@ -333,8 +335,8 @@ private fun RoomHeaderSection(
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
CompositeAvatar(
|
||||
@@ -343,8 +345,8 @@ private fun RoomHeaderSection(
|
||||
user.getAvatarData(size = AvatarSize.RoomHeader)
|
||||
}.toPersistentList(),
|
||||
modifier = Modifier
|
||||
.clickable(enabled = avatarUrl != null) { openAvatarPreview(avatarUrl!!) }
|
||||
.testTag(TestTags.roomDetailAvatar)
|
||||
.clickable(enabled = avatarUrl != null) { openAvatarPreview(avatarUrl!!) }
|
||||
.testTag(TestTags.roomDetailAvatar)
|
||||
)
|
||||
TitleAndSubtitle(title = roomName, subtitle = roomAlias?.value)
|
||||
}
|
||||
@@ -360,8 +362,8 @@ private fun DmHeaderSection(
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
DmAvatars(
|
||||
@@ -406,32 +408,37 @@ private fun BadgeList(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
if (isEncrypted || isPublic) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.padding(start = 16.dp, end = 16.dp, top = 8.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
if (isEncrypted) {
|
||||
MatrixBadgeAtom.View(
|
||||
text = stringResource(R.string.screen_room_details_badge_encrypted),
|
||||
icon = CompoundIcons.LockSolid(),
|
||||
type = MatrixBadgeAtom.Type.Positive,
|
||||
)
|
||||
} else {
|
||||
MatrixBadgeAtom.View(
|
||||
text = stringResource(R.string.screen_room_details_badge_not_encrypted),
|
||||
icon = CompoundIcons.LockOff(),
|
||||
type = MatrixBadgeAtom.Type.Neutral,
|
||||
)
|
||||
}
|
||||
if (isPublic) {
|
||||
MatrixBadgeAtom.View(
|
||||
text = stringResource(R.string.screen_room_details_badge_public),
|
||||
icon = CompoundIcons.Public(),
|
||||
type = MatrixBadgeAtom.Type.Neutral,
|
||||
)
|
||||
}
|
||||
}
|
||||
MatrixBadgeRowMolecule(
|
||||
modifier = modifier,
|
||||
data = buildList {
|
||||
if (isEncrypted) {
|
||||
add(
|
||||
MatrixBadgeAtom.MatrixBadgeData(
|
||||
text = stringResource(R.string.screen_room_details_badge_encrypted),
|
||||
icon = CompoundIcons.LockSolid(),
|
||||
type = MatrixBadgeAtom.Type.Positive,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
add(
|
||||
MatrixBadgeAtom.MatrixBadgeData(
|
||||
text = stringResource(R.string.screen_room_details_badge_not_encrypted),
|
||||
icon = CompoundIcons.LockOff(),
|
||||
type = MatrixBadgeAtom.Type.Neutral,
|
||||
)
|
||||
)
|
||||
}
|
||||
if (isPublic) {
|
||||
add(
|
||||
MatrixBadgeAtom.MatrixBadgeData(
|
||||
text = stringResource(R.string.screen_room_details_badge_public),
|
||||
icon = CompoundIcons.Public(),
|
||||
type = MatrixBadgeAtom.Type.Neutral,
|
||||
)
|
||||
)
|
||||
}
|
||||
}.toImmutableList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@ import io.element.android.libraries.designsystem.theme.badgePositiveBackgroundCo
|
||||
import io.element.android.libraries.designsystem.theme.badgePositiveContentColor
|
||||
|
||||
object MatrixBadgeAtom {
|
||||
data class MatrixBadgeData(
|
||||
val text: String,
|
||||
val icon: ImageVector,
|
||||
val type: Type,
|
||||
)
|
||||
|
||||
enum class Type {
|
||||
Positive,
|
||||
Neutral,
|
||||
@@ -30,28 +36,26 @@ object MatrixBadgeAtom {
|
||||
|
||||
@Composable
|
||||
fun View(
|
||||
text: String,
|
||||
icon: ImageVector,
|
||||
type: Type,
|
||||
data: MatrixBadgeData,
|
||||
) {
|
||||
val backgroundColor = when (type) {
|
||||
val backgroundColor = when (data.type) {
|
||||
Type.Positive -> ElementTheme.colors.badgePositiveBackgroundColor
|
||||
Type.Neutral -> ElementTheme.colors.badgeNeutralBackgroundColor
|
||||
Type.Negative -> ElementTheme.colors.badgeNegativeBackgroundColor
|
||||
}
|
||||
val textColor = when (type) {
|
||||
val textColor = when (data.type) {
|
||||
Type.Positive -> ElementTheme.colors.badgePositiveContentColor
|
||||
Type.Neutral -> ElementTheme.colors.badgeNeutralContentColor
|
||||
Type.Negative -> ElementTheme.colors.badgeNegativeContentColor
|
||||
}
|
||||
val iconColor = when (type) {
|
||||
val iconColor = when (data.type) {
|
||||
Type.Positive -> ElementTheme.colors.iconSuccessPrimary
|
||||
Type.Neutral -> ElementTheme.colors.iconSecondary
|
||||
Type.Negative -> ElementTheme.colors.iconCriticalPrimary
|
||||
}
|
||||
Badge(
|
||||
text = text,
|
||||
icon = icon,
|
||||
text = data.text,
|
||||
icon = data.icon,
|
||||
backgroundColor = backgroundColor,
|
||||
iconColor = iconColor,
|
||||
textColor = textColor,
|
||||
@@ -63,9 +67,11 @@ object MatrixBadgeAtom {
|
||||
@Composable
|
||||
internal fun MatrixBadgeAtomPositivePreview() = ElementPreview {
|
||||
MatrixBadgeAtom.View(
|
||||
text = "Trusted",
|
||||
icon = CompoundIcons.Verified(),
|
||||
type = MatrixBadgeAtom.Type.Positive,
|
||||
MatrixBadgeAtom.MatrixBadgeData(
|
||||
text = "Trusted",
|
||||
icon = CompoundIcons.Verified(),
|
||||
type = MatrixBadgeAtom.Type.Positive,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -73,9 +79,11 @@ internal fun MatrixBadgeAtomPositivePreview() = ElementPreview {
|
||||
@Composable
|
||||
internal fun MatrixBadgeAtomNeutralPreview() = ElementPreview {
|
||||
MatrixBadgeAtom.View(
|
||||
text = "Public room",
|
||||
icon = CompoundIcons.Public(),
|
||||
type = MatrixBadgeAtom.Type.Neutral,
|
||||
MatrixBadgeAtom.MatrixBadgeData(
|
||||
text = "Public room",
|
||||
icon = CompoundIcons.Public(),
|
||||
type = MatrixBadgeAtom.Type.Neutral,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -83,8 +91,10 @@ internal fun MatrixBadgeAtomNeutralPreview() = ElementPreview {
|
||||
@Composable
|
||||
internal fun MatrixBadgeAtomNegativePreview() = ElementPreview {
|
||||
MatrixBadgeAtom.View(
|
||||
text = "Not trusted",
|
||||
icon = CompoundIcons.Error(),
|
||||
type = MatrixBadgeAtom.Type.Negative,
|
||||
MatrixBadgeAtom.MatrixBadgeData(
|
||||
text = "Not trusted",
|
||||
icon = CompoundIcons.Error(),
|
||||
type = MatrixBadgeAtom.Type.Negative,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user