Skip to content

Commit

Permalink
fix(audio-recorder): crash if saving immediately
Browse files Browse the repository at this point in the history
` if (isRecording || isRecordingPaused) {` returned true

so `clearRecording` was called even though `stop()` has been called

which crashed.

```
Done -> stopAndSaveRecording()
then -> done() -> onViewFocusChanged()
```

We fix this by setting the state to CLEARED after stopAndSaveRecording

Cause: cad603e
I missed that `stopAndSaveRecording` was public

Fixes 16321
  • Loading branch information
david-allison committed May 4, 2024
1 parent 905a407 commit 5ed93ad
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.ichi2.anki.showThemedToast
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.utils.elapsed
import com.ichi2.anki.utils.formatAsString
import com.ichi2.annotations.NeedsTest
import com.ichi2.audio.AudioRecordingController.RecordingState.AppendToRecording
import com.ichi2.audio.AudioRecordingController.RecordingState.ImmediatePlayback
import com.ichi2.compat.CompatHelper
Expand Down Expand Up @@ -276,6 +277,8 @@ class AudioRecordingController :
}
}

/** Called on pause, and when 'done' is pressed */
@NeedsTest("16321: record -> 'done' without pressing save")
fun onViewFocusChanged() {
Timber.i("activity paused: stopping recording/resetting player")
if (isRecording || isRecordingPaused) {
Expand Down Expand Up @@ -434,7 +437,6 @@ class AudioRecordingController :
fun toggleSave(vibrate: Boolean = true) {
Timber.i("recording completed")
if (vibrate) CompatHelper.compat.vibrate(context, 20)
setUiState(state.afterSave())
stopAndSaveRecording()
// show this snackbar only in the edit field/multimedia activity
if (inEditField) (context as Activity).showSnackbar(context.resources.getString(R.string.audio_saved))
Expand Down Expand Up @@ -571,6 +573,7 @@ class AudioRecordingController :
}
isRecording = false
isAudioRecordingSaved = true
setUiState(state.afterSave())
// save recording only in the edit field not in the reviewer but save it temporarily
if (inEditField) saveRecording()
}
Expand Down

0 comments on commit 5ed93ad

Please sign in to comment.