From 489dc64a12186f703de044d96f69198ac63a829d Mon Sep 17 00:00:00 2001
From: Janne Mareike Koschinski <mail@justjanne.de>
Date: Mon, 30 Oct 2023 22:53:30 +0100
Subject: [PATCH] wip: add hilt

---
 api/build.gradle.kts                          | 10 -----
 app/build.gradle.kts                          |  7 ++++
 app/src/main/AndroidManifest.xml              |  1 +
 .../main/kotlin/de/chaosdorf/meteroid/App.kt  | 38 +++++++++++++++++++
 .../de/chaosdorf/meteroid/MainActivity.kt     | 13 +------
 .../chaosdorf/meteroid/MeteroidApplication.kt | 31 +++++++++++++++
 build.gradle.kts                              |  2 +
 gradle/libs.versions.toml                     |  4 ++
 persistence/build.gradle.kts                  |  4 ++
 9 files changed, 89 insertions(+), 21 deletions(-)
 create mode 100644 app/src/main/kotlin/de/chaosdorf/meteroid/App.kt
 create mode 100644 app/src/main/kotlin/de/chaosdorf/meteroid/MeteroidApplication.kt

diff --git a/api/build.gradle.kts b/api/build.gradle.kts
index ff29e76..b6e578e 100644
--- a/api/build.gradle.kts
+++ b/api/build.gradle.kts
@@ -25,16 +25,6 @@ plugins {
 }
 
 dependencies {
-  implementation(libs.kotlin.stdlib)
-
-  implementation(libs.kotlinx.coroutines.core)
-  testImplementation(libs.kotlinx.coroutines.test)
-
-  testImplementation(libs.kotlin.test)
-  testImplementation(libs.junit.api)
-  testImplementation(libs.junit.params)
-  testRuntimeOnly(libs.junit.engine)
-
   implementation(libs.kotlinx.datetime)
 
   implementation(libs.okhttp)
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index b64fb07..5692fb9 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -21,6 +21,9 @@
 
 plugins {
   id("justjanne.android.app")
+  alias(libs.plugins.kotlin.serialization)
+  alias(libs.plugins.kotlin.ksp)
+  alias(libs.plugins.dagger.hilt)
 }
 
 android {
@@ -85,6 +88,10 @@ dependencies {
   implementation(libs.okhttp)
   implementation(libs.kotlinx.serialization.json)
   implementation(libs.coil.compose)
+
+  implementation(libs.hilt.android)
+  ksp(libs.hilt.compiler)
+
   implementation(project(":api"))
   implementation(project(":persistence"))
 
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3ae67d5..9cd15e0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,7 @@
   <uses-permission android:name="android.permission.INTERNET" />
 
   <application
+    android:name=".MeteroidApplication"
     android:allowBackup="true"
     android:icon="@mipmap/ic_launcher"
     android:label="@string/application_name"
diff --git a/app/src/main/kotlin/de/chaosdorf/meteroid/App.kt b/app/src/main/kotlin/de/chaosdorf/meteroid/App.kt
new file mode 100644
index 0000000..710454e
--- /dev/null
+++ b/app/src/main/kotlin/de/chaosdorf/meteroid/App.kt
@@ -0,0 +1,38 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2023 Chaosdorf e.V.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package de.chaosdorf.meteroid
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import de.chaosdorf.meteroid.di.RootViewModel
+import de.chaosdorf.meteroid.routes.RootRouter
+
+@Composable
+fun App(viewModel: RootViewModel) {
+  val route by viewModel.route.collectAsState()
+
+    RootRouter(route)
+}
diff --git a/app/src/main/kotlin/de/chaosdorf/meteroid/MainActivity.kt b/app/src/main/kotlin/de/chaosdorf/meteroid/MainActivity.kt
index 875e72b..af1770b 100644
--- a/app/src/main/kotlin/de/chaosdorf/meteroid/MainActivity.kt
+++ b/app/src/main/kotlin/de/chaosdorf/meteroid/MainActivity.kt
@@ -27,16 +27,14 @@ package de.chaosdorf.meteroid
 import android.os.Bundle
 import androidx.activity.ComponentActivity
 import androidx.activity.compose.setContent
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.collectAsState
-import androidx.compose.runtime.getValue
+import dagger.hilt.android.AndroidEntryPoint
 import de.chaosdorf.meteroid.di.RootViewModel
 import de.chaosdorf.meteroid.di.RootViewModelFactory
-import de.chaosdorf.meteroid.routes.RootRouter
 import de.chaosdorf.meteroid.ui.theme.MeteroidTheme
 import kotlinx.coroutines.MainScope
 
 
+@AndroidEntryPoint
 class MainActivity : ComponentActivity() {
   private val rootViewModelFactory = object : RootViewModelFactory {}
   private lateinit var rootViewModel: RootViewModel
@@ -54,10 +52,3 @@ class MainActivity : ComponentActivity() {
     }
   }
 }
-
-@Composable
-fun App(viewModel: RootViewModel) {
-  val route by viewModel.route.collectAsState()
-
-  RootRouter(route)
-}
diff --git a/app/src/main/kotlin/de/chaosdorf/meteroid/MeteroidApplication.kt b/app/src/main/kotlin/de/chaosdorf/meteroid/MeteroidApplication.kt
new file mode 100644
index 0000000..1d67c5c
--- /dev/null
+++ b/app/src/main/kotlin/de/chaosdorf/meteroid/MeteroidApplication.kt
@@ -0,0 +1,31 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2023 Chaosdorf e.V.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package de.chaosdorf.meteroid
+
+import android.app.Application
+import dagger.hilt.android.HiltAndroidApp
+
+@HiltAndroidApp
+class MeteroidApplication : Application()
diff --git a/build.gradle.kts b/build.gradle.kts
index 6c489d0..51555c9 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -11,4 +11,6 @@ plugins {
   alias(libs.plugins.android.application) apply false
   alias(libs.plugins.kotlin.jvm) apply false
   alias(libs.plugins.kotlin.serialization) apply false
+  alias(libs.plugins.kotlin.ksp) apply false
+  alias(libs.plugins.dagger.hilt) apply false
 }
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index b1ef116..1cd49f7 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -11,6 +11,7 @@ androidx-compose-tooling = "1.6.0-alpha08"
 androidx-navigation = "2.7.4"
 androidx-room = "2.6.0"
 coil = "2.4.0"
+dagger-hilt = "2.48.1"
 kotlin = "1.9.10"
 kotlin-ksp = "1.9.10-1.0.13"
 kotlinxCoroutines = "1.7.1"
@@ -49,6 +50,8 @@ androidx-room-paging = { module = "androidx.room:room-paging", version.ref = "an
 
 coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
 
+hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "dagger-hilt" }
+hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "dagger-hilt" }
 okhttp = { module = "com.squareup.okhttp3:okhttp", version = "4.12.0" }
 retrofit-core = { module = "com.squareup.retrofit2:retrofit", version = "2.9.0" }
 retrofit-converter-kotlinx = { module = "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter", version = "1.0.0" }
@@ -75,6 +78,7 @@ kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-pl
 android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
 android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
 android-test = { id = "com.android.test", version.ref = "androidGradlePlugin" }
+dagger-hilt = { id = "com.google.dagger.hilt.android", version.ref = "dagger-hilt" }
 kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
 kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
 kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "kotlin.ksp" }
diff --git a/persistence/build.gradle.kts b/persistence/build.gradle.kts
index 56a70fe..fe766b9 100644
--- a/persistence/build.gradle.kts
+++ b/persistence/build.gradle.kts
@@ -23,6 +23,7 @@ plugins {
   id("justjanne.android.library")
   alias(libs.plugins.kotlin.serialization)
   alias(libs.plugins.kotlin.ksp)
+  alias(libs.plugins.dagger.hilt)
 }
 
 android {
@@ -50,6 +51,9 @@ dependencies {
   implementation(libs.androidx.room.ktx)
   implementation(libs.androidx.room.paging)
 
+  implementation(libs.hilt.android)
+  ksp(libs.hilt.compiler)
+
   implementation(libs.kotlinx.datetime)
   implementation(libs.kotlinx.serialization.json)
   implementation(project(":api"))
-- 
GitLab