diff --git a/androidApp/src/androidMain/kotlin/com/mbakgun/mj/App.kt b/androidApp/src/androidMain/kotlin/com/mbakgun/mj/App.kt index b5c82a4..70e76da 100644 --- a/androidApp/src/androidMain/kotlin/com/mbakgun/mj/App.kt +++ b/androidApp/src/androidMain/kotlin/com/mbakgun/mj/App.kt @@ -1,7 +1,6 @@ package com.mbakgun.mj import android.app.Application -import com.mbakgun.mj.di.viewModelModule import di.initKoin import org.koin.android.ext.koin.androidContext @@ -11,7 +10,6 @@ class App : Application() { super.onCreate() initKoin { androidContext(this@App) - modules(viewModelModule) } } } diff --git a/androidApp/src/androidMain/kotlin/com/mbakgun/mj/di/ViewModelModule.kt b/androidApp/src/androidMain/kotlin/com/mbakgun/mj/di/ViewModelModule.kt deleted file mode 100644 index f61ce8d..0000000 --- a/androidApp/src/androidMain/kotlin/com/mbakgun/mj/di/ViewModelModule.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.mbakgun.mj.di - -import org.koin.core.module.dsl.viewModelOf -import org.koin.dsl.module -import ui.MjImagesViewModel - -val viewModelModule = module { - viewModelOf(::MjImagesViewModel) -} diff --git a/androidApp/src/androidMain/kotlin/com/mbakgun/mj/ui/MainActivity.kt b/androidApp/src/androidMain/kotlin/com/mbakgun/mj/ui/MainActivity.kt index 37d2b97..fba594f 100644 --- a/androidApp/src/androidMain/kotlin/com/mbakgun/mj/ui/MainActivity.kt +++ b/androidApp/src/androidMain/kotlin/com/mbakgun/mj/ui/MainActivity.kt @@ -3,7 +3,6 @@ package com.mbakgun.mj.ui import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import org.koin.android.ext.android.get import ui.MjImagesApp class MainActivity : AppCompatActivity() { @@ -15,9 +14,7 @@ class MainActivity : AppCompatActivity() { private fun setComposable() { setContent { - MjImagesApp( - viewModel = get() - ) + MjImagesApp() } } } diff --git a/automotiveApp/src/main/java/com/mbakgun/mj/App.kt b/automotiveApp/src/main/java/com/mbakgun/mj/App.kt index b5c82a4..70e76da 100644 --- a/automotiveApp/src/main/java/com/mbakgun/mj/App.kt +++ b/automotiveApp/src/main/java/com/mbakgun/mj/App.kt @@ -1,7 +1,6 @@ package com.mbakgun.mj import android.app.Application -import com.mbakgun.mj.di.viewModelModule import di.initKoin import org.koin.android.ext.koin.androidContext @@ -11,7 +10,6 @@ class App : Application() { super.onCreate() initKoin { androidContext(this@App) - modules(viewModelModule) } } } diff --git a/automotiveApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt b/automotiveApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt deleted file mode 100644 index f61ce8d..0000000 --- a/automotiveApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.mbakgun.mj.di - -import org.koin.core.module.dsl.viewModelOf -import org.koin.dsl.module -import ui.MjImagesViewModel - -val viewModelModule = module { - viewModelOf(::MjImagesViewModel) -} diff --git a/automotiveApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt b/automotiveApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt index 37d2b97..fba594f 100644 --- a/automotiveApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt +++ b/automotiveApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt @@ -3,7 +3,6 @@ package com.mbakgun.mj.ui import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import org.koin.android.ext.android.get import ui.MjImagesApp class MainActivity : AppCompatActivity() { @@ -15,9 +14,7 @@ class MainActivity : AppCompatActivity() { private fun setComposable() { setContent { - MjImagesApp( - viewModel = get() - ) + MjImagesApp() } } } diff --git a/desktopApp/src/jvmMain/kotlin/com/mbakgun/mj/Main.kt b/desktopApp/src/jvmMain/kotlin/com/mbakgun/mj/Main.kt index aa10a68..5586fc6 100644 --- a/desktopApp/src/jvmMain/kotlin/com/mbakgun/mj/Main.kt +++ b/desktopApp/src/jvmMain/kotlin/com/mbakgun/mj/Main.kt @@ -3,25 +3,18 @@ package com.mbakgun.mj import androidx.compose.ui.window.Window import androidx.compose.ui.window.application import di.initKoin -import domain.usecase.MjImagesFetchUseCase -import domain.usecase.MjImagesUseCase -import org.koin.java.KoinJavaComponent.inject import ui.MjImagesApp -import ui.MjImagesViewModel fun main() { System.setProperty("apple.awt.application.appearance", "system") - initKoin { } - val fetchUseCase by inject(MjImagesFetchUseCase::class.java) - val useCase by inject(MjImagesUseCase::class.java) - val viewModel = MjImagesViewModel(fetchUseCase, useCase) + initKoin() application { Window( onCloseRequest = ::exitApplication, title = "MjImages", ) { - MjImagesApp(viewModel) + MjImagesApp() } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 37ca6b2..6695a91 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,8 @@ coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil3" coil-compose-core = { module = "io.coil-kt.coil3:coil-compose-core", version.ref = "coil3" } coil-network-ktor = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coil3" } coil-mp = { module = "io.coil-kt.coil3:coil", version.ref = "coil3" } -koin = { module = "io.insert-koin:koin-android", version.ref="koin" } +koinAndroid = { module = "io.insert-koin:koin-android", version.ref="koin" } +koinComposeViewmodel = { module = "io.insert-koin:koin-compose-viewmodel", version.ref = "koin" } koinCore = { module = "io.insert-koin:koin-core", version.ref="koin" } koinTest = { module = "io.insert-koin:koin-test", version.ref="koin" } ktorClient = { module = "io.ktor:ktor-client-android", version.ref="ktorClient" } diff --git a/iosApp/iosApp/ContentView.swift b/iosApp/iosApp/ContentView.swift index ee64109..18e0379 100644 --- a/iosApp/iosApp/ContentView.swift +++ b/iosApp/iosApp/ContentView.swift @@ -5,18 +5,13 @@ import shared struct ComposeView: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> UIViewController { - let viewModel = MjImagesViewModel.init( - fetchUseCase: MjImagesFetchUseCase.init(), - useCase: MjImagesUseCase.init() - ) - return Main_iosKt.MainViewController(viewModel: viewModel) + return Main_iosKt.MainViewController() } func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} } struct ContentView: View { - init() { KoinModuleKt.doInitKoin() } diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index c80f602..d600204 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -54,6 +54,7 @@ kotlin { //di api(libs.koinCore) + api(libs.koinComposeViewmodel) //network implementation(libs.ktorClientCore) @@ -77,7 +78,7 @@ kotlin { } androidMain.dependencies { - api(libs.koin) + api(libs.koinAndroid) implementation(libs.ktorClient) implementation(libs.lifecycle.runtime.android) } diff --git a/shared/detekt-baseline.xml b/shared/detekt-baseline.xml index 19687c9..b0c5049 100644 --- a/shared/detekt-baseline.xml +++ b/shared/detekt-baseline.xml @@ -11,13 +11,13 @@ FunctionNaming:MjImagesApp.kt$@Composable fun PreviewDialog( hqImageUrl: String, onDismissed: () -> Unit, ) FunctionNaming:MjImagesApp.kt$@Composable fun PreviewImage(hqImageUrl: String) FunctionNaming:MjImagesApp.kt$@Composable fun ScrollToTopButton( onClick: () -> Unit, modifier: Modifier = Modifier ) - FunctionNaming:MjImagesApp.kt$@OptIn(ExperimentalMaterialApi::class) @Composable fun MjImagesApp( viewModel: MjImagesViewModel ) + FunctionNaming:MjImagesApp.kt$@OptIn(ExperimentalMaterialApi::class) @Composable fun MjImagesApp( viewModel: MjImagesViewModel = koinViewModel<MjImagesViewModel>() ) FunctionNaming:String0.commonMain.kt$@InternalResourceApi internal fun _collectCommonMainString0Resources(map: MutableMap<String, StringResource>) FunctionNaming:String0.commonMain.kt$private fun init_failed_fetch_message(): StringResource FunctionNaming:String0.commonMain.kt$private fun init_snack_message(): StringResource FunctionNaming:Theme.kt$@Composable fun AppTheme( useDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit ) - FunctionNaming:main.ios.kt$fun MainViewController(viewModel: MjImagesViewModel): UIViewController - LongMethod:MjImagesApp.kt$@OptIn(ExperimentalMaterialApi::class) @Composable fun MjImagesApp( viewModel: MjImagesViewModel ) + FunctionNaming:main.ios.kt$fun MainViewController(): UIViewController + LongMethod:MjImagesApp.kt$@OptIn(ExperimentalMaterialApi::class) @Composable fun MjImagesApp( viewModel: MjImagesViewModel = koinViewModel<MjImagesViewModel>() ) MagicNumber:Colors.kt$0xFF1F1B16 MagicNumber:Colors.kt$0xFF3E2D16 MagicNumber:Colors.kt$0xFF452B00 diff --git a/shared/src/commonMain/kotlin/di/KoinModule.kt b/shared/src/commonMain/kotlin/di/KoinModule.kt index 822c5f9..0d66fd4 100644 --- a/shared/src/commonMain/kotlin/di/KoinModule.kt +++ b/shared/src/commonMain/kotlin/di/KoinModule.kt @@ -10,8 +10,10 @@ import domain.mapper.MjImagesMapper import domain.usecase.MjImagesFetchUseCase import domain.usecase.MjImagesUseCase import org.koin.core.context.startKoin +import org.koin.core.module.dsl.viewModelOf import org.koin.dsl.KoinAppDeclaration import org.koin.dsl.module +import ui.MjImagesViewModel import util.getDispatcherProvider private val utilityModule = module { @@ -35,7 +37,12 @@ private val useCaseModule = module { factory { MjImagesUseCase() } } -private val sharedModules = listOf(useCaseModule, repositoryModule, apiModule, utilityModule) +private val uiModule = module { + viewModelOf(::MjImagesViewModel) +} + +private val sharedModules = + listOf(uiModule, useCaseModule, repositoryModule, apiModule, utilityModule) fun initKoin(appDeclaration: KoinAppDeclaration) = startKoin { modules(sharedModules) diff --git a/shared/src/commonMain/kotlin/ui/MjImagesApp.kt b/shared/src/commonMain/kotlin/ui/MjImagesApp.kt index 72fc0a4..4eba828 100644 --- a/shared/src/commonMain/kotlin/ui/MjImagesApp.kt +++ b/shared/src/commonMain/kotlin/ui/MjImagesApp.kt @@ -88,6 +88,7 @@ import kotlinx.coroutines.launch import midjourneyimagescomposemultiplatform.shared.generated.resources.Res import midjourneyimagescomposemultiplatform.shared.generated.resources.snack_message import org.jetbrains.compose.resources.getString +import org.koin.compose.viewmodel.koinViewModel import ui.theme.AppTheme import util.OnBottomReached import util.getAsyncImageLoader @@ -96,7 +97,7 @@ import util.getImageProvider @OptIn(ExperimentalMaterialApi::class) @Composable fun MjImagesApp( - viewModel: MjImagesViewModel + viewModel: MjImagesViewModel = koinViewModel() ) { setSingletonImageLoaderFactory { context -> getAsyncImageLoader(context) diff --git a/shared/src/iosMain/kotlin/main.ios.kt b/shared/src/iosMain/kotlin/main.ios.kt index 12b500a..dd2f67a 100644 --- a/shared/src/iosMain/kotlin/main.ios.kt +++ b/shared/src/iosMain/kotlin/main.ios.kt @@ -1,9 +1,8 @@ import androidx.compose.ui.window.ComposeUIViewController import platform.UIKit.UIViewController import ui.MjImagesApp -import ui.MjImagesViewModel -fun MainViewController(viewModel: MjImagesViewModel): UIViewController = +fun MainViewController(): UIViewController = ComposeUIViewController { - MjImagesApp(viewModel) + MjImagesApp() } diff --git a/televisionApp/src/main/java/com/mbakgun/mj/App.kt b/televisionApp/src/main/java/com/mbakgun/mj/App.kt index b5c82a4..70e76da 100644 --- a/televisionApp/src/main/java/com/mbakgun/mj/App.kt +++ b/televisionApp/src/main/java/com/mbakgun/mj/App.kt @@ -1,7 +1,6 @@ package com.mbakgun.mj import android.app.Application -import com.mbakgun.mj.di.viewModelModule import di.initKoin import org.koin.android.ext.koin.androidContext @@ -11,7 +10,6 @@ class App : Application() { super.onCreate() initKoin { androidContext(this@App) - modules(viewModelModule) } } } diff --git a/televisionApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt b/televisionApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt deleted file mode 100644 index f61ce8d..0000000 --- a/televisionApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.mbakgun.mj.di - -import org.koin.core.module.dsl.viewModelOf -import org.koin.dsl.module -import ui.MjImagesViewModel - -val viewModelModule = module { - viewModelOf(::MjImagesViewModel) -} diff --git a/televisionApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt b/televisionApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt index 37d2b97..fba594f 100644 --- a/televisionApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt +++ b/televisionApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt @@ -3,7 +3,6 @@ package com.mbakgun.mj.ui import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import org.koin.android.ext.android.get import ui.MjImagesApp class MainActivity : AppCompatActivity() { @@ -15,9 +14,7 @@ class MainActivity : AppCompatActivity() { private fun setComposable() { setContent { - MjImagesApp( - viewModel = get() - ) + MjImagesApp() } } } diff --git a/wasmApp/src/wasmJsMain/kotlin/com/mbakgun/mj/Main.kt b/wasmApp/src/wasmJsMain/kotlin/com/mbakgun/mj/Main.kt index 26f5f48..edd7c61 100644 --- a/wasmApp/src/wasmJsMain/kotlin/com/mbakgun/mj/Main.kt +++ b/wasmApp/src/wasmJsMain/kotlin/com/mbakgun/mj/Main.kt @@ -3,21 +3,15 @@ package com.mbakgun.mj import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.window.CanvasBasedWindow import di.initKoin -import domain.usecase.MjImagesFetchUseCase -import domain.usecase.MjImagesUseCase import kotlinx.browser.document import ui.MjImagesApp -import ui.MjImagesViewModel @OptIn(ExperimentalComposeUiApi::class) fun main() { - val koin = initKoin { }.koin - val fetchUseCase = koin.get() - val useCase = koin.get() - val viewModel = MjImagesViewModel(fetchUseCase, useCase) + initKoin() CanvasBasedWindow("MjImagesApp") { - MjImagesApp(viewModel) + MjImagesApp() } document.getElementById("loader-container")?.remove() } diff --git a/wearApp/src/main/java/com/mbakgun/mj/App.kt b/wearApp/src/main/java/com/mbakgun/mj/App.kt index b5c82a4..70e76da 100644 --- a/wearApp/src/main/java/com/mbakgun/mj/App.kt +++ b/wearApp/src/main/java/com/mbakgun/mj/App.kt @@ -1,7 +1,6 @@ package com.mbakgun.mj import android.app.Application -import com.mbakgun.mj.di.viewModelModule import di.initKoin import org.koin.android.ext.koin.androidContext @@ -11,7 +10,6 @@ class App : Application() { super.onCreate() initKoin { androidContext(this@App) - modules(viewModelModule) } } } diff --git a/wearApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt b/wearApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt deleted file mode 100644 index f61ce8d..0000000 --- a/wearApp/src/main/java/com/mbakgun/mj/di/ViewModelModule.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.mbakgun.mj.di - -import org.koin.core.module.dsl.viewModelOf -import org.koin.dsl.module -import ui.MjImagesViewModel - -val viewModelModule = module { - viewModelOf(::MjImagesViewModel) -} diff --git a/wearApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt b/wearApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt index 37d2b97..fba594f 100644 --- a/wearApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt +++ b/wearApp/src/main/java/com/mbakgun/mj/ui/MainActivity.kt @@ -3,7 +3,6 @@ package com.mbakgun.mj.ui import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import org.koin.android.ext.android.get import ui.MjImagesApp class MainActivity : AppCompatActivity() { @@ -15,9 +14,7 @@ class MainActivity : AppCompatActivity() { private fun setComposable() { setContent { - MjImagesApp( - viewModel = get() - ) + MjImagesApp() } } } diff --git a/webApp/src/jsMain/kotlin/com/mbakgun/mj/Main.kt b/webApp/src/jsMain/kotlin/com/mbakgun/mj/Main.kt index 4627f46..13f98a0 100644 --- a/webApp/src/jsMain/kotlin/com/mbakgun/mj/Main.kt +++ b/webApp/src/jsMain/kotlin/com/mbakgun/mj/Main.kt @@ -3,23 +3,16 @@ package com.mbakgun.mj import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.window.CanvasBasedWindow import di.initKoin -import domain.usecase.MjImagesFetchUseCase -import domain.usecase.MjImagesUseCase import kotlinx.browser.document import org.jetbrains.skiko.wasm.onWasmReady import ui.MjImagesApp -import ui.MjImagesViewModel @OptIn(ExperimentalComposeUiApi::class) fun main() { - val koin = initKoin { }.koin - val fetchUseCase = koin.get() - val useCase = koin.get() - val viewModel = MjImagesViewModel(fetchUseCase, useCase) - + initKoin() onWasmReady { CanvasBasedWindow("MjImagesApp") { - MjImagesApp(viewModel) + MjImagesApp() } document.getElementById("loader-container")?.remove() }