From 24d4270215d749d257ee7b34b08d6d19b27a1399 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 6 Nov 2024 14:57:55 +0100 Subject: [PATCH] create room : clean up after review. --- .../createroom/impl/CreateRoomDataStore.kt | 2 +- .../impl/components/RoomAccessOption.kt | 86 -------------- .../impl/components/RoomVisibilityOption.kt | 108 ------------------ .../configureroom/ConfigureRoomPresenter.kt | 2 +- .../impl/configureroom/ConfigureRoomView.kt | 41 ++++--- 5 files changed, 26 insertions(+), 213 deletions(-) delete mode 100644 features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomAccessOption.kt delete mode 100644 features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomVisibilityOption.kt diff --git a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/CreateRoomDataStore.kt b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/CreateRoomDataStore.kt index 36feb0aec3..56ebe326dd 100644 --- a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/CreateRoomDataStore.kt +++ b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/CreateRoomDataStore.kt @@ -37,7 +37,7 @@ class CreateRoomDataStore @Inject constructor( field = value } - val createRoomConfig: Flow = combine( + val createRoomConfigWithInvites: Flow = combine( selectedUserListDataStore.selectedUsers(), createRoomConfigFlow, ) { selectedUsers, config -> diff --git a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomAccessOption.kt b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomAccessOption.kt deleted file mode 100644 index 6cde477f2e..0000000000 --- a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomAccessOption.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.features.createroom.impl.components - -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.selection.selectable -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.Role -import androidx.compose.ui.unit.dp -import io.element.android.compound.theme.ElementTheme -import io.element.android.features.createroom.impl.configureroom.RoomAccessItem -import io.element.android.libraries.designsystem.preview.ElementPreview -import io.element.android.libraries.designsystem.preview.PreviewsDayNight -import io.element.android.libraries.designsystem.theme.components.RadioButton -import io.element.android.libraries.designsystem.theme.components.Text - -@Composable -fun RoomAccessOption( - roomAccessItem: RoomAccessItem, - onOptionClick: (RoomAccessItem) -> Unit, - modifier: Modifier = Modifier, - isSelected: Boolean = false, -) { - Row( - modifier - .fillMaxWidth() - .selectable( - selected = isSelected, - onClick = { onOptionClick(roomAccessItem) }, - role = Role.RadioButton, - ) - ) { - Column(Modifier.weight(1f)) { - Text( - text = stringResource(roomAccessItem.title), - style = ElementTheme.typography.fontBodyLgRegular, - color = MaterialTheme.colorScheme.primary, - ) - Spacer(Modifier.size(8.dp)) - Text( - text = stringResource(roomAccessItem.description), - style = ElementTheme.typography.fontBodySmRegular, - color = MaterialTheme.colorScheme.tertiary, - ) - } - RadioButton( - modifier = Modifier - .align(Alignment.CenterVertically) - .size(48.dp), - selected = isSelected, - // null recommended for accessibility with screenreaders - onClick = null - ) - } -} - -@PreviewsDayNight -@Composable -internal fun RoomAccessOptionPreview() = ElementPreview { - val aRoomAccessItem = RoomAccessItem.Anyone - Column { - RoomAccessOption( - roomAccessItem = aRoomAccessItem, - onOptionClick = {}, - isSelected = true, - ) - RoomAccessOption( - roomAccessItem = aRoomAccessItem, - onOptionClick = {}, - isSelected = false, - ) - } -} diff --git a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomVisibilityOption.kt b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomVisibilityOption.kt deleted file mode 100644 index e76296fa4c..0000000000 --- a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/components/RoomVisibilityOption.kt +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2023, 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.features.createroom.impl.components - -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.selection.selectable -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.Role -import androidx.compose.ui.unit.dp -import io.element.android.compound.theme.ElementTheme -import io.element.android.features.createroom.impl.configureroom.RoomVisibilityItem -import io.element.android.libraries.designsystem.preview.ElementPreview -import io.element.android.libraries.designsystem.preview.PreviewsDayNight -import io.element.android.libraries.designsystem.theme.components.Icon -import io.element.android.libraries.designsystem.theme.components.RadioButton -import io.element.android.libraries.designsystem.theme.components.Text - -@Composable -fun RoomVisibilityOption( - roomPrivacyItem: RoomVisibilityItem, - onOptionClick: (RoomVisibilityItem) -> Unit, - modifier: Modifier = Modifier, - isSelected: Boolean = false, -) { - Row( - modifier - .fillMaxWidth() - .selectable( - selected = isSelected, - onClick = { onOptionClick(roomPrivacyItem) }, - role = Role.RadioButton, - ) - ) { - Box( - modifier = Modifier - .size(30.dp) - .clip(RoundedCornerShape(8.dp)) - .background(ElementTheme.colors.bgSubtleSecondary) - .padding(3.dp), - contentAlignment = Alignment.Center, - ) { - Icon( - resourceId = roomPrivacyItem.icon, - contentDescription = null, - tint = if (isSelected) ElementTheme.colors.iconPrimary else ElementTheme.colors.iconSecondary, - ) - } - Spacer(Modifier.size(16.dp)) - Column(Modifier.weight(1f)) { - Text( - text = stringResource(roomPrivacyItem.title), - style = ElementTheme.typography.fontBodyLgRegular, - color = MaterialTheme.colorScheme.primary, - ) - Spacer(Modifier.size(3.dp)) - Text( - text = stringResource(roomPrivacyItem.description), - style = ElementTheme.typography.fontBodySmRegular, - color = MaterialTheme.colorScheme.tertiary, - ) - } - - RadioButton( - modifier = Modifier - .align(Alignment.CenterVertically) - .size(48.dp), - selected = isSelected, - // null recommended for accessibility with screenreaders - onClick = null - ) - } -} - -@PreviewsDayNight -@Composable -internal fun RoomVisibilityOptionPreview() = ElementPreview { - val aRoomPrivacyItem = RoomVisibilityItem.Private - Column { - RoomVisibilityOption( - roomPrivacyItem = aRoomPrivacyItem, - onOptionClick = {}, - isSelected = true, - ) - RoomVisibilityOption( - roomPrivacyItem = aRoomPrivacyItem, - onOptionClick = {}, - isSelected = false, - ) - } -} diff --git a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomPresenter.kt b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomPresenter.kt index 1b7623adfb..ad19d2cb9b 100644 --- a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomPresenter.kt +++ b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomPresenter.kt @@ -58,7 +58,7 @@ class ConfigureRoomPresenter @Inject constructor( @Composable override fun present(): ConfigureRoomState { val cameraPermissionState = cameraPermissionPresenter.present() - val createRoomConfig = dataStore.createRoomConfig.collectAsState(CreateRoomConfig()) + val createRoomConfig = dataStore.createRoomConfigWithInvites.collectAsState(CreateRoomConfig()) val homeserverName = remember { matrixClient.userIdServerName() } val isKnockFeatureEnabled by featureFlagService.isFeatureEnabledFlow(FeatureFlags.Knock).collectAsState(initial = false) diff --git a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomView.kt b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomView.kt index 1101f9d35f..b0084f68f6 100644 --- a/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomView.kt +++ b/features/createroom/impl/src/main/kotlin/io/element/android/features/createroom/impl/configureroom/ConfigureRoomView.kt @@ -36,16 +36,18 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import io.element.android.compound.theme.ElementTheme import io.element.android.features.createroom.impl.R -import io.element.android.features.createroom.impl.components.RoomAccessOption -import io.element.android.features.createroom.impl.components.RoomVisibilityOption +import io.element.android.libraries.designsystem.atomic.atoms.RoundedIconAtom +import io.element.android.libraries.designsystem.atomic.atoms.RoundedIconAtomSize import io.element.android.libraries.designsystem.components.LabelledTextField import io.element.android.libraries.designsystem.components.async.AsyncActionView import io.element.android.libraries.designsystem.components.async.AsyncActionViewDefaults import io.element.android.libraries.designsystem.components.button.BackButton +import io.element.android.libraries.designsystem.components.list.ListItemContent import io.element.android.libraries.designsystem.modifiers.clearFocusOnTap import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.theme.aliasScreenTitle +import io.element.android.libraries.designsystem.theme.components.ListItem import io.element.android.libraries.designsystem.theme.components.Scaffold import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.components.TextButton @@ -247,20 +249,17 @@ private fun RoomTopic( @Composable private fun ConfigureRoomOptions( title: String, - verticalArrangement: Arrangement.Vertical, modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit, ) { Column( - modifier = modifier - .selectableGroup() - .padding(horizontal = 12.dp), - verticalArrangement = verticalArrangement, + modifier = modifier.selectableGroup() ) { Text( text = title, style = ElementTheme.typography.fontBodyLgMedium, color = ElementTheme.colors.textPrimary, + modifier = Modifier.padding(horizontal = 16.dp), ) content() } @@ -275,13 +274,21 @@ private fun RoomVisibilityOptions( ConfigureRoomOptions( title = stringResource(R.string.screen_create_room_room_visibility_section_title), modifier = modifier, - verticalArrangement = Arrangement.spacedBy(16.dp), ) { RoomVisibilityItem.entries.forEach { item -> - RoomVisibilityOption( - roomPrivacyItem = item, - isSelected = item == selected, - onOptionClick = onOptionClick, + val isSelected = item == selected + ListItem( + leadingContent = ListItemContent.Custom { + RoundedIconAtom( + size = RoundedIconAtomSize.Big, + resourceId = item.icon, + tint = if (isSelected) ElementTheme.colors.iconPrimary else ElementTheme.colors.iconSecondary, + ) + }, + headlineContent = { Text(text = stringResource(item.title)) }, + supportingContent = { Text(text = stringResource(item.description)) }, + trailingContent = ListItemContent.RadioButton(selected = isSelected), + onClick = { onOptionClick(item) }, ) } } @@ -296,13 +303,13 @@ private fun RoomAccessOptions( ConfigureRoomOptions( title = stringResource(R.string.screen_create_room_room_access_section_header), modifier = modifier, - verticalArrangement = Arrangement.spacedBy(12.dp), ) { RoomAccessItem.entries.forEach { item -> - RoomAccessOption( - roomAccessItem = item, - isSelected = item == selected, - onOptionClick = onOptionClick, + ListItem( + headlineContent = { Text(text = stringResource(item.title)) }, + supportingContent = { Text(text = stringResource(item.description)) }, + trailingContent = ListItemContent.RadioButton(selected = item == selected), + onClick = { onOptionClick(item) }, ) } }