feat: basic persistent settings
This commit is contained in:
parent
61bb748925
commit
946429a2f5
6 changed files with 38 additions and 4 deletions
|
|
@ -18,7 +18,7 @@ kotlin {
|
|||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
// Add any common dependencies here
|
||||
implementation(libs.settings)
|
||||
}
|
||||
commonTest.dependencies {
|
||||
implementation(libs.kotlin.test)
|
||||
|
|
|
|||
16
core/src/commonMain/kotlin/moe/lava/neon/core/AppSettings.kt
Normal file
16
core/src/commonMain/kotlin/moe/lava/neon/core/AppSettings.kt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package moe.lava.neon.core
|
||||
|
||||
import com.russhwolf.settings.Settings
|
||||
import com.russhwolf.settings.nullableString
|
||||
import com.russhwolf.settings.string
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.Inject
|
||||
import dev.zacsweers.metro.SingleIn
|
||||
|
||||
@SingleIn(AppScope::class)
|
||||
@Inject
|
||||
class AppSettings {
|
||||
private val settings = Settings()
|
||||
|
||||
var token by settings.nullableString()
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
package moe.lava.neon.core.di
|
||||
|
||||
import com.russhwolf.settings.Settings
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.DependencyGraph
|
||||
import dev.zacsweers.metro.GraphExtension
|
||||
import dev.zacsweers.metro.SingleIn
|
||||
import moe.lava.neon.core.AppSettings
|
||||
import moe.lava.neon.core.repository.AuthRepository
|
||||
import moe.lava.neon.core.repository.UserRepository
|
||||
|
||||
|
|
@ -11,4 +13,5 @@ import moe.lava.neon.core.repository.UserRepository
|
|||
interface AppGraph {
|
||||
val auth: AuthRepository
|
||||
val users: UserRepository
|
||||
val settings: AppSettings
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package moe.lava.neon.core.di
|
||||
|
||||
import com.russhwolf.settings.Settings
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.ContributesTo
|
||||
import dev.zacsweers.metro.Provides
|
||||
|
||||
@ContributesTo(AppScope::class)
|
||||
interface Providers {
|
||||
// @Provides
|
||||
// fun providesSettings(): Settings = Settings()
|
||||
}
|
||||
|
|
@ -3,14 +3,15 @@ package moe.lava.neon.core.repository
|
|||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.Inject
|
||||
import dev.zacsweers.metro.SingleIn
|
||||
import moe.lava.neon.core.AppSettings
|
||||
|
||||
@Inject
|
||||
@SingleIn(AppScope::class)
|
||||
class AuthRepository {
|
||||
var token: String? = null
|
||||
class AuthRepository(private val settings: AppSettings) {
|
||||
var token by settings::token
|
||||
private set
|
||||
|
||||
fun login(username: String, password: String) {
|
||||
suspend fun login(username: String, password: String) {
|
||||
// api.login(username, password)
|
||||
}
|
||||
suspend fun login(token: String) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ kotlinx-coroutines = "1.10.2"
|
|||
material3 = "1.10.0-alpha05"
|
||||
material3-adaptive = "1.3.0-alpha03"
|
||||
metro = "0.10.0"
|
||||
settings = "1.3.0"
|
||||
sqldelight = "2.2.1"
|
||||
|
||||
[libraries]
|
||||
|
|
@ -47,6 +48,7 @@ compose-components-resources = { module = "org.jetbrains.compose.components:comp
|
|||
compose-uiToolingPreview = { module = "org.jetbrains.compose.ui:ui-tooling-preview", version.ref = "composeMultiplatform" }
|
||||
kotlinx-coroutinesSwing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }
|
||||
metrox-viewmodel-compose = { module = "dev.zacsweers.metro:metrox-viewmodel-compose", version.ref = "metro" }
|
||||
settings = { module = "com.russhwolf:multiplatform-settings-no-arg", version.ref = "settings" }
|
||||
|
||||
[plugins]
|
||||
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue