Update enable state of create room button
This commit is contained in:
parent
f1b350c8d4
commit
5741be3689
5 changed files with 12 additions and 4 deletions
|
|
@ -23,4 +23,5 @@ sealed interface ConfigureRoomEvents {
|
||||||
data class TopicChanged(val topic: String) : ConfigureRoomEvents
|
data class TopicChanged(val topic: String) : ConfigureRoomEvents
|
||||||
data class AvatarUriChanged(val uri: Uri?) : ConfigureRoomEvents
|
data class AvatarUriChanged(val uri: Uri?) : ConfigureRoomEvents
|
||||||
data class RoomPrivacyChanged(val privacy: RoomPrivacy?) : ConfigureRoomEvents
|
data class RoomPrivacyChanged(val privacy: RoomPrivacy?) : ConfigureRoomEvents
|
||||||
|
object CreateRoom : ConfigureRoomEvents
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@ class ConfigureRoomPresenter @AssistedInject constructor(
|
||||||
var topic by rememberSaveable { mutableStateOf("") }
|
var topic by rememberSaveable { mutableStateOf("") }
|
||||||
var avatarUri by rememberSaveable { mutableStateOf<Uri?>(null) }
|
var avatarUri by rememberSaveable { mutableStateOf<Uri?>(null) }
|
||||||
var privacy by rememberSaveable { mutableStateOf<RoomPrivacy?>(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) {
|
fun handleEvents(event: ConfigureRoomEvents) {
|
||||||
when (event) {
|
when (event) {
|
||||||
|
|
@ -50,6 +54,7 @@ class ConfigureRoomPresenter @AssistedInject constructor(
|
||||||
is ConfigureRoomEvents.RoomNameChanged -> roomName = event.name
|
is ConfigureRoomEvents.RoomNameChanged -> roomName = event.name
|
||||||
is ConfigureRoomEvents.TopicChanged -> topic = event.topic
|
is ConfigureRoomEvents.TopicChanged -> topic = event.topic
|
||||||
is ConfigureRoomEvents.RoomPrivacyChanged -> privacy = event.privacy
|
is ConfigureRoomEvents.RoomPrivacyChanged -> privacy = event.privacy
|
||||||
|
ConfigureRoomEvents.CreateRoom -> Unit // TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,6 +64,7 @@ class ConfigureRoomPresenter @AssistedInject constructor(
|
||||||
topic = topic,
|
topic = topic,
|
||||||
avatarUri = avatarUri,
|
avatarUri = avatarUri,
|
||||||
privacy = privacy,
|
privacy = privacy,
|
||||||
|
isCreateButtonEnabled = isCreateButtonEnabled,
|
||||||
eventSink = ::handleEvents,
|
eventSink = ::handleEvents,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,6 @@ data class ConfigureRoomState(
|
||||||
val topic: String,
|
val topic: String,
|
||||||
val avatarUri: Uri?,
|
val avatarUri: Uri?,
|
||||||
val privacy: RoomPrivacy?,
|
val privacy: RoomPrivacy?,
|
||||||
|
val isCreateButtonEnabled: Boolean,
|
||||||
val eventSink: (ConfigureRoomEvents) -> Unit
|
val eventSink: (ConfigureRoomEvents) -> Unit
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ open class ConfigureRoomStateProvider : PreviewParameterProvider<ConfigureRoomSt
|
||||||
override val values: Sequence<ConfigureRoomState>
|
override val values: Sequence<ConfigureRoomState>
|
||||||
get() = sequenceOf(
|
get() = sequenceOf(
|
||||||
aConfigureRoomState(),
|
aConfigureRoomState(),
|
||||||
// Add other state here
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,5 +33,6 @@ fun aConfigureRoomState() = ConfigureRoomState(
|
||||||
topic = "",
|
topic = "",
|
||||||
avatarUri = null,
|
avatarUri = null,
|
||||||
privacy = null,
|
privacy = null,
|
||||||
|
isCreateButtonEnabled = false,
|
||||||
eventSink = {}
|
eventSink = {}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -71,16 +71,15 @@ fun ConfigureRoomView(
|
||||||
state: ConfigureRoomState,
|
state: ConfigureRoomState,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
onBackPressed: () -> Unit = {},
|
onBackPressed: () -> Unit = {},
|
||||||
onCreatePressed: () -> Unit = {},
|
|
||||||
) {
|
) {
|
||||||
val selectedUsersListState = rememberLazyListState()
|
val selectedUsersListState = rememberLazyListState()
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
topBar = {
|
topBar = {
|
||||||
ConfigureRoomToolbar(
|
ConfigureRoomToolbar(
|
||||||
isNextActionEnabled = false,
|
isNextActionEnabled = state.isCreateButtonEnabled,
|
||||||
onBackPressed = onBackPressed,
|
onBackPressed = onBackPressed,
|
||||||
onNextPressed = onCreatePressed,
|
onNextPressed = { state.eventSink(ConfigureRoomEvents.CreateRoom) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { padding ->
|
) { padding ->
|
||||||
|
|
@ -326,6 +325,7 @@ fun RoomPrivacyOption(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move this composable to design module if we want to reuse it in other screens
|
||||||
@Composable
|
@Composable
|
||||||
fun LabelledTextField(
|
fun LabelledTextField(
|
||||||
label: String,
|
label: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue