feat: Only show processing dialog after some time

Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
Myzel394 2024-03-23 14:01:53 +01:00
parent 7d83bca1fe
commit cfea5a9143
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -33,6 +33,8 @@ import app.myzel394.alibi.ui.utils.rememberFileSaverDialog
import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import java.util.Timer
import kotlin.concurrent.schedule
import kotlin.concurrent.thread import kotlin.concurrent.thread
typealias RecorderModel = BaseRecorderModel< typealias RecorderModel = BaseRecorderModel<
@ -140,10 +142,13 @@ fun RecorderEventsHandler(
recorder: RecorderModel, recorder: RecorderModel,
cleanupOldFiles: Boolean = false cleanupOldFiles: Boolean = false
): CompletableDeferred<Unit> { ): CompletableDeferred<Unit> {
isProcessing = true
val completer = CompletableDeferred<Unit>() val completer = CompletableDeferred<Unit>()
// If processing takes this short, don't show the processing dialog
val timer = Timer().schedule(250L) {
isProcessing = true
}
thread { thread {
runBlocking { runBlocking {
try { try {
@ -231,6 +236,7 @@ fun RecorderEventsHandler(
if (recorder.isCurrentlyActivelyRecording) { if (recorder.isCurrentlyActivelyRecording) {
recorder.recorderService?.unlockFiles(cleanupOldFiles) recorder.recorderService?.unlockFiles(cleanupOldFiles)
} }
timer.cancel()
isProcessing = false isProcessing = false
processingProgress = null processingProgress = null
completer.complete(Unit) completer.complete(Unit)