Update enable state of create room button

This commit is contained in:
Florian Renaud 2023-04-07 14:51:47 +02:00
parent 572ac9aef0
commit 5d8c0fa5bd
5 changed files with 12 additions and 4 deletions

View file

@ -23,4 +23,5 @@ sealed interface ConfigureRoomEvents {
data class TopicChanged(val topic: String) : ConfigureRoomEvents
data class AvatarUriChanged(val uri: Uri?) : ConfigureRoomEvents
data class RoomPrivacyChanged(val privacy: RoomPrivacy?) : ConfigureRoomEvents
object CreateRoom : ConfigureRoomEvents
}

View file

@ -43,6 +43,10 @@ class ConfigureRoomPresenter @AssistedInject constructor(
var topic by rememberSaveable { mutableStateOf("") }
var avatarUri by rememberSaveable { mutableStateOf<Uri?>(null) }
var privacy by rememberSaveable { mutableStateOf<RoomPrivacy?>(null) }
val isCreateButtonEnabled by rememberSaveable(roomName, privacy) {
val enabled = roomName.isNotEmpty() && privacy != null
mutableStateOf(enabled)
}
fun handleEvents(event: ConfigureRoomEvents) {
when (event) {
@ -50,6 +54,7 @@ class ConfigureRoomPresenter @AssistedInject constructor(
is ConfigureRoomEvents.RoomNameChanged -> roomName = event.name
is ConfigureRoomEvents.TopicChanged -> topic = event.topic
is ConfigureRoomEvents.RoomPrivacyChanged -> privacy = event.privacy
ConfigureRoomEvents.CreateRoom -> Unit // TODO
}
}
@ -59,6 +64,7 @@ class ConfigureRoomPresenter @AssistedInject constructor(
topic = topic,
avatarUri = avatarUri,
privacy = privacy,
isCreateButtonEnabled = isCreateButtonEnabled,
eventSink = ::handleEvents,
)
}

View file

@ -26,5 +26,6 @@ data class ConfigureRoomState(
val topic: String,
val avatarUri: Uri?,
val privacy: RoomPrivacy?,
val isCreateButtonEnabled: Boolean,
val eventSink: (ConfigureRoomEvents) -> Unit
)

View file

@ -24,7 +24,6 @@ open class ConfigureRoomStateProvider : PreviewParameterProvider<ConfigureRoomSt
override val values: Sequence<ConfigureRoomState>
get() = sequenceOf(
aConfigureRoomState(),
// Add other state here
)
}
@ -34,5 +33,6 @@ fun aConfigureRoomState() = ConfigureRoomState(
topic = "",
avatarUri = null,
privacy = null,
isCreateButtonEnabled = false,
eventSink = {}
)

View file

@ -71,16 +71,15 @@ fun ConfigureRoomView(
state: ConfigureRoomState,
modifier: Modifier = Modifier,
onBackPressed: () -> Unit = {},
onCreatePressed: () -> Unit = {},
) {
val selectedUsersListState = rememberLazyListState()
Scaffold(
modifier = modifier,
topBar = {
ConfigureRoomToolbar(
isNextActionEnabled = false,
isNextActionEnabled = state.isCreateButtonEnabled,
onBackPressed = onBackPressed,
onNextPressed = onCreatePressed,
onNextPressed = { state.eventSink(ConfigureRoomEvents.CreateRoom) },
)
}
) { padding ->
@ -326,6 +325,7 @@ fun RoomPrivacyOption(
}
}
// Move this composable to design module if we want to reuse it in other screens
@Composable
fun LabelledTextField(
label: String,