Reset form when user press back
This commit is contained in:
parent
613573931e
commit
f567f92d8f
|
@ -28,4 +28,5 @@ sealed class CreateRoomAction : VectorViewModelAction {
|
|||
data class SetIsEncrypted(val isEncrypted: Boolean) : CreateRoomAction()
|
||||
|
||||
object Create : CreateRoomAction()
|
||||
object Reset : CreateRoomAction()
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in New Issue