Skip to content

Commit

Permalink
[#3144] Remove Persistence and use DI dispatchers in Coroutine based …
Browse files Browse the repository at this point in the history
…Persistences (#3145)

* [#3144] Remove Persistence and use DI dispatchers in Coroutine based Persistences

* [#3144] Remove Persistence and use DI dispatchers in Coroutine based Persistences
  • Loading branch information
mustafaozhan committed Feb 1, 2024
1 parent 5f4251e commit c59e1a5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 156 deletions.
1 change: 1 addition & 0 deletions client/core/persistence/client-core-persistence.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ kotlin {

sourceSets {
commonMain.dependencies {
implementation(project(Modules.Common.Core.infrastructure))
libs.common.apply {
implementation(koinCore)
implementation(coroutines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ import android.content.Context
import android.content.SharedPreferences
import com.oztechan.ccc.client.core.persistence.FlowPersistence
import com.oztechan.ccc.client.core.persistence.FlowPersistenceImpl
import com.oztechan.ccc.client.core.persistence.Persistence
import com.oztechan.ccc.client.core.persistence.PersistenceImpl
import com.oztechan.ccc.client.core.persistence.SuspendPersistence
import com.oztechan.ccc.client.core.persistence.SuspendPersistenceImpl
import com.oztechan.ccc.common.core.infrastructure.di.DISPATCHER_IO
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.Settings
import com.russhwolf.settings.SharedPreferencesSettings
import com.russhwolf.settings.coroutines.FlowSettings
import com.russhwolf.settings.coroutines.SuspendSettings
import com.russhwolf.settings.coroutines.toFlowSettings
import com.russhwolf.settings.coroutines.toSuspendSettings
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.core.qualifier.named
import org.koin.dsl.module

private const val KEY_APPLICATION_PREFERENCES = "application_preferences"
Expand All @@ -25,17 +21,13 @@ actual val clientCorePersistenceModule = module {
singleOf(::provideSharedPreferences)

single<ObservableSettings> { SharedPreferencesSettings(get()) }
single<Settings> { get<ObservableSettings>() }
@Suppress("OPT_IN_USAGE")
single<SuspendSettings> { get<ObservableSettings>().toSuspendSettings() }
@Suppress("OPT_IN_USAGE")
single<FlowSettings> { get<ObservableSettings>().toFlowSettings() }

singleOf(::PersistenceImpl) { bind<Persistence>() }
@Suppress("OPT_IN_USAGE")
singleOf(::FlowPersistenceImpl) { bind<FlowPersistence>() }
@Suppress("OPT_IN_USAGE")
singleOf(::SuspendPersistenceImpl) { bind<SuspendPersistence>() }
single<FlowPersistence> {
FlowPersistenceImpl(get<ObservableSettings>().toFlowSettings(get(named(DISPATCHER_IO))))
}
single<SuspendPersistence> {
SuspendPersistenceImpl(get<ObservableSettings>().toSuspendSettings(get(named(DISPATCHER_IO))))
}
}

private fun provideSharedPreferences(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,27 @@ package com.oztechan.ccc.client.core.persistence.di

import com.oztechan.ccc.client.core.persistence.FlowPersistence
import com.oztechan.ccc.client.core.persistence.FlowPersistenceImpl
import com.oztechan.ccc.client.core.persistence.Persistence
import com.oztechan.ccc.client.core.persistence.PersistenceImpl
import com.oztechan.ccc.client.core.persistence.SuspendPersistence
import com.oztechan.ccc.client.core.persistence.SuspendPersistenceImpl
import com.oztechan.ccc.common.core.infrastructure.di.DISPATCHER_IO
import com.russhwolf.settings.NSUserDefaultsSettings
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.Settings
import com.russhwolf.settings.coroutines.FlowSettings
import com.russhwolf.settings.coroutines.SuspendSettings
import com.russhwolf.settings.coroutines.toFlowSettings
import com.russhwolf.settings.coroutines.toSuspendSettings
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.core.qualifier.named
import org.koin.dsl.module

actual val clientCorePersistenceModule = module {
single<ObservableSettings> {
NSUserDefaultsSettings(get<NativeDependencyWrapper>().userDefaults)
}
single<Settings> { get<ObservableSettings>() }
@Suppress("OPT_IN_USAGE")
single<SuspendSettings> { get<ObservableSettings>().toSuspendSettings() }
@Suppress("OPT_IN_USAGE")
single<FlowSettings> { get<ObservableSettings>().toFlowSettings() }

singleOf(::PersistenceImpl) { bind<Persistence>() }
@Suppress("OPT_IN_USAGE")
singleOf(::FlowPersistenceImpl) { bind<FlowPersistence>() }
single<FlowPersistence> {
FlowPersistenceImpl(get<ObservableSettings>().toFlowSettings(get(named(DISPATCHER_IO))))
}
@Suppress("OPT_IN_USAGE")
singleOf(::SuspendPersistenceImpl) { bind<SuspendPersistence>() }
single<SuspendPersistence> {
SuspendPersistenceImpl(get<ObservableSettings>().toSuspendSettings(get(named(DISPATCHER_IO))))
}
}

0 comments on commit c59e1a5

Please sign in to comment.