Skip to content

Commit

Permalink
feat: Show error dialog when batches folder is inaccessible
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Dec 31, 2023
1 parent 47fc65a commit cf6c653
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/app/myzel394/alibi/ui/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ val SUPPORTS_DARK_MODE_NATIVELY = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q

val MEDIA_SUBFOLDER_NAME = "alibi"

// TODO: Fix!
val SUPPORTS_SCOPED_STORAGE = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
val MEDIA_RECORDINGS_PREFIX = "alibi-recording-"
val RECORDER_MEDIA_SELECTED_VALUE = "_'media"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app.myzel394.alibi.ui.components.RecorderScreen.atoms

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import app.myzel394.alibi.R

@Composable
fun BatchesInaccessibleDialog(
onClose: () -> Unit,
) {
AlertDialog(
onDismissRequest = onClose,
icon = {
Icon(
Icons.Default.Error,
contentDescription = null,
)
},
title = {
Text(stringResource(R.string.ui_audioRecorder_error_recording_title))
},
text = {
Text(stringResource(R.string.ui_audioRecorder_error_batchesInaccessible_description))
},
confirmButton = {
Button(
onClick = onClose,
colors = ButtonDefaults.textButtonColors(),
) {
Text(stringResource(R.string.dialog_close_neutral_label))
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import app.myzel394.alibi.helpers.AudioBatchesFolder
import app.myzel394.alibi.helpers.BatchesFolder
import app.myzel394.alibi.helpers.VideoBatchesFolder
import app.myzel394.alibi.services.IntervalRecorderService
import app.myzel394.alibi.ui.components.RecorderScreen.atoms.BatchesInaccessibleDialog
import app.myzel394.alibi.ui.components.RecorderScreen.atoms.RecorderErrorDialog
import app.myzel394.alibi.ui.components.RecorderScreen.atoms.RecorderProcessingDialog
import app.myzel394.alibi.ui.models.AudioRecorderModel
Expand Down Expand Up @@ -51,6 +52,7 @@ fun RecorderEventsHandler(

var isProcessing by remember { mutableStateOf(false) }
var showRecorderError by remember { mutableStateOf(false) }
var showBatchesInaccessibleError by remember { mutableStateOf(false) }

val saveAudioFile = rememberFileSaverDialog(settings.audioRecorderSettings.getMimeType()) {
if (settings.deleteRecordingsImmediately) {
Expand Down Expand Up @@ -235,6 +237,18 @@ fun RecorderEventsHandler(
showRecorderError = true
}
}
audioRecorder.onBatchesFolderNotAccessible = {
scope.launch {
showBatchesInaccessibleError = true

runCatching {
audioRecorder.stopRecording(context)
}
runCatching {
audioRecorder.destroyService(context)
}
}
}

onDispose {
audioRecorder.onRecordingSave = {}
Expand Down Expand Up @@ -266,6 +280,18 @@ fun RecorderEventsHandler(
showRecorderError = true
}
}
videoRecorder.onBatchesFolderNotAccessible = {
scope.launch {
showBatchesInaccessibleError = true

runCatching {
videoRecorder.stopRecording(context)
}
runCatching {
videoRecorder.destroyService(context)
}
}
}

onDispose {
videoRecorder.onRecordingSave = {}
Expand All @@ -284,4 +310,11 @@ fun RecorderEventsHandler(
onSave = {
},
)

if (showBatchesInaccessibleError)
BatchesInaccessibleDialog(
onClose = {
showBatchesInaccessibleError = false
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract class BaseRecorderModel<I, B : BatchesFolder, T : IntervalRecorderServi
// thus the service is not running and thus doesn't need to be stopped or destroyed
var onRecordingSave: (isSavingAsOldRecording: Boolean) -> Unit = {}
var onError: () -> Unit = {}
var onBatchesFolderNotAccessible: () -> Unit = {}
abstract var batchesFolder: B?

private var notificationDetails: RecorderNotificationHelper.NotificationDetails? = null
Expand All @@ -70,11 +71,14 @@ abstract class BaseRecorderModel<I, B : BatchesFolder, T : IntervalRecorderServi
recorder.onError = {
onError()
}
recorder.onBatchesFolderNotAccessible = {
onBatchesFolderNotAccessible()
}

if (batchesFolder != null) {
recorder.batchesFolder = batchesFolder!!
} else {
batchesFolder = recorder.batchesFolder as B
batchesFolder = recorder.batchesFolder
}

if (settings != null) {
Expand Down Expand Up @@ -167,9 +171,9 @@ abstract class BaseRecorderModel<I, B : BatchesFolder, T : IntervalRecorderServi

fun destroyService(context: Context) {
recorderService!!.destroy()
reset()

stopOldServices(context)
reset()
}

// Bind functions used to manually bind to the service if the app
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,5 @@
<string name="ui_settings_option_saveFolder_externalPermissionRequired_title">Permission required</string>
<string name="ui_settings_option_saveFolder_externalPermissionRequired_text">To access the DCIM folder, you need to grant Alibi the permission to access external storage. Alibi will only use this permission to write your recordings to the DCIM folder.</string>
<string name="ui_settings_option_saveFolder_externalPermissionRequired_action_confirm">Grant permission</string>
<string name="ui_audioRecorder_error_batchesInaccessible_description">Alibi couldn\'t access or write to the batches folder. Try to choose a different folder or use the internal storage instead. The recording has been aborted.</string>
</resources>

0 comments on commit cf6c653

Please sign in to comment.