Skip to content

Commit

Permalink
Refactored PreferenceHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
revanthkumarJ committed Jan 13, 2025
1 parent f4d75b6 commit c7bc4e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> { Settings() }
single { PreferencesHelper(settings = get()) }
factory<Settings> { Settings() }

factory {
UserPreferencesDataSource(
settings = get(),
dispatcher = get(named(MifosDispatchers.IO.name))
)
}

single<UserPreferencesRepository> {
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
}

0 comments on commit c7bc4e4

Please sign in to comment.