|
| 1 | +/* |
| 2 | + * Copyright 2025 New Vector Ltd. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | + * Please see LICENSE files in the repository root for full details. |
| 6 | + */ |
| 7 | + |
| 8 | +package io.element.android.libraries.matrix.ui.components |
| 9 | + |
| 10 | +import androidx.compose.foundation.layout.Arrangement.spacedBy |
| 11 | +import androidx.compose.foundation.layout.Column |
| 12 | +import androidx.compose.foundation.layout.Row |
| 13 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 14 | +import androidx.compose.foundation.layout.size |
| 15 | +import androidx.compose.material3.Text |
| 16 | +import androidx.compose.runtime.Composable |
| 17 | +import androidx.compose.runtime.ReadOnlyComposable |
| 18 | +import androidx.compose.ui.Alignment |
| 19 | +import androidx.compose.ui.Modifier |
| 20 | +import androidx.compose.ui.graphics.vector.ImageVector |
| 21 | +import androidx.compose.ui.res.pluralStringResource |
| 22 | +import androidx.compose.ui.res.stringResource |
| 23 | +import androidx.compose.ui.text.style.TextAlign |
| 24 | +import androidx.compose.ui.unit.dp |
| 25 | +import io.element.android.compound.theme.ElementTheme |
| 26 | +import io.element.android.compound.tokens.generated.CompoundIcons |
| 27 | +import io.element.android.libraries.designsystem.preview.ElementPreview |
| 28 | +import io.element.android.libraries.designsystem.preview.PreviewsDayNight |
| 29 | +import io.element.android.libraries.designsystem.theme.components.Icon |
| 30 | +import io.element.android.libraries.matrix.api.room.join.JoinRule |
| 31 | +import io.element.android.libraries.ui.strings.CommonPlurals |
| 32 | +import io.element.android.libraries.ui.strings.CommonStrings |
| 33 | + |
| 34 | +@Composable |
| 35 | +fun SpaceInfoRow( |
| 36 | + leftText: String, |
| 37 | + rightText: String, |
| 38 | + modifier: Modifier = Modifier, |
| 39 | + iconVector: ImageVector? = null, |
| 40 | +) { |
| 41 | + Row( |
| 42 | + modifier = modifier, |
| 43 | + horizontalArrangement = spacedBy(4.dp), |
| 44 | + verticalAlignment = Alignment.CenterVertically, |
| 45 | + ) { |
| 46 | + if (iconVector != null) { |
| 47 | + Icon( |
| 48 | + modifier = Modifier.size(20.dp), |
| 49 | + imageVector = iconVector, |
| 50 | + contentDescription = null, |
| 51 | + tint = ElementTheme.colors.iconTertiary, |
| 52 | + ) |
| 53 | + } |
| 54 | + val text = stringResource(id = CommonStrings.screen_space_list_details, leftText, rightText) |
| 55 | + Text( |
| 56 | + text = text, |
| 57 | + style = ElementTheme.typography.fontBodyLgRegular, |
| 58 | + color = ElementTheme.colors.textSecondary, |
| 59 | + textAlign = TextAlign.Center, |
| 60 | + ) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +@Composable |
| 65 | +fun SpaceInfoRow( |
| 66 | + joinRule: JoinRule, |
| 67 | + numberOfRooms: Int, |
| 68 | + modifier: Modifier = Modifier, |
| 69 | +) { |
| 70 | + val (leftText, rightText, icon) = when (joinRule) { |
| 71 | + JoinRule.Public -> Triple( |
| 72 | + stringResource(id = CommonStrings.common_public_space), |
| 73 | + numberOfRooms(numberOfRooms), |
| 74 | + CompoundIcons.Public(), |
| 75 | + ) |
| 76 | + // TODO External space |
| 77 | + // JoinRule.Private -> Triple( |
| 78 | + // stringResource(id = CommonStrings.common_external_space), |
| 79 | + // numberOfRooms(numberOfRooms), |
| 80 | + // CompoundIcons.Guest(), |
| 81 | + // ) |
| 82 | + // JoinRule.Private, |
| 83 | + else -> Triple( |
| 84 | + stringResource(id = CommonStrings.common_private_space), |
| 85 | + numberOfRooms(numberOfRooms), |
| 86 | + CompoundIcons.Lock(), |
| 87 | + ) |
| 88 | + } |
| 89 | + SpaceInfoRow( |
| 90 | + leftText = leftText, |
| 91 | + rightText = rightText, |
| 92 | + modifier = modifier, |
| 93 | + iconVector = icon, |
| 94 | + ) |
| 95 | +} |
| 96 | + |
| 97 | +@Composable |
| 98 | +@ReadOnlyComposable |
| 99 | +fun numberOfRooms(numberOfRooms: Int): String { |
| 100 | + return pluralStringResource(CommonPlurals.common_rooms, numberOfRooms, numberOfRooms) |
| 101 | +} |
| 102 | + |
| 103 | +@Composable |
| 104 | +@ReadOnlyComposable |
| 105 | +fun numberOfSpaces(numberOfSpaces: Int): String { |
| 106 | + return pluralStringResource(CommonPlurals.common_spaces, numberOfSpaces, numberOfSpaces) |
| 107 | +} |
| 108 | + |
| 109 | +@PreviewsDayNight |
| 110 | +@Composable |
| 111 | +internal fun SpaceInfoRowPreview() = ElementPreview { |
| 112 | + Column( |
| 113 | + modifier = Modifier.fillMaxWidth(), |
| 114 | + verticalArrangement = spacedBy(4.dp), |
| 115 | + horizontalAlignment = Alignment.CenterHorizontally, |
| 116 | + ) { |
| 117 | + SpaceInfoRow( |
| 118 | + leftText = numberOfSpaces(5), |
| 119 | + rightText = numberOfRooms(10), |
| 120 | + ) |
| 121 | + SpaceInfoRow( |
| 122 | + leftText = "Element space", |
| 123 | + rightText = numberOfRooms(16), |
| 124 | + iconVector = CompoundIcons.Workspace(), |
| 125 | + ) |
| 126 | + SpaceInfoRow( |
| 127 | + joinRule = JoinRule.Private, |
| 128 | + numberOfRooms = 4, |
| 129 | + ) |
| 130 | + SpaceInfoRow( |
| 131 | + joinRule = JoinRule.Public, |
| 132 | + numberOfRooms = 10, |
| 133 | + ) |
| 134 | + } |
| 135 | +} |
0 commit comments