Reset form when user press back

This commit is contained in:
Benoit Marty 2020-10-20 17:10:59 +02:00 committed by Benoit Marty
parent 613573931e
commit f567f92d8f
3 changed files with 19 additions and 1 deletions

View File

@ -28,4 +28,5 @@ sealed class CreateRoomAction : VectorViewModelAction {
data class SetIsEncrypted(val isEncrypted: Boolean) : CreateRoomAction()
object Create : CreateRoomAction()
object Reset : CreateRoomAction()
}

View File

@ -29,6 +29,7 @@ import im.vector.app.R
import im.vector.app.core.dialogs.GalleryOrCameraDialogHelper
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.features.media.createUCropWithDefaultSettings
import im.vector.app.features.roomdirectory.RoomDirectorySharedAction
@ -43,7 +44,8 @@ class CreateRoomFragment @Inject constructor(
private val createRoomController: CreateRoomController
) : VectorBaseFragment(),
CreateRoomController.Listener,
GalleryOrCameraDialogHelper.Listener {
GalleryOrCameraDialogHelper.Listener,
OnBackPressed {
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel
private val viewModel: CreateRoomViewModel by activityViewModel()
@ -131,6 +133,11 @@ class CreateRoomFragment @Inject constructor(
viewModel.handle(CreateRoomAction.Create)
}
override fun onBackPressed(toolbarButton: Boolean): Boolean {
viewModel.handle(CreateRoomAction.Reset)
return false
}
override fun invalidate() = withState(viewModel) { state ->
val async = state.asyncCreateRoomRequest
if (async is Success) {

View File

@ -98,9 +98,19 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
is CreateRoomAction.SetIsInRoomDirectory -> setIsInRoomDirectory(action)
is CreateRoomAction.SetIsEncrypted -> setIsEncrypted(action)
is CreateRoomAction.Create -> doCreateRoom()
CreateRoomAction.Reset -> doReset()
}.exhaustive
}
private fun doReset() {
setState {
CreateRoomViewState(
isEncrypted = adminE2EByDefault,
hsAdminHasDisabledE2E = !adminE2EByDefault
)
}
}
private fun setAvatar(action: CreateRoomAction.SetAvatar) = setState { copy(avatarUri = action.imageUri) }
private fun setName(action: CreateRoomAction.SetName) = setState { copy(roomName = action.name) }