Skip to content

Commit

Permalink
- wrapper for general mutliplatform settings implementation. Example…
Browse files Browse the repository at this point in the history
… usage of the wrapper in our good old POC greeting-related code. Note this commit make all apps crash because methods are throwing not implemented exceptions on purpose
  • Loading branch information
rodvar committed Nov 18, 2024
1 parent 1d4dc72 commit be5bfe6
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
2 changes: 2 additions & 0 deletions bisqapps/androidNode/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AndroidNodeGreeting>()
class NodeGreetingRepository: GreetingRepository<AndroidNodeGreeting>(getKoin().get())
Original file line number Diff line number Diff line change
@@ -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 <T : BaseModel> save(item: T) {
TODO("Not yet implemented")
}

override suspend fun <T : BaseModel> saveAll(items: List<T>) {
TODO("Not yet implemented")
}

override suspend fun <T : BaseModel> get(): T? {
TODO("Not yet implemented")
}

override suspend fun <T : BaseModel> getAll(): List<T> {
TODO("Not yet implemented")
}

override suspend fun <T : BaseModel> delete(item: T) {
TODO("Not yet implemented")
}

override suspend fun deleteAll() {
TODO("Not yet implemented")
}

override suspend fun clear() {
TODO("Not yet implemented")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package network.bisq.mobile.domain.data.persistance

import network.bisq.mobile.domain.data.model.BaseModel

interface PersistenceSource<T: BaseModel> {
suspend fun save(item: T)
suspend fun saveAll(items: List<T>)
suspend fun get(): T?
suspend fun getAll(): List<T>
suspend fun delete(item: T)
interface PersistenceSource {

suspend fun <T: BaseModel> save(item: T)
suspend fun <T: BaseModel>saveAll(items: List<T>)
suspend fun <T: BaseModel> get(): T?
suspend fun <T: BaseModel> getAll(): List<T>
suspend fun <T: BaseModel> delete(item: T)
suspend fun deleteAll()
suspend fun clear()
}
Original file line number Diff line number Diff line change
@@ -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<T: Greeting>: SingleObjectRepository<T>()
open class GreetingRepository<T: Greeting>(keyValuePersister: KeyValuePersister) : SingleObjectRepository<T>(keyValuePersister)
open class BisqStatsRepository: SingleObjectRepository<BisqStats>()
open class BtcPriceRepository: SingleObjectRepository<BtcPrice>()
open class UserProfileRepository: SingleObjectRepository<UserProfile>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<out T : BaseModel>(
private val persistenceSource: PersistenceSource<T>? = null
private val persistenceSource: PersistenceSource? = null
) : Repository<T> {

private val logger = Logger.withTag(SingleObjectRepository::class.simpleName ?: "SingleObjectRepository")
Expand Down Expand Up @@ -49,7 +49,7 @@ abstract class SingleObjectRepository<out T : BaseModel>(
}

override suspend fun fetch(): T? {
return _data.value ?: persistenceSource?.get().also { _data.value = it }
return _data.value ?: persistenceSource?.get<T>().also { _data.value = it }
}

override suspend fun clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Greeting>> { GreetingRepository() }
single<Settings> { Settings() }
// wrapper for MP settings lib
single<KeyValuePersister> { KeyValuePersister(get()) }

single<BisqStatsRepository> { BisqStatsRepository() }
single<BtcPriceRepository> { BtcPriceRepository() }
single<UserProfileRepository> { UserProfileRepository() }
single<SettingsRepository> { SettingsRepository() }
single { Settings() }

// this example uses persistance with the above
single<GreetingRepository<Greeting>> { GreetingRepository(get()) }
}

0 comments on commit be5bfe6

Please sign in to comment.