mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
fix: Fix recording deletions
This commit is contained in:
parent
b2a413f609
commit
558aa2c86f
@ -112,8 +112,7 @@ data class AudioRecorderExporter(
|
|||||||
getFolder(context).deleteRecursively()
|
getFolder(context).deleteRecursively()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasRecordingsAvailable(context: Context) {
|
fun hasRecordingsAvailable(context: Context) =
|
||||||
getFolder(context).listFiles()?.isNotEmpty() ?: false
|
getFolder(context).listFiles()?.isNotEmpty() ?: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -60,7 +60,8 @@ fun StartRecording(
|
|||||||
// Loading this from parent, because if we load it ourselves
|
// Loading this from parent, because if we load it ourselves
|
||||||
// and permissions have already been granted, initial
|
// and permissions have already been granted, initial
|
||||||
// settings will be used, instead of the actual settings.
|
// settings will be used, instead of the actual settings.
|
||||||
appSettings: AppSettings
|
appSettings: AppSettings,
|
||||||
|
onSaveLastRecording: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
@ -168,10 +169,7 @@ fun StartRecording(
|
|||||||
contentDescription = label
|
contentDescription = label
|
||||||
},
|
},
|
||||||
colors = ButtonDefaults.textButtonColors(),
|
colors = ButtonDefaults.textButtonColors(),
|
||||||
onClick = {
|
onClick = onSaveLastRecording,
|
||||||
audioRecorder.stopRecording(context)
|
|
||||||
audioRecorder.onRecordingSave()
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Save,
|
Icons.Default.Save,
|
||||||
|
@ -36,6 +36,7 @@ import app.myzel394.alibi.ui.utils.rememberFileSaverDialog
|
|||||||
import app.myzel394.alibi.R
|
import app.myzel394.alibi.R
|
||||||
import app.myzel394.alibi.dataStore
|
import app.myzel394.alibi.dataStore
|
||||||
import app.myzel394.alibi.db.AppSettings
|
import app.myzel394.alibi.db.AppSettings
|
||||||
|
import app.myzel394.alibi.db.RecordingInformation
|
||||||
import app.myzel394.alibi.helpers.AudioRecorderExporter
|
import app.myzel394.alibi.helpers.AudioRecorderExporter
|
||||||
import app.myzel394.alibi.ui.effects.rememberSettings
|
import app.myzel394.alibi.ui.effects.rememberSettings
|
||||||
import app.myzel394.alibi.ui.models.AudioRecorderModel
|
import app.myzel394.alibi.ui.models.AudioRecorderModel
|
||||||
@ -60,6 +61,14 @@ fun AudioRecorderScreen(
|
|||||||
if (settings.audioRecorderSettings.deleteRecordingsImmediately) {
|
if (settings.audioRecorderSettings.deleteRecordingsImmediately) {
|
||||||
AudioRecorderExporter.clearAllRecordings(context)
|
AudioRecorderExporter.clearAllRecordings(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!AudioRecorderExporter.hasRecordingsAvailable(context)) {
|
||||||
|
scope.launch {
|
||||||
|
dataStore.updateData {
|
||||||
|
it.setLastRecording(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isProcessingAudio by remember { mutableStateOf(false) }
|
var isProcessingAudio by remember { mutableStateOf(false) }
|
||||||
@ -77,10 +86,7 @@ fun AudioRecorderScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DisposableEffect(key1 = audioRecorder, key2 = settings) {
|
fun saveRecording() {
|
||||||
audioRecorder.onRecordingSave = onRecordingSave@{
|
|
||||||
val recordingInformation = audioRecorder.recorderService!!.getRecordingInformation()
|
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
isProcessingAudio = true
|
isProcessingAudio = true
|
||||||
|
|
||||||
@ -88,11 +94,13 @@ fun AudioRecorderScreen(
|
|||||||
delay(100)
|
delay(100)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val file = AudioRecorderExporter(recordingInformation).concatenateFiles()
|
val file = AudioRecorderExporter(
|
||||||
|
audioRecorder.recorderService?.getRecordingInformation()
|
||||||
|
?: settings.lastRecording
|
||||||
|
?: throw Exception("No recording information available"),
|
||||||
|
).concatenateFiles()
|
||||||
|
|
||||||
saveFile(file, file.name)
|
saveFile(file, file.name)
|
||||||
|
|
||||||
saveAsLastRecording()
|
|
||||||
} catch (error: Exception) {
|
} catch (error: Exception) {
|
||||||
Log.getStackTraceString(error)
|
Log.getStackTraceString(error)
|
||||||
} finally {
|
} finally {
|
||||||
@ -100,6 +108,13 @@ fun AudioRecorderScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DisposableEffect(key1 = audioRecorder, key2 = settings) {
|
||||||
|
audioRecorder.onRecordingSave = onRecordingSave@{
|
||||||
|
saveAsLastRecording()
|
||||||
|
|
||||||
|
saveRecording()
|
||||||
|
}
|
||||||
audioRecorder.onError = {
|
audioRecorder.onError = {
|
||||||
saveAsLastRecording()
|
saveAsLastRecording()
|
||||||
|
|
||||||
@ -166,7 +181,9 @@ fun AudioRecorderScreen(
|
|||||||
confirmButton = {
|
confirmButton = {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
audioRecorder.onRecordingSave()
|
showRecorderError = false
|
||||||
|
|
||||||
|
saveRecording()
|
||||||
},
|
},
|
||||||
colors = ButtonDefaults.textButtonColors(),
|
colors = ButtonDefaults.textButtonColors(),
|
||||||
) {
|
) {
|
||||||
@ -206,7 +223,10 @@ fun AudioRecorderScreen(
|
|||||||
if (audioRecorder.isInRecording)
|
if (audioRecorder.isInRecording)
|
||||||
RecordingStatus(audioRecorder = audioRecorder)
|
RecordingStatus(audioRecorder = audioRecorder)
|
||||||
else
|
else
|
||||||
StartRecording(audioRecorder = audioRecorder, appSettings = appSettings)
|
StartRecording(
|
||||||
|
audioRecorder = audioRecorder, appSettings = appSettings,
|
||||||
|
onSaveLastRecording = ::saveRecording,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ import java.io.File
|
|||||||
@Composable
|
@Composable
|
||||||
fun rememberFileSaverDialog(
|
fun rememberFileSaverDialog(
|
||||||
mimeType: String,
|
mimeType: String,
|
||||||
callback: (Uri) -> Unit = {},
|
callback: (Uri?) -> Unit = {},
|
||||||
): ((File, String) -> Unit) {
|
): ((File, String) -> Unit) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
@ -32,10 +32,8 @@ fun rememberFileSaverDialog(
|
|||||||
|
|
||||||
file.value = null
|
file.value = null
|
||||||
|
|
||||||
if (it != null) {
|
|
||||||
callback(it)
|
callback(it)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return { it, name ->
|
return { it, name ->
|
||||||
file.value = it
|
file.value = it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user