separating the cancelled and ended events to make the consumption simpler

This commit is contained in:
Adam Brown 2021-11-18 17:25:30 +00:00
parent 4dbb150ac2
commit 1afc1b51e5
2 changed files with 19 additions and 14 deletions

View file

@ -708,18 +708,12 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.handle(RoomDetailAction.PlayOrPauseRecordingPlayback)
}
override fun onVoiceRecordingEnded(lastKnownState: RecordingUiState?) {
when (lastKnownState) {
RecordingUiState.Locked -> {
// do nothing,
// onSendVoiceMessage, onDeleteVoiceMessage or onRecordingLimitReached will be triggered instead
}
else -> {
val isCancelled = lastKnownState == RecordingUiState.Cancelled
roomDetailViewModel.handle(RoomDetailAction.EndRecordingVoiceMessage(isCancelled = isCancelled))
updateRecordingUiState(RecordingUiState.None)
}
}
override fun onVoiceRecordingCancelled() {
onDeleteVoiceMessage()
}
override fun onVoiceRecordingEnded() {
onSendVoiceMessage()
}
override fun onUiStateChanged(state: RecordingUiState) {

View file

@ -41,8 +41,9 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
interface Callback {
fun onVoiceRecordingStarted()
fun onVoiceRecordingEnded(lastKnownState: RecordingUiState?)
fun onVoiceRecordingEnded()
fun onVoicePlaybackButtonClicked()
fun onVoiceRecordingCancelled()
fun onUiStateChanged(state: RecordingUiState)
fun onSendVoiceMessage()
fun onDeleteVoiceMessage()
@ -72,7 +73,17 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
private fun initListeners() {
voiceMessageViews.start(object : VoiceMessageViews.Actions {
override fun onRequestRecording() = callback.onVoiceRecordingStarted()
override fun onMicButtonReleased() = callback.onVoiceRecordingEnded(lastKnownState)
override fun onMicButtonReleased() {
when (lastKnownState) {
RecordingUiState.Locked -> {
// do nothing,
// onSendVoiceMessage, onDeleteVoiceMessage or onRecordingLimitReached will be triggered instead
}
RecordingUiState.Cancelled -> callback.onVoiceRecordingCancelled()
else -> callback.onVoiceRecordingEnded()
}
}
override fun onSendVoiceMessage() = callback.onSendVoiceMessage()
override fun onDeleteVoiceMessage() = callback.onDeleteVoiceMessage()
override fun onWaveformClicked() = callback.onRecordingWaveformClicked()