diff --git a/bisqapps/androidNode/build.gradle.kts b/bisqapps/androidNode/build.gradle.kts index f1154c56..0867259e 100644 --- a/bisqapps/androidNode/build.gradle.kts +++ b/bisqapps/androidNode/build.gradle.kts @@ -120,6 +120,8 @@ dependencies { implementation(project(":shared:domain")) debugImplementation(compose.uiTooling) + implementation(libs.koin.core) + // bisq2 core dependencies implementation(libs.androidx.multidex) implementation(libs.google.guava) diff --git a/bisqapps/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/domain/data/repository/Repositories.kt b/bisqapps/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/domain/data/repository/Repositories.kt index 841187e5..f72aa1f9 100644 --- a/bisqapps/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/domain/data/repository/Repositories.kt +++ b/bisqapps/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/domain/data/repository/Repositories.kt @@ -2,7 +2,9 @@ package network.bisq.mobile.android.node.domain.data.repository import network.bisq.mobile.android.node.AndroidNodeGreeting import network.bisq.mobile.domain.data.repository.GreetingRepository +import org.koin.java.KoinJavaComponent.get +import org.koin.java.KoinJavaComponent.getKoin // this way of definingsupports both platforms // add your repositories here and then in your DI module call this classes for instanciation -class NodeGreetingRepository: GreetingRepository() \ No newline at end of file +class NodeGreetingRepository: GreetingRepository(getKoin().get()) \ No newline at end of file diff --git a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/persistance/KeyValuePersister.kt b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/persistance/KeyValuePersister.kt new file mode 100644 index 00000000..864aa5c4 --- /dev/null +++ b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/persistance/KeyValuePersister.kt @@ -0,0 +1,38 @@ +package network.bisq.mobile.domain.data.persistance + +import com.russhwolf.settings.Settings +import network.bisq.mobile.domain.data.model.BaseModel + +/** + * This implementation relies on multiplatform settings + */ + class KeyValuePersister(settings: Settings): PersistenceSource { + override suspend fun save(item: T) { + TODO("Not yet implemented") + } + + override suspend fun saveAll(items: List) { + TODO("Not yet implemented") + } + + override suspend fun get(): T? { + TODO("Not yet implemented") + } + + override suspend fun getAll(): List { + TODO("Not yet implemented") + } + + override suspend fun delete(item: T) { + TODO("Not yet implemented") + } + + override suspend fun deleteAll() { + TODO("Not yet implemented") + } + + override suspend fun clear() { + TODO("Not yet implemented") + } + +} \ No newline at end of file diff --git a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/persistance/PersistanceSource.kt b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/persistance/PersistanceSource.kt index cfd7d03c..24236175 100644 --- a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/persistance/PersistanceSource.kt +++ b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/persistance/PersistanceSource.kt @@ -2,12 +2,13 @@ package network.bisq.mobile.domain.data.persistance import network.bisq.mobile.domain.data.model.BaseModel -interface PersistenceSource { - suspend fun save(item: T) - suspend fun saveAll(items: List) - suspend fun get(): T? - suspend fun getAll(): List - suspend fun delete(item: T) +interface PersistenceSource { + + suspend fun save(item: T) + suspend fun saveAll(items: List) + suspend fun get(): T? + suspend fun getAll(): List + suspend fun delete(item: T) suspend fun deleteAll() suspend fun clear() } \ No newline at end of file diff --git a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/Repositories.kt b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/Repositories.kt index 0ebf0612..dbca5204 100644 --- a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/Repositories.kt +++ b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/Repositories.kt @@ -1,10 +1,11 @@ package network.bisq.mobile.domain.data.repository import network.bisq.mobile.domain.data.model.* +import network.bisq.mobile.domain.data.persistance.KeyValuePersister // this way of definingsupports both platforms // add your repositories here and then in your DI module call this classes for instanciation -open class GreetingRepository: SingleObjectRepository() +open class GreetingRepository(keyValuePersister: KeyValuePersister) : SingleObjectRepository(keyValuePersister) open class BisqStatsRepository: SingleObjectRepository() open class BtcPriceRepository: SingleObjectRepository() open class UserProfileRepository: SingleObjectRepository() diff --git a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/SingleObjectRepository.kt b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/SingleObjectRepository.kt index d16c58ed..8af88dd2 100644 --- a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/SingleObjectRepository.kt +++ b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/data/repository/SingleObjectRepository.kt @@ -13,7 +13,7 @@ import network.bisq.mobile.domain.data.persistance.PersistenceSource * TODO: create a map-based multi object repository when needed (might need to leverage some kind of id generation on the base model) */ abstract class SingleObjectRepository( - private val persistenceSource: PersistenceSource? = null + private val persistenceSource: PersistenceSource? = null ) : Repository { private val logger = Logger.withTag(SingleObjectRepository::class.simpleName ?: "SingleObjectRepository") @@ -49,7 +49,7 @@ abstract class SingleObjectRepository( } override suspend fun fetch(): T? { - return _data.value ?: persistenceSource?.get().also { _data.value = it } + return _data.value ?: persistenceSource?.get().also { _data.value = it } } override suspend fun clear() { diff --git a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/di/DomainModule.kt b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/di/DomainModule.kt index e7714125..f102f773 100644 --- a/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/di/DomainModule.kt +++ b/bisqapps/shared/domain/src/commonMain/kotlin/network/bisq/mobile/domain/di/DomainModule.kt @@ -3,13 +3,19 @@ package network.bisq.mobile.domain.di import network.bisq.mobile.domain.data.model.* import network.bisq.mobile.domain.data.repository.* import com.russhwolf.settings.Settings +import network.bisq.mobile.domain.data.persistance.KeyValuePersister import org.koin.dsl.module val domainModule = module { - single> { GreetingRepository() } + single { Settings() } + // wrapper for MP settings lib + single { KeyValuePersister(get()) } + single { BisqStatsRepository() } single { BtcPriceRepository() } single { UserProfileRepository() } single { SettingsRepository() } - single { Settings() } + + // this example uses persistance with the above + single> { GreetingRepository(get()) } }