Skip to content

Commit

Permalink
Hilt to Koin
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Mar 27, 2024
1 parent 4b03836 commit 610f227
Show file tree
Hide file tree
Showing 326 changed files with 1,334 additions and 1,876 deletions.
2 changes: 1 addition & 1 deletion androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.androidx.navigation.safeargs)
alias(libs.plugins.palantir.git)
id("movies-android-hilt")
}

val gitCommitsCount by lazy {
Expand Down Expand Up @@ -188,6 +187,7 @@ dependencies {
implementation(project(":feature:search-kmp"))
implementation(project(":feature:settings-kmp"))
implementation(libs.kotlin.reflect)
implementation(libs.bundles.koin.android)
testImplementation(libs.junit)
androidTestImplementation(libs.bundles.androidx.test.espresso)
androidTestImplementation(libs.androidx.test.ext.junit.ktx)
Expand Down
25 changes: 17 additions & 8 deletions androidApp/src/main/kotlin/org/michaelbel/movies/App.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
package org.michaelbel.movies

import android.app.Application
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import org.michaelbel.movies.common_kmp.BuildConfig
import org.koin.android.ext.android.inject
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.workmanager.factory.KoinWorkerFactory
import org.koin.androidx.workmanager.koin.workManagerFactory
import org.koin.core.context.startKoin
import org.michaelbel.movies.common.crashlytics.CrashlyticsTree
import org.michaelbel.movies.common_kmp.BuildConfig
import org.michaelbel.movies.di.appKoinModule
import org.michaelbel.movies.platform.app.AppService
import org.michaelbel.movies.platform.crashlytics.CrashlyticsService
import org.michaelbel.movies.ui.appicon.installLauncherIcon
import timber.log.Timber

@HiltAndroidApp
internal class App: Application(), Configuration.Provider {

@Inject lateinit var workerFactory: HiltWorkerFactory
@Inject lateinit var appService: AppService
@Inject lateinit var crashlyticsService: CrashlyticsService
private val workerFactory: KoinWorkerFactory by inject()
private val appService: AppService by inject()
private val crashlyticsService: CrashlyticsService by inject()

override val workManagerConfiguration: Configuration
get() = Configuration.Builder().setWorkerFactory(workerFactory).build()

override fun onCreate() {
super.onCreate()
installLauncherIcon()
startKoin {
androidLogger()
androidContext(this@App)
workManagerFactory()
modules(appKoinModule)
}
appService.installApp()
Timber.plant(if (BuildConfig.DEBUG) Timber.DebugTree() else CrashlyticsTree(crashlyticsService))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import android.os.Bundle
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.fragment.app.FragmentActivity
import dagger.hilt.android.AndroidEntryPoint
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.michaelbel.movies.common.ktx.launchAndCollectIn
import org.michaelbel.movies.ui.ktx.resolveNotificationPreferencesIntent
import org.michaelbel.movies.ui.shortcuts.installShortcuts

@AndroidEntryPoint
internal class MainActivity: FragmentActivity() {

private val viewModel: MainViewModel by viewModels()
private val viewModel: MainViewModel by viewModel()

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen().apply { setKeepOnScreenCondition { viewModel.splashLoading.value } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package org.michaelbel.movies

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import org.koin.androidx.compose.koinViewModel
import org.michaelbel.movies.account.accountGraph
import org.michaelbel.movies.account.navigateToAccount
import org.michaelbel.movies.auth.authGraph
Expand All @@ -25,7 +25,7 @@ import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
internal fun MainActivityContent(
viewModel: MainViewModel = hiltViewModel(),
viewModel: MainViewModel = koinViewModel(),
enableEdgeToEdge: (Any, Any) -> Unit
) {
val currentTheme by viewModel.currentTheme.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.navigation.NavDestination
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.workDataOf
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -27,10 +26,8 @@ import org.michaelbel.movies.interactor.Interactor
import org.michaelbel.movies.platform.messaging.MessagingService
import org.michaelbel.movies.work.AccountUpdateWorker
import org.michaelbel.movies.work.MoviesDatabaseWorker
import javax.inject.Inject

@HiltViewModel
internal class MainViewModel @Inject constructor(
internal class MainViewModel(
private val interactor: Interactor,
private val biometricController: BiometricController,
private val analytics: MoviesAnalytics,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.michaelbel.movies.di

import org.koin.dsl.module
import org.michaelbel.movies.account.di.accountKoinModule
import org.michaelbel.movies.auth.di.authKoinModule
import org.michaelbel.movies.debug.di.debugKoinModule
import org.michaelbel.movies.details.di.detailsKoinModule
import org.michaelbel.movies.feed.di.feedKoinModule
import org.michaelbel.movies.gallery.di.galleryKoinModule
import org.michaelbel.movies.platform.inject.flavorServiceKtorModule
import org.michaelbel.movies.search.di.searchKoinModule
import org.michaelbel.movies.settings.di.settingsKoinModule
import org.michaelbel.movies.widget.di.glanceKoinModule

val appKoinModule = module {
includes(
flavorServiceKtorModule,
mainKoinModule,
accountKoinModule,
authKoinModule,
detailsKoinModule,
feedKoinModule,
galleryKoinModule,
searchKoinModule,
settingsKoinModule,
debugKoinModule,
glanceKoinModule
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.michaelbel.movies.di

import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module
import org.michaelbel.movies.MainViewModel
import org.michaelbel.movies.analytics.di.moviesAnalyticsKoinModule
import org.michaelbel.movies.common.biometric.di.biometricKoinModule
import org.michaelbel.movies.debug.di.debugNotificationClientKoinModule
import org.michaelbel.movies.interactor.di.interactorKoinModule
import org.michaelbel.movies.platform.inject.flavorServiceKtorModule
import org.michaelbel.movies.work.di.workKoinModule

val mainKoinModule = module {
includes(
interactorKoinModule,
biometricKoinModule,
moviesAnalyticsKoinModule,
flavorServiceKtorModule,
workKoinModule,
debugNotificationClientKoinModule
)
viewModelOf(::MainViewModel)
}
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ plugins {
alias(libs.plugins.google.services) apply false
alias(libs.plugins.google.firebase.appdistribution) apply false
alias(libs.plugins.google.firebase.crashlytics) apply false
alias(libs.plugins.google.hilt) apply false
alias(libs.plugins.sqldelight) apply false
alias(libs.plugins.androidx.navigation.safeargs) apply false
alias(libs.plugins.spotless)
Expand Down
9 changes: 0 additions & 9 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,4 @@ dependencies {
compileOnly(libs.gradle.plugin)
compileOnly(libs.kotlin.plugin)
implementation(libs.javapoet)
}

gradlePlugin {
plugins {
register("androidHilt") {
id = "movies-android-hilt"
implementationClass = "plugins.AndroidHiltConventionPlugin"
}
}
}
4 changes: 1 addition & 3 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ dependencyResolutionManagement {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
}
25 changes: 0 additions & 25 deletions buildSrc/src/main/kotlin/plugins/AndroidHiltConventionPlugin.kt

This file was deleted.

8 changes: 6 additions & 2 deletions core/analytics-kmp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.library)
id("movies-android-hilt")
}

kotlin {
Expand All @@ -12,10 +11,15 @@ kotlin {
}
}
}
jvm("desktop")

sourceSets {
androidMain.dependencies {
commonMain.dependencies {
implementation(project(":core:platform-services:interactor-kmp"))
implementation(libs.bundles.koin.common)
}
androidMain.dependencies {
implementation(libs.koin.android)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.michaelbel.movies.analytics.di

import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import org.michaelbel.movies.analytics.MoviesAnalytics
import org.michaelbel.movies.analytics.impl.MoviesAnalyticsImpl

val moviesAnalyticsKoinModule = module {
singleOf(::MoviesAnalyticsImpl) { bind<MoviesAnalytics>() }
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 610f227

Please sign in to comment.