EditUserProfileEvents -> EditUserProfileEvent

This commit is contained in:
Benoit Marty 2025-12-03 17:04:53 +01:00 committed by Benoit Marty
parent 766e97dcc1
commit e6dc2501a5
7 changed files with 71 additions and 71 deletions

View file

@ -10,10 +10,10 @@ package io.element.android.features.preferences.impl.user.editprofile
import io.element.android.libraries.matrix.ui.media.AvatarAction
sealed interface EditUserProfileEvents {
data class HandleAvatarAction(val action: AvatarAction) : EditUserProfileEvents
data class UpdateDisplayName(val name: String) : EditUserProfileEvents
data object Exit : EditUserProfileEvents
data object Save : EditUserProfileEvents
data object CloseDialog : EditUserProfileEvents
sealed interface EditUserProfileEvent {
data class HandleAvatarAction(val action: AvatarAction) : EditUserProfileEvent
data class UpdateDisplayName(val name: String) : EditUserProfileEvent
data object Exit : EditUserProfileEvent
data object Save : EditUserProfileEvent
data object CloseDialog : EditUserProfileEvent
}

View file

@ -112,15 +112,15 @@ class EditUserProfilePresenter(
!userDisplayName.isNullOrBlank() && hasProfileChanged
}
fun handleEvent(event: EditUserProfileEvents) {
fun handleEvent(event: EditUserProfileEvent) {
when (event) {
is EditUserProfileEvents.Save -> localCoroutineScope.saveChanges(
is EditUserProfileEvent.Save -> localCoroutineScope.saveChanges(
name = userDisplayName,
avatarUri = userAvatarUri?.toUri(),
currentUser = matrixUser,
action = saveAction,
)
is EditUserProfileEvents.HandleAvatarAction -> {
is EditUserProfileEvent.HandleAvatarAction -> {
when (event.action) {
AvatarAction.ChoosePhoto -> galleryImagePicker.launch()
AvatarAction.TakePhoto -> if (cameraPermissionState.permissionGranted) {
@ -135,8 +135,8 @@ class EditUserProfilePresenter(
}
}
}
is EditUserProfileEvents.UpdateDisplayName -> userDisplayName = event.name
EditUserProfileEvents.Exit -> {
is EditUserProfileEvent.UpdateDisplayName -> userDisplayName = event.name
EditUserProfileEvent.Exit -> {
when (saveAction.value) {
is AsyncAction.Confirming -> {
// Close the dialog right now
@ -157,7 +157,7 @@ class EditUserProfilePresenter(
}
}
}
EditUserProfileEvents.CloseDialog -> saveAction.value = AsyncAction.Uninitialized
EditUserProfileEvent.CloseDialog -> saveAction.value = AsyncAction.Uninitialized
}
}

View file

@ -22,5 +22,5 @@ data class EditUserProfileState(
val saveButtonEnabled: Boolean,
val saveAction: AsyncAction<Unit>,
val cameraPermissionState: PermissionsState,
val eventSink: (EditUserProfileEvents) -> Unit
val eventSink: (EditUserProfileEvent) -> Unit
)

View file

@ -33,7 +33,7 @@ fun aEditUserProfileState(
saveButtonEnabled: Boolean = true,
saveAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
cameraPermissionState: PermissionsState = aPermissionsState(showDialog = false),
eventSink: (EditUserProfileEvents) -> Unit = {},
eventSink: (EditUserProfileEvent) -> Unit = {},
) = EditUserProfileState(
userId = userId,
displayName = displayName,

View file

@ -68,7 +68,7 @@ fun EditUserProfileView(
fun onBackClick() {
focusManager.clearFocus()
state.eventSink(EditUserProfileEvents.Exit)
state.eventSink(EditUserProfileEvent.Exit)
}
BackHandler(
@ -87,7 +87,7 @@ fun EditUserProfileView(
enabled = state.saveButtonEnabled,
onClick = {
focusManager.clearFocus()
state.eventSink(EditUserProfileEvents.Save)
state.eventSink(EditUserProfileEvent.Save)
},
)
}
@ -125,7 +125,7 @@ fun EditUserProfileView(
value = state.displayName,
placeholder = stringResource(CommonStrings.common_room_name_placeholder),
singleLine = true,
onValueChange = { state.eventSink(EditUserProfileEvents.UpdateDisplayName(it)) },
onValueChange = { state.eventSink(EditUserProfileEvent.UpdateDisplayName(it)) },
)
}
@ -133,7 +133,7 @@ fun EditUserProfileView(
actions = state.avatarActions,
isVisible = isAvatarActionsSheetVisible.value,
onDismiss = { isAvatarActionsSheetVisible.value = false },
onSelectAction = { state.eventSink(EditUserProfileEvents.HandleAvatarAction(it)) }
onSelectAction = { state.eventSink(EditUserProfileEvent.HandleAvatarAction(it)) }
)
AsyncActionView(
@ -147,9 +147,9 @@ fun EditUserProfileView(
when (confirming) {
is AsyncAction.ConfirmingCancellation -> {
SaveChangesDialog(
onSaveClick = { state.eventSink(EditUserProfileEvents.Save) },
onDiscardClick = { state.eventSink(EditUserProfileEvents.Exit) },
onDismiss = { state.eventSink(EditUserProfileEvents.CloseDialog) },
onSaveClick = { state.eventSink(EditUserProfileEvent.Save) },
onDiscardClick = { state.eventSink(EditUserProfileEvent.Exit) },
onDismiss = { state.eventSink(EditUserProfileEvent.CloseDialog) },
)
}
}
@ -157,7 +157,7 @@ fun EditUserProfileView(
onSuccess = { onEditProfileSuccess() },
errorTitle = { stringResource(R.string.screen_edit_profile_error_title) },
errorMessage = { stringResource(R.string.screen_edit_profile_error) },
onErrorDismiss = { state.eventSink(EditUserProfileEvents.CloseDialog) },
onErrorDismiss = { state.eventSink(EditUserProfileEvent.CloseDialog) },
)
}
PermissionsView(