From fa9a6ba4635191b5e26245ea5eca05808dd16003 Mon Sep 17 00:00:00 2001 From: IacobIonut01 Date: Sat, 16 Nov 2024 13:08:38 +0200 Subject: [PATCH] Fix database updater worker crashes when there's more than a single media update Signed-off-by: IacobIonut01 --- .../kotlin/com/dot/gallery/core/DatabaseUpdaterWorker.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/dot/gallery/core/DatabaseUpdaterWorker.kt b/app/src/main/kotlin/com/dot/gallery/core/DatabaseUpdaterWorker.kt index fa0988250e..4aa02c7c33 100644 --- a/app/src/main/kotlin/com/dot/gallery/core/DatabaseUpdaterWorker.kt +++ b/app/src/main/kotlin/com/dot/gallery/core/DatabaseUpdaterWorker.kt @@ -18,8 +18,8 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedInject import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.single import kotlinx.coroutines.withContext fun WorkManager.updateDatabase() { @@ -52,8 +52,8 @@ class DatabaseUpdaterWorker @AssistedInject constructor( val mediaVersion = appContext.mediaStoreVersion printDebug("Database is not up to date. Updating to version $mediaVersion") database.getMediaDao().setMediaVersion(MediaVersion(mediaVersion)) - val media = repository.getMedia().map { it.data ?: emptyList() }.single() - database.getMediaDao().updateMedia(media) + val media = repository.getMedia().map { it.data ?: emptyList() }.firstOrNull() + media?.let { database.getMediaDao().updateMedia(it) } delay(5000) }