diff --git a/core/common/build.gradle.kts b/core/common/build.gradle.kts
index b02024487..dfa028b85 100644
--- a/core/common/build.gradle.kts
+++ b/core/common/build.gradle.kts
@@ -15,7 +15,7 @@
*/
plugins {
alias(libs.plugins.nowinandroid.kmp.library)
- alias(libs.plugins.nowinandroid.kotlin.inject)
+ alias(libs.plugins.nowinandroid.di.koin)
alias(libs.plugins.nowinandroid.android.library.jacoco)
}
diff --git a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidDispatchersComponent.kt b/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidDispatchersComponent.kt
deleted file mode 100644
index 8c4aaf877..000000000
--- a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidDispatchersComponent.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.samples.apps.nowinandroid.core.di
-
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.DEFAULT
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.IO
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.MAIN
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.Dispatchers
-import me.tatarka.inject.annotations.Component
-import me.tatarka.inject.annotations.Provides
-
-@Component
-abstract class AndroidDispatchersComponent : DispatchersComponent() {
- @Provides
- override fun providesIODispatcher():
- @Dispatcher(IO)
- CoroutineDispatcher = Dispatchers.IO
-
- @Provides
- override fun providesDefaultDispatcher():
- @Dispatcher(DEFAULT)
- CoroutineDispatcher =
- Dispatchers.Default
-
- @Provides
- override fun providesMainDispatcher():
- @Dispatcher(MAIN)
- CoroutineDispatcher = Dispatchers.Main
-}
diff --git a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidPlatformContextProvider.kt b/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
similarity index 77%
rename from core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidPlatformContextProvider.kt
rename to core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
index e96aa74e7..4d1fae22b 100644
--- a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidPlatformContextProvider.kt
+++ b/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
@@ -18,9 +18,13 @@ package com.google.samples.apps.nowinandroid.core.di
import android.content.Context
import coil3.PlatformContext
-import me.tatarka.inject.annotations.Inject
+import org.koin.core.annotation.Single
-@Inject
-class AndroidPlatformContextProvider(private val context: Context) : PlatformContextProvider {
- override val platformContext: PlatformContext get() = context
-}
+@Single
+actual class PlatformContextProvider(
+ val context: Context,
+) {
+ actual fun getPlatformContext(): PlatformContext {
+ return context
+ }
+}
\ No newline at end of file
diff --git a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidApplicationComponent.kt b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CommonModule.kt
similarity index 69%
rename from core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidApplicationComponent.kt
rename to core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CommonModule.kt
index 1d5b08309..28784a280 100644
--- a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/AndroidApplicationComponent.kt
+++ b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CommonModule.kt
@@ -16,12 +16,17 @@
package com.google.samples.apps.nowinandroid.core.di
-import android.app.Application
-import me.tatarka.inject.annotations.Component
-import me.tatarka.inject.annotations.Provides
+import org.koin.core.annotation.ComponentScan
+import org.koin.core.annotation.Module
+import org.koin.ksp.generated.module
-@Component
-@ApplicationScope
-abstract class AndroidApplicationComponent(
- @get:Provides val application: Application,
+fun commonModule() = listOf(
+ CommonModule().module,
+ coroutineDispatcherModule,
+ coroutineScopeModule,
+ imageLoaderModule,
)
+
+@Module
+@ComponentScan
+class CommonModule
diff --git a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformComponent.kt b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineDispatcherModule.kt
similarity index 66%
rename from core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformComponent.kt
rename to core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineDispatcherModule.kt
index 118d643c1..fd36210bc 100644
--- a/core/common/src/androidMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformComponent.kt
+++ b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineDispatcherModule.kt
@@ -16,11 +16,13 @@
package com.google.samples.apps.nowinandroid.core.di
-import android.app.Application
-import coil3.PlatformContext
-import me.tatarka.inject.annotations.Provides
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.IO
+import org.koin.core.qualifier.named
+import org.koin.dsl.module
-interface PlatformComponent {
- @Provides
- fun providePlatformContext(application: Application): PlatformContext = application
+val coroutineDispatcherModule = module {
+ single(named("IoDispatcher")) { Dispatchers.IO }
+ single(named("DefaultDispatcher")) { Dispatchers.Default }
+ single(named("MainDispatcher")) { Dispatchers.Main }
}
diff --git a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineScopeComponent.kt b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineScopeModule.kt
similarity index 70%
rename from core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineScopeComponent.kt
rename to core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineScopeModule.kt
index afe01ee99..a7ab13efc 100644
--- a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineScopeComponent.kt
+++ b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/CoroutineScopeModule.kt
@@ -16,13 +16,12 @@
package com.google.samples.apps.nowinandroid.core.di
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.DEFAULT
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
-import me.tatarka.inject.annotations.Component
-import me.tatarka.inject.annotations.Provides
import me.tatarka.inject.annotations.Scope
+import org.koin.core.qualifier.named
+import org.koin.dsl.module
/**
* The application-level scope. There will only be one instance of anything annotated with this.
@@ -30,14 +29,9 @@ import me.tatarka.inject.annotations.Scope
@Scope
annotation class ApplicationScope
-@Component
-abstract class CoroutineScopeComponent(
- @Component val dispatchersComponent: DispatchersComponent,
-) {
- @Dispatcher(DEFAULT)
- abstract val dispatcher: CoroutineDispatcher
-
- @Provides
- fun providesCoroutineScope(): CoroutineScope =
+val coroutineScopeModule = module {
+ single {
+ val dispatcher: CoroutineDispatcher = get(named("DefaultDispatcher"))
CoroutineScope(SupervisorJob() + dispatcher)
-}
+ }
+}
\ No newline at end of file
diff --git a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/DispatchersComponent.kt b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/DispatchersComponent.kt
deleted file mode 100644
index 60f5782e4..000000000
--- a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/DispatchersComponent.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.samples.apps.nowinandroid.core.di
-
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.DEFAULT
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.IO
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.MAIN
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.IO
-import me.tatarka.inject.annotations.Provides
-
-abstract class DispatchersComponent {
- @Provides
- abstract fun providesIODispatcher():
- @Dispatcher(IO)
- CoroutineDispatcher
-
- @Provides
- abstract fun providesDefaultDispatcher():
- @Dispatcher(DEFAULT)
- CoroutineDispatcher
-
- @Provides
- abstract fun providesMainDispatcher():
- @Dispatcher(MAIN)
- CoroutineDispatcher
-}
diff --git a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/ImageLoaderComponent.kt b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/ImageLoaderComponent.kt
index 0888d567f..81859fd50 100644
--- a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/ImageLoaderComponent.kt
+++ b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/ImageLoaderComponent.kt
@@ -21,27 +21,16 @@ import coil3.PlatformContext
import coil3.memory.MemoryCache
import coil3.request.crossfade
import coil3.util.DebugLogger
-import me.tatarka.inject.annotations.Component
-import me.tatarka.inject.annotations.Provides
+import org.koin.dsl.module
-@Component
-abstract class ImageLoaderComponent {
- /**
- * Since we're displaying SVGs in the app, Coil needs an ImageLoader which supports this
- * format. During Coil's initialization it will call `applicationContext.newImageLoader()` to
- * obtain an ImageLoader.
- *
- * @see Coil
- */
- @Provides
- fun provideImageLoader(
- context: PlatformContext,
- ): ImageLoader {
- return ImageLoader.Builder(context)
+val imageLoaderModule = module {
+ single {
+ val platformContext: PlatformContext = get()
+ ImageLoader.Builder(platformContext)
.memoryCache {
MemoryCache.Builder()
// Set the max size to 25% of the app's available memory.
- .maxSizePercent(context, percent = 0.25)
+ .maxSizePercent(platformContext, percent = 0.25)
.build()
}
// Show a short crossfade when loading images asynchronously.
diff --git a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
index 3a07c9c18..582e739dd 100644
--- a/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
+++ b/core/common/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
@@ -18,6 +18,6 @@ package com.google.samples.apps.nowinandroid.core.di
import coil3.PlatformContext
-interface PlatformContextProvider {
- val platformContext: PlatformContext
+expect class PlatformContextProvider {
+ fun getPlatformContext(): PlatformContext
}
diff --git a/core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/JvmDispatchersComponent.kt b/core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/JvmDispatchersComponent.kt
deleted file mode 100644
index 08ac30090..000000000
--- a/core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/JvmDispatchersComponent.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.samples.apps.nowinandroid.core.di
-
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.DEFAULT
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.IO
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.MAIN
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.Dispatchers
-import me.tatarka.inject.annotations.Component
-import me.tatarka.inject.annotations.Provides
-
-@Component
-abstract class JvmDispatchersComponent : DispatchersComponent() {
- @Provides
- override fun providesIODispatcher():
- @Dispatcher(IO)
- CoroutineDispatcher = Dispatchers.IO
-
- @Provides
- override fun providesDefaultDispatcher():
- @Dispatcher(DEFAULT)
- CoroutineDispatcher = Dispatchers.Default
-
- @Provides
- override fun providesMainDispatcher():
- @Dispatcher(MAIN)
- CoroutineDispatcher = Dispatchers.Main
-}
diff --git a/core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/NativePlatformContextProvider.kt b/core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
similarity index 80%
rename from core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/NativePlatformContextProvider.kt
rename to core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
index 925acb997..a26c879c3 100644
--- a/core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/NativePlatformContextProvider.kt
+++ b/core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
@@ -17,8 +17,9 @@
package com.google.samples.apps.nowinandroid.core.di
import coil3.PlatformContext
+import org.koin.core.annotation.Single
-class NativePlatformContextProvider : PlatformContextProvider {
- override val platformContext: PlatformContext
- get() = PlatformContext.INSTANCE
+@Single
+actual class PlatformContextProvider {
+ actual fun getPlatformContext(): PlatformContext = PlatformContext.INSTANCE
}
diff --git a/core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/NativeDispatchersComponent.kt b/core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/NativeDispatchersComponent.kt
deleted file mode 100644
index dde117d16..000000000
--- a/core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/NativeDispatchersComponent.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.samples.apps.nowinandroid.core.di
-
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.DEFAULT
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.IO
-import com.google.samples.apps.nowinandroid.core.di.NiaDispatchers.MAIN
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import me.tatarka.inject.annotations.Component
-import me.tatarka.inject.annotations.Provides
-
-@Component
-abstract class NativeDispatchersComponent : DispatchersComponent() {
- @Provides
- override fun providesIODispatcher():
- @Dispatcher(IO)
- CoroutineDispatcher = Dispatchers.IO
-
- @Provides
- override fun providesDefaultDispatcher():
- @Dispatcher(DEFAULT)
- CoroutineDispatcher =
- Dispatchers.Default
-
- @Provides
- override fun providesMainDispatcher():
- @Dispatcher(MAIN)
- CoroutineDispatcher = Dispatchers.Main
-}
diff --git a/core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/JvmPlatformContextProvider.kt b/core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
similarity index 80%
rename from core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/JvmPlatformContextProvider.kt
rename to core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
index 99850386c..a26c879c3 100644
--- a/core/common/src/jvmMain/kotlin/com/google/samples/apps/nowinandroid/core/di/JvmPlatformContextProvider.kt
+++ b/core/common/src/nativeMain/kotlin/com/google/samples/apps/nowinandroid/core/di/PlatformContextProvider.kt
@@ -17,8 +17,9 @@
package com.google.samples.apps.nowinandroid.core.di
import coil3.PlatformContext
+import org.koin.core.annotation.Single
-class JvmPlatformContextProvider : PlatformContextProvider {
- override val platformContext: PlatformContext
- get() = PlatformContext.INSTANCE
+@Single
+actual class PlatformContextProvider {
+ actual fun getPlatformContext(): PlatformContext = PlatformContext.INSTANCE
}
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index fd519d909..5e273d01f 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -2,7 +2,7 @@
accompanist = "0.36.0"
androidDesugarJdkLibs = "2.1.2"
# AGP and tools should be updated together
-androidGradlePlugin = "8.6.1"
+androidGradlePlugin = "8.7.0"
androidTools = "31.7.0"
androidxActivity = "1.9.2"
androidxAppCompat = "1.7.0"
@@ -146,7 +146,7 @@ hilt-ext-work = { group = "androidx.hilt", name = "hilt-work", version.ref = "hi
javax-inject = { module = "javax.inject:javax.inject", version = "1" }
koin-annotations-bom = { group = "io.insert-koin", name = "koin-annotations-bom", version.ref = "koin-annotations" }
koin-annotations = { group = "io.insert-koin", name = "koin-annotations" }
-koin-ksp-compiler = { group = "io.insert-koin", name = "koin-ksp-compiler" }
+koin-ksp-compiler = { group = "io.insert-koin", name = "koin-ksp-compiler", version.ref = "koin-annotations" }
koin-bom = { group = "io.insert-koin", name = "koin-bom", version.ref = "koin" }
koin-android = { group = "io.insert-koin", name = "koin-android"}
koin-core = { group = "io.insert-koin", name = "koin-core"}