From f567f92d8f3957387e6408037648fa753237a762 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 20 Oct 2020 17:10:59 +0200 Subject: [PATCH] Reset form when user press back --- .../roomdirectory/createroom/CreateRoomAction.kt | 1 + .../roomdirectory/createroom/CreateRoomFragment.kt | 9 ++++++++- .../roomdirectory/createroom/CreateRoomViewModel.kt | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomAction.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomAction.kt index 17aa8c8deb..4b3eacffaa 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomAction.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomAction.kt @@ -28,4 +28,5 @@ sealed class CreateRoomAction : VectorViewModelAction { data class SetIsEncrypted(val isEncrypted: Boolean) : CreateRoomAction() object Create : CreateRoomAction() + object Reset : CreateRoomAction() } diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt index 0b6d12bc98..e12939f222 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt @@ -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) { diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt index c40744a258..a0e0672d25 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt @@ -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) }