mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Add progress bar; Closes #64
This commit is contained in:
parent
e8df9fbc28
commit
c6932fd31d
@ -253,7 +253,7 @@ abstract class BatchesFolder(
|
||||
disableCache: Boolean = false,
|
||||
onNextParameterTry: (String) -> Unit = {},
|
||||
durationPerBatchInMilliseconds: Long = 0,
|
||||
onProgress: (Float) -> Unit = {},
|
||||
onProgress: (Float?) -> Unit = {},
|
||||
): String {
|
||||
if (!disableCache && checkIfOutputAlreadyExists(recordingStart, extension)) {
|
||||
return getOutputFileForFFmpeg(
|
||||
@ -265,6 +265,7 @@ abstract class BatchesFolder(
|
||||
for (parameter in ffmpegParameters) {
|
||||
Log.i("Concatenation", "Trying parameter $parameter")
|
||||
onNextParameterTry(parameter)
|
||||
onProgress(null)
|
||||
|
||||
try {
|
||||
val filePaths = getBatchesForFFmpeg()
|
||||
@ -293,7 +294,13 @@ abstract class BatchesFolder(
|
||||
parameter
|
||||
) { time ->
|
||||
if (fullTime != null) {
|
||||
println("**************** check24")
|
||||
println(time)
|
||||
println(fullTime)
|
||||
onProgress(time / fullTime!!)
|
||||
} else {
|
||||
onProgress(null)
|
||||
println("----------------- nonono")
|
||||
}
|
||||
}.await()
|
||||
return outputFile
|
||||
|
@ -92,8 +92,6 @@ class MediaConverter {
|
||||
"-protocol_whitelist saf,concat,content,file,subfile" +
|
||||
" -i 'concat:$filePathsConcatenated'" +
|
||||
extraCommand +
|
||||
" -nostats" +
|
||||
" -loglevel error" +
|
||||
" -y" +
|
||||
" $outputFile"
|
||||
|
||||
@ -150,8 +148,6 @@ class MediaConverter {
|
||||
" -i ${listFile.absolutePath}" +
|
||||
extraCommand +
|
||||
" -strict normal" +
|
||||
" -nostats" +
|
||||
" -loglevel error" +
|
||||
" -y" +
|
||||
" $outputFile"
|
||||
|
||||
|
@ -41,10 +41,10 @@ fun RecorderProcessingDialog(
|
||||
stringResource(R.string.ui_recorder_action_save_processing_dialog_description),
|
||||
)
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
if (progress != null)
|
||||
LinearProgressIndicator(progress = progress)
|
||||
else
|
||||
if (progress == null)
|
||||
LinearProgressIndicator()
|
||||
else
|
||||
LinearProgressIndicator(progress = progress)
|
||||
}
|
||||
},
|
||||
confirmButton = {}
|
||||
|
@ -18,6 +18,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -34,6 +35,10 @@ import app.myzel394.alibi.ui.SUPPORTS_SCOPED_STORAGE
|
||||
import app.myzel394.alibi.ui.components.atoms.PermissionRequester
|
||||
import app.myzel394.alibi.ui.models.AudioRecorderModel
|
||||
import app.myzel394.alibi.ui.utils.PermissionHelper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun AudioRecordingStart(
|
||||
@ -54,6 +59,17 @@ fun AudioRecordingStart(
|
||||
}
|
||||
}
|
||||
|
||||
println("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww app: ${appSettings.saveFolder}")
|
||||
val requiresExternalPerm = rememberSaveable {
|
||||
appSettings.requiresExternalStoragePermission(context)
|
||||
}
|
||||
println("hasGranted ${requiresExternalPerm}")
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
fun test() {
|
||||
println("appSäääääääääääääääääääääääääääääääättings ${appSettings.saveFolder}")
|
||||
}
|
||||
|
||||
PermissionRequester(
|
||||
permission = Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
icon = Icons.Default.InsertDriveFile,
|
||||
@ -65,11 +81,8 @@ fun AudioRecordingStart(
|
||||
permission = Manifest.permission.RECORD_AUDIO,
|
||||
icon = Icons.Default.Mic,
|
||||
onPermissionAvailable = {
|
||||
if (!SUPPORTS_SCOPED_STORAGE && !PermissionHelper.hasGranted(
|
||||
context,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
) {
|
||||
test()
|
||||
if (appSettings.requiresExternalStoragePermission(context)) {
|
||||
triggerExternalStorage()
|
||||
} else {
|
||||
startRecording = true
|
||||
|
@ -80,11 +80,6 @@ fun VideoRecordingStart(
|
||||
)
|
||||
}
|
||||
|
||||
val hasGrantedStorage = SUPPORTS_SCOPED_STORAGE || PermissionHelper.hasGranted(
|
||||
context,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
|
||||
PermissionRequester(
|
||||
permission = Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
icon = Icons.Default.InsertDriveFile,
|
||||
@ -112,7 +107,7 @@ fun VideoRecordingStart(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
||||
onClick = {
|
||||
if (!hasGrantedStorage) {
|
||||
if (appSettings.requiresExternalStoragePermission(context)) {
|
||||
triggerExternalStorage()
|
||||
return@combinedClickable
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ fun RecorderEventsHandler(
|
||||
var showRecorderError by remember { mutableStateOf(false) }
|
||||
var showBatchesInaccessibleError by remember { mutableStateOf(false) }
|
||||
|
||||
var processingProgress by remember { mutableFloatStateOf(0.0f) }
|
||||
var processingProgress by remember { mutableStateOf<Float?>(null) }
|
||||
|
||||
val saveAudioFile = rememberFileSaverDialog(settings.audioRecorderSettings.getMimeType()) {
|
||||
if (settings.deleteRecordingsImmediately) {
|
||||
|
@ -24,6 +24,7 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
@ -45,15 +46,22 @@ fun PermissionRequester(
|
||||
|
||||
var isGranted by remember { mutableStateOf(PermissionHelper.hasGranted(context, permission)) }
|
||||
var visibleDialog by remember { mutableStateOf<VisibleDialog?>(null) }
|
||||
|
||||
var _runFunc by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
val requestPermission = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.RequestPermission(),
|
||||
onResult = { isPermissionGranted: Boolean ->
|
||||
isGranted = isPermissionGranted
|
||||
|
||||
if (isGranted) {
|
||||
onPermissionAvailable()
|
||||
_runFunc = true
|
||||
} else {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(context as Activity, permission)) {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(
|
||||
context as Activity,
|
||||
permission
|
||||
)
|
||||
) {
|
||||
visibleDialog = VisibleDialog.REQUEST
|
||||
} else {
|
||||
visibleDialog = VisibleDialog.PERMANENTLY_DENIED
|
||||
@ -64,12 +72,21 @@ fun PermissionRequester(
|
||||
|
||||
fun callback() {
|
||||
if (isGranted) {
|
||||
onPermissionAvailable()
|
||||
_runFunc = true
|
||||
} else {
|
||||
requestPermission.launch(permission)
|
||||
}
|
||||
}
|
||||
|
||||
// No idea but this hacky way is required to make sure the callback
|
||||
// `onPermissionAvailable` can access other values such as the app settings.
|
||||
LaunchedEffect(_runFunc) {
|
||||
if (_runFunc) {
|
||||
_runFunc = false
|
||||
onPermissionAvailable()
|
||||
}
|
||||
}
|
||||
|
||||
if (visibleDialog == VisibleDialog.REQUEST) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user