From c7bc4e4f3c51670f6acf0a33c4556453bd6be4cb Mon Sep 17 00:00:00 2001 From: revanthkumarJ Date: Mon, 13 Jan 2025 10:39:04 +0530 Subject: [PATCH] Refactored PreferenceHelper --- .../mobile/core/datastore/PreferenceHelper.kt | 3 +- ...Source.kt => UserPreferencesDataSource.kt} | 2 +- .../core/datastore/di/PreferenceModule.kt | 31 +++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) rename core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/{UserPreferenceDataSource.kt => UserPreferencesDataSource.kt} (99%) diff --git a/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/PreferenceHelper.kt b/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/PreferenceHelper.kt index a658c9d93..c97ce0206 100644 --- a/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/PreferenceHelper.kt +++ b/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/PreferenceHelper.kt @@ -20,7 +20,8 @@ import org.mifos.mobile.core.datastore.model.AppTheme import org.mifos.mobile.core.datastore.model.UserData class PreferenceHelper( - private val preferenceManager: UserPreferenceDataSource, + private val preferenceManager: UserPreferencesDataSource, + private val ioDispatcher: CoroutineDispatcher, unconfinedDispatcher: CoroutineDispatcher, ) : UserPreferencesRepository { private val unconfinedScope = CoroutineScope(unconfinedDispatcher) diff --git a/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferenceDataSource.kt b/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferencesDataSource.kt similarity index 99% rename from core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferenceDataSource.kt rename to core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferencesDataSource.kt index d696ec112..12cd51e1f 100644 --- a/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferenceDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferencesDataSource.kt @@ -28,7 +28,7 @@ import org.mifos.mobile.core.datastore.model.UserData private const val USER_DATA = "userData" private const val APP_SETTINGS = "appSettings" -class UserPreferenceDataSource( +class UserPreferencesDataSource( private val settings: Settings, private val dispatcher: CoroutineDispatcher, ) { diff --git a/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/di/PreferenceModule.kt b/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/di/PreferenceModule.kt index c23b210e9..c9a12eeb6 100644 --- a/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/di/PreferenceModule.kt +++ b/core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/di/PreferenceModule.kt @@ -10,10 +10,35 @@ package org.mifos.mobile.core.datastore.di import com.russhwolf.settings.Settings +import org.koin.core.qualifier.named import org.koin.dsl.module -import org.mifos.mobile.core.datastore.PreferencesHelper +import org.mifos.mobile.core.datastore.PreferenceHelper +import org.mifos.mobile.core.datastore.UserPreferencesDataSource +import org.mifos.mobile.core.datastore.UserPreferencesRepository + val PreferencesModule = module { - single { Settings() } - single { PreferencesHelper(settings = get()) } + factory { Settings() } + + factory { + UserPreferencesDataSource( + settings = get(), + dispatcher = get(named(MifosDispatchers.IO.name)) + ) + } + + single { + PreferenceHelper( + preferenceManager = get(), + ioDispatcher = get(named(MifosDispatchers.IO.name)), + unconfinedDispatcher = get(named(MifosDispatchers.Unconfined.name)), + ) + } } + +// Should be removed after common module conversion +enum class MifosDispatchers { + Default, + IO, + Unconfined +} \ No newline at end of file