mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-05-18 14:34:12 +02:00
feat(connector): add Koin dependency injection
This commit is contained in:
parent
79c497e24c
commit
08b6c86283
@ -8,6 +8,9 @@ plugins {
|
|||||||
|
|
||||||
val material3Version = "1.6.1"
|
val material3Version = "1.6.1"
|
||||||
val voyagerVersion = "1.0.0"
|
val voyagerVersion = "1.0.0"
|
||||||
|
val kotlinxVersion = "1.8.0"
|
||||||
|
val koinVersion = "3.5.3"
|
||||||
|
val kodeinVersion = "7.21.2"
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
jvm("desktop")
|
jvm("desktop")
|
||||||
@ -29,6 +32,11 @@ kotlin {
|
|||||||
implementation(compose.desktop.currentOs)
|
implementation(compose.desktop.currentOs)
|
||||||
implementation("org.jetbrains.compose.material3:material3-desktop:$material3Version")
|
implementation("org.jetbrains.compose.material3:material3-desktop:$material3Version")
|
||||||
|
|
||||||
|
// Koin
|
||||||
|
implementation(project.dependencies.platform("io.insert-koin:koin-bom:$koinVersion"))
|
||||||
|
implementation("io.insert-koin:koin-core:$koinVersion")
|
||||||
|
implementation("io.insert-koin:koin-compose:1.1.2")
|
||||||
|
|
||||||
// Voyager - Navigation
|
// Voyager - Navigation
|
||||||
// Multiplatform
|
// Multiplatform
|
||||||
|
|
||||||
@ -47,6 +55,11 @@ kotlin {
|
|||||||
// Transitions
|
// Transitions
|
||||||
implementation("cafe.adriel.voyager:voyager-transitions:$voyagerVersion")
|
implementation("cafe.adriel.voyager:voyager-transitions:$voyagerVersion")
|
||||||
|
|
||||||
|
// Koin integration
|
||||||
|
implementation("cafe.adriel.voyager:voyager-koin:$voyagerVersion")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Desktop + Android
|
// Desktop + Android
|
||||||
|
|
||||||
// Kodein integration
|
// Kodein integration
|
||||||
@ -54,6 +67,8 @@ kotlin {
|
|||||||
|
|
||||||
// RxJava integration
|
// RxJava integration
|
||||||
implementation("cafe.adriel.voyager:voyager-rxjava:$voyagerVersion")
|
implementation("cafe.adriel.voyager:voyager-rxjava:$voyagerVersion")
|
||||||
|
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$kotlinxVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
@ -18,12 +19,15 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
||||||
import org.jetbrains.compose.ui.tooling.preview.Preview
|
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||||
import tab.*
|
import org.koin.compose.KoinContext
|
||||||
|
import tab.About
|
||||||
|
import tab.Settings
|
||||||
|
import tab.SimulatorTest
|
||||||
|
import tab.TestResults
|
||||||
import tab.procedure.Procedures
|
import tab.procedure.Procedures
|
||||||
import tab.project.Projects
|
import tab.project.Projects
|
||||||
import theme.AppTheme
|
import theme.AppTheme
|
||||||
|
|
||||||
@OptIn(ExperimentalResourceApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
@Preview
|
||||||
fun App() {
|
fun App() {
|
||||||
@ -37,7 +41,7 @@ fun AppScaffold() {
|
|||||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
TabNavigator(Projects) {
|
TabNavigator(Projects()) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopBar(drawerState, scope)
|
TopBar(drawerState, scope)
|
||||||
@ -47,10 +51,12 @@ fun AppScaffold() {
|
|||||||
modifier = Modifier.padding(innerPadding)
|
modifier = Modifier.padding(innerPadding)
|
||||||
) {
|
) {
|
||||||
NavigationDrawer(drawerState) {
|
NavigationDrawer(drawerState) {
|
||||||
|
KoinContext {
|
||||||
CurrentTab()
|
CurrentTab()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +120,7 @@ fun NavigationDrawer(
|
|||||||
ModalDrawerSheet {
|
ModalDrawerSheet {
|
||||||
Column(modifier = Modifier.verticalScroll(rememberScrollState()) ) {
|
Column(modifier = Modifier.verticalScroll(rememberScrollState()) ) {
|
||||||
Text("Project Name...", modifier = Modifier.padding(16.dp))
|
Text("Project Name...", modifier = Modifier.padding(16.dp))
|
||||||
TabNavigationItem(Projects)
|
TabNavigationItem(Projects())
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
|
|
||||||
Text("Tester", modifier = Modifier.padding(16.dp))
|
Text("Tester", modifier = Modifier.padding(16.dp))
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package di
|
||||||
|
|
||||||
|
import io.anthonyberg.connector.shared.ProjectTransaction
|
||||||
|
import io.anthonyberg.connector.shared.database.DriverFactory
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import tab.project.ProjectsScreenModel
|
||||||
|
|
||||||
|
fun commonModule() = module {
|
||||||
|
single<DriverFactory> {
|
||||||
|
DriverFactory()
|
||||||
|
}
|
||||||
|
|
||||||
|
single<ProjectTransaction> {
|
||||||
|
ProjectTransaction(driverFactory = get<DriverFactory>())
|
||||||
|
}
|
||||||
|
|
||||||
|
single<ProjectsScreenModel> {
|
||||||
|
ProjectsScreenModel(db = get())
|
||||||
|
}
|
||||||
|
}
|
18
connector/composeApp/src/desktopMain/kotlin/di/KoinInit.kt
Normal file
18
connector/composeApp/src/desktopMain/kotlin/di/KoinInit.kt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package di
|
||||||
|
|
||||||
|
import org.koin.core.Koin
|
||||||
|
import org.koin.core.context.startKoin
|
||||||
|
import org.koin.dsl.KoinAppDeclaration
|
||||||
|
|
||||||
|
class KoinInit {
|
||||||
|
fun init(appDeclaration: KoinAppDeclaration = {}): Koin {
|
||||||
|
return startKoin {
|
||||||
|
modules(
|
||||||
|
listOf(
|
||||||
|
commonModule()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
appDeclaration()
|
||||||
|
}.koin
|
||||||
|
}
|
||||||
|
}
|
@ -3,12 +3,27 @@ import androidx.compose.ui.window.Window
|
|||||||
import androidx.compose.ui.window.application
|
import androidx.compose.ui.window.application
|
||||||
import connector.composeapp.generated.resources.Res
|
import connector.composeapp.generated.resources.Res
|
||||||
import connector.composeapp.generated.resources.rule_24px
|
import connector.composeapp.generated.resources.rule_24px
|
||||||
|
import di.KoinInit
|
||||||
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
||||||
import org.jetbrains.compose.resources.painterResource
|
import org.jetbrains.compose.resources.painterResource
|
||||||
|
import org.koin.core.Koin
|
||||||
|
|
||||||
|
lateinit var koin: Koin
|
||||||
|
|
||||||
@OptIn(ExperimentalResourceApi::class)
|
@OptIn(ExperimentalResourceApi::class)
|
||||||
fun main() = application {
|
fun main() {
|
||||||
Window(onCloseRequest = ::exitApplication, title = "Checklist Tester", icon = painterResource(Res.drawable.rule_24px)) {
|
koin = KoinInit().init()
|
||||||
|
koin.loadModules(
|
||||||
|
listOf(),
|
||||||
|
)
|
||||||
|
|
||||||
|
return application {
|
||||||
|
Window(
|
||||||
|
onCloseRequest = ::exitApplication,
|
||||||
|
title = "Checklist Tester",
|
||||||
|
icon = painterResource(Res.drawable.rule_24px)
|
||||||
|
) {
|
||||||
App()
|
App()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package tab.project
|
||||||
|
|
||||||
|
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||||
|
import cafe.adriel.voyager.core.model.screenModelScope
|
||||||
|
import io.anthonyberg.connector.shared.ProjectTransaction
|
||||||
|
import io.anthonyberg.connector.shared.entity.Project
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class ProjectsScreenModel (
|
||||||
|
private val db: ProjectTransaction
|
||||||
|
) : StateScreenModel<ProjectsScreenModel.State>(State.UnInit) {
|
||||||
|
|
||||||
|
override fun onDispose() {
|
||||||
|
println("Project Disposed")
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class State {
|
||||||
|
object UnInit : State()
|
||||||
|
object Init : State()
|
||||||
|
object Loading : State()
|
||||||
|
data class Result(val projects: List<Project>) : State()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun projectExists() {
|
||||||
|
screenModelScope.launch {
|
||||||
|
mutableState.value = State.Loading
|
||||||
|
delay(5000)
|
||||||
|
val exists = db.projectExists()
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
getProjects()
|
||||||
|
} else {
|
||||||
|
mutableState.value = State.Init
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getProjects() {
|
||||||
|
mutableState.value = State.Loading
|
||||||
|
val projects = db.getProjects()
|
||||||
|
|
||||||
|
mutableState.value = State.Result(projects)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user