Skip to content

Commit

Permalink
migration to koin 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
babichev.a committed Oct 25, 2024
1 parent 508d05b commit 64a9645
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 147 deletions.
1 change: 1 addition & 0 deletions android-compose-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ dependencies {
debugImplementation(compose.uiTooling)
debugImplementation(libs.androidx.compose.test.manifest)
implementation(libs.androidx.navigation.compose)
implementation(platform(libs.koin.bom))
implementation(libs.koin.android)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics)
Expand Down
3 changes: 2 additions & 1 deletion desktop-compose-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ kotlin {
implementation(libs.androidx.navigation.compose)
implementation(libs.coroutines.swing)
implementation(compose.desktop.currentOs)
implementation(libs.koin.core.jvm)
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
}
jvmTest.dependencies {
implementation(project(":jvm-compose-test"))
Expand Down
15 changes: 8 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ androidxSqlite = "2.4.0"
saferoom = "1.3.0"
androidSqlCipher = "4.5.4"
iosSqlCipher = "4.5.4"
koin = "3.5.6"
koin-bom = "4.0.0"
kotlinx-serialization = "1.7.3"
kotlinx-datetime = "0.6.0"
napier = "2.7.1"
Expand Down Expand Up @@ -60,12 +60,13 @@ commonsware-saferoom = { module = "com.commonsware.cwac:saferoom.x", version.ref

android-sqlcipher = { module = "net.zetetic:android-database-sqlcipher", version.ref = "androidSqlCipher" }

koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-core-jvm = { module = "io.insert-koin:koin-core-jvm", version.ref = "koin" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }
koin-test = { module = "io.insert-koin:koin-test", version.ref = "koin" }
koin-test-junit4 = { module = "io.insert-koin:koin-test-junit4", version.ref = "koin" }
koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" }
koin-core = { module = "io.insert-koin:koin-core" }
koin-core-viewmodel = { module = "io.insert-koin:koin-core-viewmodel" }
koin-compose-viewmodel-navigation = { module = "io.insert-koin:koin-compose-viewmodel-navigation" }
koin-android = { module = "io.insert-koin:koin-android" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose" }
koin-test = { module = "io.insert-koin:koin-test" }

kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
Expand Down
2 changes: 2 additions & 0 deletions ios-compose-kit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {
baseName = "iosComposeKit"
isStatic = true
export(project(":shared"))
export(project.dependencies.platform(libs.koin.bom))
export(libs.koin.core)
}
if (!OperatingSystem.current().isMacOsX) noPodspec()
Expand All @@ -35,6 +36,7 @@ kotlin {
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.runtime)
implementation(project.dependencies.platform(libs.koin.bom))
api(libs.koin.core)
}
}
Expand Down
3 changes: 2 additions & 1 deletion jvm-compose-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ dependencies {
implementation(project(":shared-compose-ui"))
implementation(libs.androidx.lifecycle.common)
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.koin.core.jvm)
implementation(platform(libs.koin.bom))
implementation(libs.koin.core)
implementation(libs.turbine)
implementation(compose.desktop.uiTestJUnit4)
implementation(compose.desktop.currentOs)
Expand Down
6 changes: 5 additions & 1 deletion shared-compose-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ kotlin {
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.components.resources)
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
implementation(libs.koin.compose.viewmodel.navigation)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.lifecycle.runtime.compose)
}
androidMain.dependencies {
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.androidx.compose)
}
jvmMain.dependencies {
implementation(libs.koin.core.jvm)
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
}
jvmTest.dependencies {
implementation(kotlin("test"))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.dialog
import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import com.softartdev.notedelight.di.getViewModel
import com.softartdev.notedelight.shared.navigation.AppNavGraph
import com.softartdev.notedelight.shared.navigation.Router
import com.softartdev.notedelight.ui.MainScreen
Expand All @@ -27,6 +26,7 @@ import com.softartdev.notedelight.ui.dialog.security.EnterPasswordDialog
import com.softartdev.theme.material3.PreferableMaterialTheme
import com.softartdev.theme.material3.ThemeDialog
import com.softartdev.theme.pref.PreferenceHelper
import org.koin.compose.viewmodel.koinViewModel

@Composable
fun App(
Expand All @@ -42,22 +42,22 @@ fun App(
startDestination = AppNavGraph.Splash,
) {
composable<AppNavGraph.Splash> {
SplashScreen(splashViewModel = getViewModel())
SplashScreen(splashViewModel = koinViewModel())
}
composable<AppNavGraph.SignIn> {
SignInScreen(signInViewModel = getViewModel())
SignInScreen(signInViewModel = koinViewModel())
}
composable<AppNavGraph.Main> {
MainScreen(mainViewModel = getViewModel())
MainScreen(mainViewModel = koinViewModel())
}
composable<AppNavGraph.Details> { backStackEntry: NavBackStackEntry ->
NoteDetail(
noteViewModel = getViewModel(),
noteViewModel = koinViewModel(),
noteId = backStackEntry.toRoute<AppNavGraph.Details>().noteId,
)
}
composable<AppNavGraph.Settings> {
SettingsScreen(settingsViewModel = getViewModel())
SettingsScreen(settingsViewModel = koinViewModel())
}
dialog<AppNavGraph.ThemeDialog> {
val preferenceHelper: PreferenceHelper = themePrefs.preferenceHelper
Expand All @@ -68,25 +68,25 @@ fun App(
)
}
dialog<AppNavGraph.SaveChangesDialog> {
SaveDialog(saveViewModel = getViewModel())
SaveDialog(saveViewModel = koinViewModel())
}
dialog<AppNavGraph.EditTitleDialog> { backStackEntry: NavBackStackEntry ->
EditTitleDialog(
noteId = backStackEntry.toRoute<AppNavGraph.EditTitleDialog>().noteId,
editTitleViewModel = getViewModel()
editTitleViewModel = koinViewModel()
)
}
dialog<AppNavGraph.DeleteNoteDialog> {
DeleteDialog(deleteViewModel = getViewModel())
DeleteDialog(deleteViewModel = koinViewModel())
}
dialog<AppNavGraph.EnterPasswordDialog> {
EnterPasswordDialog(enterViewModel = getViewModel())
EnterPasswordDialog(enterViewModel = koinViewModel())
}
dialog<AppNavGraph.ConfirmPasswordDialog> {
ConfirmPasswordDialog(confirmViewModel = getViewModel())
ConfirmPasswordDialog(confirmViewModel = koinViewModel())
}
dialog<AppNavGraph.ChangePasswordDialog> {
ChangePasswordDialog(changeViewModel = getViewModel())
ChangePasswordDialog(changeViewModel = koinViewModel())
}
dialog<AppNavGraph.ErrorDialog> { backStackEntry: NavBackStackEntry ->
ErrorDialog(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 13 additions & 12 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ kotlin {
implementation(libs.sqlDelight.coroutinesExt)
api(libs.kotlinx.datetime)
api(libs.napier)
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
implementation(libs.koin.core.viewmodel)
api(libs.material.theme.prefs)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.kotlinx.serialization.json)
Expand All @@ -73,6 +75,7 @@ kotlin {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation(libs.coroutines.test)
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.test)
}
androidMain.dependencies {
Expand All @@ -82,21 +85,19 @@ kotlin {
api(libs.commonsware.saferoom)
api(libs.android.sqlcipher)
api(libs.androidx.lifecycle.viewmodel)
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.android)
implementation(libs.espresso.idling.resource)
}
val androidUnitTest by getting {
dependsOn(commonTest.get())
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation(libs.junit)
implementation(libs.coroutines.test)
implementation(libs.bundles.mockito)
implementation(libs.sqlDelight.jvm)
implementation(libs.androidx.arch.core.testing)
implementation(libs.turbine)
}
androidUnitTest.dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation(libs.junit)
implementation(libs.coroutines.test)
implementation(libs.bundles.mockito)
implementation(libs.sqlDelight.jvm)
implementation(libs.androidx.arch.core.testing)
implementation(libs.turbine)
}
iosMain.dependencies {
implementation(libs.sqlDelight.native)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.softartdev.notedelight.shared.di
import com.softartdev.notedelight.shared.db.AndroidSafeRepo
import com.softartdev.notedelight.shared.db.SafeRepo
import org.koin.core.module.Module
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
import org.koin.dsl.module

actual val repoModule: Module = module {
single<SafeRepo> { AndroidSafeRepo(get()) }
singleOf(::AndroidSafeRepo) bind SafeRepo::class
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.softartdev.notedelight.shared.usecase.note.DeleteNoteUseCase
import com.softartdev.notedelight.shared.usecase.note.SaveNoteUseCase
import com.softartdev.notedelight.shared.usecase.note.UpdateTitleUseCase
import org.koin.core.module.Module
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.viewModelOf
import org.koin.dsl.module

val sharedModules: List<Module>
Expand All @@ -35,25 +37,25 @@ val daoModule: Module = module {
}

val useCaseModule: Module = module {
factory { ChangePasswordUseCase(get()) }
factory { CheckPasswordUseCase(get()) }
factory { CheckSqlCipherVersionUseCase(get()) }
factory { CreateNoteUseCase(get()) }
factory { SaveNoteUseCase(get()) }
factory { DeleteNoteUseCase(get()) }
factory { UpdateTitleUseCase(get()) }
factoryOf(::ChangePasswordUseCase)
factoryOf(::CheckPasswordUseCase)
factoryOf(::CheckSqlCipherVersionUseCase)
factoryOf(::CreateNoteUseCase)
factoryOf(::SaveNoteUseCase)
factoryOf(::DeleteNoteUseCase)
factoryOf(::UpdateTitleUseCase)
}

val viewModelModule: Module = module {
viewModelFactory { SplashViewModel(get(), get()) }
viewModelFactory { SignInViewModel(get(), get()) }
viewModelFactory { MainViewModel(get(), get(), get()) }
viewModelFactory { NoteViewModel(get(), get(), get(), get(), get(), get()) }
viewModelFactory { SaveViewModel(get(), get()) }
viewModelFactory { DeleteViewModel(get()) }
viewModelFactory { EditTitleViewModel(get(), get(), get()) }
viewModelFactory { SettingsViewModel(get(), get(), get()) }
viewModelFactory { EnterViewModel(get(), get(), get(), get()) }
viewModelFactory { ConfirmViewModel(get(), get(), get()) }
viewModelFactory { ChangeViewModel(get(), get(), get(), get()) }
viewModelOf(::SplashViewModel)
viewModelOf(::SignInViewModel)
viewModelOf(::MainViewModel)
viewModelOf(::NoteViewModel)
viewModelOf(::SaveViewModel)
viewModelOf(::DeleteViewModel)
viewModelOf(::EditTitleViewModel)
viewModelOf(::SettingsViewModel)
viewModelOf(::EnterViewModel)
viewModelOf(::ConfirmViewModel)
viewModelOf(::ChangeViewModel)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.softartdev.notedelight.shared.di
import com.softartdev.notedelight.shared.db.IosSafeRepo
import com.softartdev.notedelight.shared.db.SafeRepo
import org.koin.core.module.Module
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
import org.koin.dsl.module

actual val repoModule: Module = module {
single<SafeRepo> { IosSafeRepo() }
singleOf(::IosSafeRepo) bind SafeRepo::class
}
Loading

0 comments on commit 64a9645

Please sign in to comment.