From a39efe8f6820a24f4e604e2c672615e4e2c92010 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:01:54 +0100 Subject: [PATCH] feat: Add confirmation modal for saving current recording Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com> --- .../atoms/SaveCurrentNowModal.kt | 58 +++++++++++++++++++ .../organisms/AudioRecordingStatus.kt | 26 +++++++-- app/src/main/res/values/strings.xml | 2 + 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/SaveCurrentNowModal.kt diff --git a/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/SaveCurrentNowModal.kt b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/SaveCurrentNowModal.kt new file mode 100644 index 0000000..8480f55 --- /dev/null +++ b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/atoms/SaveCurrentNowModal.kt @@ -0,0 +1,58 @@ +package app.myzel394.alibi.ui.components.RecorderScreen.atoms + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalBottomSheet +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.material3.rememberModalBottomSheetState +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import app.myzel394.alibi.R +import app.myzel394.alibi.ui.SHEET_BOTTOM_OFFSET + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun SaveCurrentNowModal( + onDismiss: () -> Unit, + onConfirm: () -> Unit, +) { + val sheetState = rememberModalBottomSheetState(true) + + // Auto save on specific events + ModalBottomSheet( + onDismissRequest = onDismiss, + sheetState = sheetState, + ) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(16.dp), + modifier = Modifier + .fillMaxWidth() + .padding(bottom = SHEET_BOTTOM_OFFSET) + .padding(16.dp) + ) { + Text( + stringResource(R.string.ui_recorder_action_saveCurrent), + style = MaterialTheme.typography.headlineMedium, + textAlign = TextAlign.Center, + ) + + Text( + stringResource(R.string.ui_recorder_action_saveCurrent_explanation), + ) + + TextButton(onClick = onConfirm) { + Text(stringResource(R.string.ui_recorder_action_save_label)) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/AudioRecordingStatus.kt b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/AudioRecordingStatus.kt index 664cc38..0e6d983 100644 --- a/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/AudioRecordingStatus.kt +++ b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/AudioRecordingStatus.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import app.myzel394.alibi.dataStore import app.myzel394.alibi.ui.components.RecorderScreen.atoms.RealtimeAudioVisualizer +import app.myzel394.alibi.ui.components.RecorderScreen.atoms.SaveCurrentNowModal import app.myzel394.alibi.ui.components.RecorderScreen.molecules.MicrophoneStatus import app.myzel394.alibi.ui.components.RecorderScreen.molecules.RecordingControl import app.myzel394.alibi.ui.components.RecorderScreen.molecules.RecordingStatus @@ -123,6 +124,25 @@ fun _PrimitiveControls(audioRecorder: AudioRecorderModel) { val dataStore = context.dataStore val scope = rememberCoroutineScope() + var showConfirmSaveNow by remember { mutableStateOf(false) } + + if (showConfirmSaveNow) { + SaveCurrentNowModal( + onDismiss = { + showConfirmSaveNow = false + }, + onConfirm = { + showConfirmSaveNow = false + + scope.launch { + audioRecorder.recorderService!!.startNewCycle() + + audioRecorder.onRecordingSave(false).join() + } + }, + ) + } + RecordingControl( isPaused = audioRecorder.isPaused, recordingTime = audioRecorder.recordingTime, @@ -160,11 +180,7 @@ fun _PrimitiveControls(audioRecorder: AudioRecorderModel) { } }, onSaveCurrent = { - scope.launch { - audioRecorder.recorderService!!.startNewCycle() - - audioRecorder.onRecordingSave(false).join() - } + showConfirmSaveNow = true }, ) } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 15b1d26..edeb3f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -191,4 +191,6 @@ To protect your privacy, Alibi stores its batches into its own private, encrypted storage. This storage is only accessible by Alibi and can\'t be accessed by other apps or by a possible intruder. Once you save the recording, you will be asked where you want to save the recording to. Please rotate your device to portait mode Back + Save now? + You can save the current ongoing recording by pressing and holding down on the save button. The recording will continue in the background. \ No newline at end of file