Skip to content

Commit

Permalink
Replace Koin with Kotlin inject
Browse files Browse the repository at this point in the history
  • Loading branch information
kirich1409 committed Oct 7, 2024
1 parent d930a99 commit 3b809a2
Show file tree
Hide file tree
Showing 28 changed files with 100 additions and 239 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ android {

packaging {
resources {


excludes += "/META-INF/{AL2.0,LGPL2.1}"
excludes += "/okhttp3/internal/publicsuffix/NOTICE"
excludes += "/kotlin/**"
Expand All @@ -88,7 +90,6 @@ dependencies {
implementation(projects.core.platform)

implementation(projects.composeApp)
implementation(libs.koin.android)
implementation(libs.coil.core)
implementation(projects.core.common)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.androidbroadcast.newssearchapp
import android.app.Application
import coil3.SingletonImageLoader
import dev.androidbroadcast.news.core.NewsAppPlatform
import org.koin.android.ext.koin.androidContext

class NewsApplication @JvmOverloads constructor(
private val platform: NewsAppPlatform = NewsAppPlatform()
Expand All @@ -15,9 +14,7 @@ class NewsApplication @JvmOverloads constructor(
debug = BuildConfig.DEBUG,
newsApiKey = BuildConfig.NEWS_API_KEY,
newsApiBaseUrl = BuildConfig.NEWS_API_BASE_URL,
targetAppDeclaration = {
androidContext(this@NewsApplication)
}
platformContext = this
)
}
}
2 changes: 0 additions & 2 deletions compose-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ kotlin {
jvm()

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
Expand All @@ -39,7 +38,6 @@ kotlin {
implementation(projects.features.newsMain.ui)
implementation(projects.core.common)
implementation(projects.core.uikit)
implementation(libs.koin.compose)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
import dev.androidbroadcast.news.NewsTheme

@Composable
Expand All @@ -19,7 +18,7 @@ internal actual fun NewsPlatformTheme(
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
// WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
}
}
content()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import dev.androidbroadcast.news.NewsTheme
import dev.androidbroadcast.news.main.NewsMainScreen
import org.koin.compose.KoinContext

/**
* Setup theme for platform
Expand All @@ -29,9 +28,7 @@ public fun NewsApp() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
KoinContext {
NewsMainScreen()
}
NewsMainScreen()
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ kotlin {
jvm()

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
Expand All @@ -37,14 +36,13 @@ kotlin {
api(libs.kotlinx.immutable)
api(libs.kotlinx.datetime)
api(libs.coil.core)
api(libs.koin.core)
api(libs.kotlinInject.runtime)
implementation(libs.coil.network.ktor)
}

androidMain.dependencies {
implementation(libs.androidx.core.ktx)
api(libs.kotlinx.coroutines.android)
api(libs.koin.android)
}

jvmMain.dependencies {
Expand Down
1 change: 0 additions & 1 deletion core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ kotlin {
jvm()

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.androidbroadcast.news.data

import dev.androidbroadcast.common.Logger
import dev.androidbroadcast.common.Singleton
import dev.androidbroadcast.news.data.model.Article
import dev.androidbroadcast.news.database.NewsDatabase
import dev.androidbroadcast.news.database.models.ArticleDBO
Expand All @@ -17,7 +18,9 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onEach
import me.tatarka.inject.annotations.Inject

@Inject
public class ArticlesRepository(
private val database: NewsDatabase,
private val api: NewsApi,
Expand Down
2 changes: 0 additions & 2 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ kotlin {
jvm()

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
Expand Down Expand Up @@ -81,7 +80,6 @@ dependencies {
add("kspJvm", libs.androidx.room.compiler)
add("kspAndroid", libs.androidx.room.compiler)
add("kspIosSimulatorArm64", libs.androidx.room.compiler)
add("kspIosX64", libs.androidx.room.compiler)
add("kspIosArm64", libs.androidx.room.compiler)
// add("kspCommonMainMetadata", libs.androidx.room.compiler)
}
1 change: 0 additions & 1 deletion core/opennews-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ kotlin {
jvm()

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
Expand Down
9 changes: 8 additions & 1 deletion core/platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.ksp)
}

kotlin {
Expand All @@ -21,7 +22,6 @@ kotlin {
jvm()

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
Expand Down Expand Up @@ -63,3 +63,10 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}
}

dependencies {
"kspAndroid"(libs.kotlinInject.compiler)
"kspIosArm64"(libs.kotlinInject.compiler)
"kspIosSimulatorArm64"(libs.kotlinInject.compiler)
"kspJvm"(libs.kotlinInject.compiler)
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,54 +1,29 @@
package dev.androidbroadcast.news.core

import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
import org.koin.core.component.KoinComponent
import org.koin.core.component.KoinScopeComponent
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
import org.koin.core.scope.Scope
import org.koin.dsl.KoinAppDeclaration
import dev.androidbroadcast.common.PlatformContext
import kotlin.properties.Delegates.notNull

public class NewsAppPlatform :
KoinComponent,
KoinScopeComponent,
SingletonImageLoader.Factory {
override val scope: Scope
// Root scope id taken from Koin source code
get() = getKoin().getScope("_root_")

public var appComponent: AppComponent by notNull()
private set

public fun start(
debug: Boolean,
newsApiKey: String,
newsApiBaseUrl: String,
targetAppDeclaration: KoinAppDeclaration = {}
platformContext: PlatformContext,
) {
startKoin {
modules(
appKoinModule,
targetKoinModule
)

properties(
mapOf(
ConfigProperties.NewsPlatform.Debug to debug,
ConfigProperties.NewsApi.ApiKey to newsApiKey,
ConfigProperties.NewsApi.BaseUrl to newsApiBaseUrl
)
)

if (debug) {
printLogger(Level.DEBUG)
}

targetAppDeclaration()
}
appComponent = AppComponent.create(
debug, newsApiBaseUrl, newsApiKey,
platformContext
)
}

override fun newImageLoader(context: PlatformContext): ImageLoader =
newImageLoader(
context,
debug = getKoin().getProperty(ConfigProperties.NewsPlatform.Debug, false)
)
override fun newImageLoader(context: coil3.PlatformContext): ImageLoader {
return newImageLoader(context)
}
}

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion core/uikit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ kotlin {
jvm()

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
Expand Down
Loading

0 comments on commit 3b809a2

Please sign in to comment.