diff --git a/common/translation/build.gradle.kts b/common/translation/build.gradle.kts index dfd5350af3..f0eae4f4d5 100644 --- a/common/translation/build.gradle.kts +++ b/common/translation/build.gradle.kts @@ -17,7 +17,6 @@ sqldelight { packageName.set("com.quran.mobile.translation.data") schemaOutputDirectory.set(file("src/main/sqldelight/databases")) verifyMigrations.set(true) - generateAsync.set(true) } } } diff --git a/common/translation/src/main/kotlin/com/quran/mobile/translation/data/TranslationsDataSource.kt b/common/translation/src/main/kotlin/com/quran/mobile/translation/data/TranslationsDataSource.kt index 9c77d3fb6c..605b2d8639 100644 --- a/common/translation/src/main/kotlin/com/quran/mobile/translation/data/TranslationsDataSource.kt +++ b/common/translation/src/main/kotlin/com/quran/mobile/translation/data/TranslationsDataSource.kt @@ -1,6 +1,5 @@ package com.quran.mobile.translation.data -import app.cash.sqldelight.async.coroutines.awaitAsOne import app.cash.sqldelight.coroutines.asFlow import app.cash.sqldelight.coroutines.mapToList import com.quran.mobile.translation.mapper.LocalTranslationMapper @@ -10,6 +9,7 @@ import kotlinx.coroutines.MainScope import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.withContext import javax.inject.Inject import javax.inject.Singleton @@ -28,37 +28,45 @@ class TranslationsDataSource @Inject constructor(translationsDatabase: Translati fun translations(): StateFlow?> = translations suspend fun updateTranslations(items: List) { - translationsQueries.transaction { - items.forEach { - translationsQueries.update( - id = it.id, - name = it.name, - translator = it.translator, - translatorForeign = it.translatorForeign, - filename = it.filename, - url = it.url, - languageCode = it.languageCode, - version = it.version.toLong(), - minimumRequiredVersion = it.minimumVersion.toLong(), - userDisplayOrder = it.displayOrder.toLong() - ) + withContext(Dispatchers.IO) { + translationsQueries.transaction { + items.forEach { + translationsQueries.update( + id = it.id, + name = it.name, + translator = it.translator, + translatorForeign = it.translatorForeign, + filename = it.filename, + url = it.url, + languageCode = it.languageCode, + version = it.version.toLong(), + minimumRequiredVersion = it.minimumVersion.toLong(), + userDisplayOrder = it.displayOrder.toLong() + ) + } } } } suspend fun removeTranslation(filename: String) { - translationsQueries.deleteByFileName(filename) + withContext(Dispatchers.IO) { + translationsQueries.deleteByFileName(filename) + } } suspend fun removeTranslationsById(ids: List) { - translationsQueries.transaction { - ids.forEach { - translationsQueries.deleteById(it) + withContext(Dispatchers.IO) { + translationsQueries.transaction { + ids.forEach { + translationsQueries.deleteById(it) + } } } } suspend fun maximumDisplayOrder(): Long { - return translationsQueries.greatestDisplayOrder().awaitAsOne().MAX ?: 0 + return withContext(Dispatchers.IO) { + translationsQueries.greatestDisplayOrder().executeAsOne().MAX ?: 0 + } } } diff --git a/common/translation/src/main/kotlin/com/quran/mobile/translation/di/TranslationDataModule.kt b/common/translation/src/main/kotlin/com/quran/mobile/translation/di/TranslationDataModule.kt index a922400461..dca6c7e82d 100644 --- a/common/translation/src/main/kotlin/com/quran/mobile/translation/di/TranslationDataModule.kt +++ b/common/translation/src/main/kotlin/com/quran/mobile/translation/di/TranslationDataModule.kt @@ -1,7 +1,6 @@ package com.quran.mobile.translation.di import android.content.Context -import app.cash.sqldelight.async.coroutines.synchronous import app.cash.sqldelight.driver.android.AndroidSqliteDriver import com.quran.data.di.AppScope import com.quran.mobile.di.qualifier.ApplicationContext @@ -20,7 +19,7 @@ class TranslationDataModule { fun provideTranslationDatabase(@ApplicationContext context: Context): TranslationsDatabase { return TranslationsDatabase( AndroidSqliteDriver( - schema = TranslationsDatabase.Schema.synchronous(), + schema = TranslationsDatabase.Schema, context = context, name = "translations.db" )