diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt index 9c5f436728..a9b9f8000b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt @@ -115,5 +115,5 @@ sealed class RoomDetailAction : VectorViewModelAction { object PauseRecordingVoiceMessage : RoomDetailAction() data class PlayOrPauseVoicePlayback(val eventId: String, val messageAudioContent: MessageAudioContent) : RoomDetailAction() object PlayOrPauseRecordingPlayback : RoomDetailAction() - object EndAllVoiceActions : RoomDetailAction() + data class EndAllVoiceActions(val deleteRecord: Boolean = true) : RoomDetailAction() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 2066bf9d08..a144715aa2 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -1095,6 +1095,8 @@ class RoomDetailFragment @Inject constructor( textComposerViewModel.handle(TextComposerAction.SaveDraft(views.composerLayout.text.toString())) + // We should improve the UX to support going into playback mode when paused and delete the media when the view is destroyed. + roomDetailViewModel.handle(RoomDetailAction.EndAllVoiceActions(deleteRecord = false)) views.voiceMessageRecorderView.initVoiceRecordingViews() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index bd11ec6718..7971b5123a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -343,7 +343,7 @@ class RoomDetailViewModel @AssistedInject constructor( is RoomDetailAction.PlayOrPauseVoicePlayback -> handlePlayOrPauseVoicePlayback(action) RoomDetailAction.PauseRecordingVoiceMessage -> handlePauseRecordingVoiceMessage() RoomDetailAction.PlayOrPauseRecordingPlayback -> handlePlayOrPauseRecordingPlayback() - RoomDetailAction.EndAllVoiceActions -> handleEndAllVoiceActions() + is RoomDetailAction.EndAllVoiceActions -> handleEndAllVoiceActions(action.deleteRecord) is RoomDetailAction.RoomUpgradeSuccess -> { setState { copy(joinUpgradedRoomAsync = Success(action.replacementRoomId)) @@ -649,8 +649,8 @@ class RoomDetailViewModel @AssistedInject constructor( voiceMessageHelper.startOrPauseRecordingPlayback() } - private fun handleEndAllVoiceActions() { - voiceMessageHelper.stopAllVoiceActions() + private fun handleEndAllVoiceActions(deleteRecord: Boolean) { + voiceMessageHelper.stopAllVoiceActions(deleteRecord) } private fun handlePauseRecordingVoiceMessage() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt index b0880623de..adcd6a3008 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt @@ -217,10 +217,12 @@ class VoiceMessageHelper @Inject constructor( playbackTicker = null } - fun stopAllVoiceActions() { + fun stopAllVoiceActions(deleteRecord: Boolean = true) { stopRecording() stopPlayback() - deleteRecording() + if (deleteRecord) { + deleteRecording() + } playbackTracker.clear() } }