Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Migration] Android hilt to koin #410

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions zeapp/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ plugins {
alias(libs.plugins.jetbrains.compose.compiler)
alias(libs.plugins.ktlint.gradle)
alias(libs.plugins.detekt.gradle)
alias(libs.plugins.dagger.hilt)
alias(libs.plugins.ksp)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.baselineprofile)
alias(libs.plugins.aboutlibraries.gradle)
Expand All @@ -31,6 +29,12 @@ android {
versionCode = appVersionCode
versionName = "1.0"

testOptions {
unitTests {
isIncludeAndroidResources = true
}
}

vectorDrawables {
useSupportLibrary = true
}
Expand Down Expand Up @@ -116,15 +120,9 @@ android {
"${layout.buildDirectory.get()}/generated/assets",
)

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"

freeCompilerArgs +=
kotlin {
jvmToolchain(17)
kotlinOptions.freeCompilerArgs +=
listOf(
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
"-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi",
Expand Down Expand Up @@ -189,12 +187,18 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.zxing)
implementation(libs.material3.wsc)
implementation(libs.dagger.hilt)
implementation(libs.coil.compose)
implementation(libs.coil.transformations)

// koin-start
implementation(libs.koin.core)
implementation(libs.koin.android)
implementation(libs.koin.androidx.navigation)
implementation(libs.koin.androidx.compose)
// koin-end

implementation(libs.timber)
implementation(libs.aboutlibraries.compose)
implementation(libs.androidx.compose.hilt.navigation)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)

Expand All @@ -206,7 +210,6 @@ dependencies {

androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.compose.ui.test.junit)
ksp(libs.dagger.hilt.compiler)
baselineProfile(projects.benchmark)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.rules.ActivityScenarioRule
import de.berlindroid.zeapp.zeentrypoint.ZeMainActivity
import org.junit.Rule
import org.junit.Test

Expand Down
2 changes: 1 addition & 1 deletion zeapp/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<profileable android:shell="true" />

<activity
android:name=".ZeMainActivity"
android:name=".zeentrypoint.ZeMainActivity"
android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden"
android:exported="true"
android:theme="@style/Theme.ZeBadgeApp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package de.berlindroid.zeapp

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

@HiltAndroidApp
class ZeApplication : Application() {
override fun onCreate() {
super.onCreate()

zeStartKoin()
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
}
}
18 changes: 18 additions & 0 deletions zeapp/android/src/main/java/de/berlindroid/zeapp/ZeKoinStarter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.berlindroid.zeapp

import de.berlindroid.zeapp.zedi.apiModule
import de.berlindroid.zeapp.zedi.servicesModule
import de.berlindroid.zeapp.zedi.viewModelModule
import de.berlindroid.zeapp.zeservices.github.zeGitHubModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level

fun ZeApplication.zeStartKoin() {
startKoin {
androidContext(this@zeStartKoin)
androidLogger(if (BuildConfig.DEBUG) Level.DEBUG else Level.NONE)
modules(apiModule, viewModelModule, servicesModule, zeGitHubModule)
}
}
110 changes: 0 additions & 110 deletions zeapp/android/src/main/java/de/berlindroid/zeapp/ZeMainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
import coil.compose.SubcomposeAsyncImage
import de.berlindroid.zeapp.zealteregos.vm.AlterEgosVm
import de.berlindroid.zeapp.zealteregos.vm.UiState
import de.berlindroid.zeapp.zealteregos.vm.User
import org.koin.androidx.compose.koinViewModel

@Composable
@Preview
fun ZeAlterEgos(paddingValues: PaddingValues) {
val viewModel: AlterEgosVm = hiltViewModel()
val viewModel: AlterEgosVm = koinViewModel()

val state by viewModel.uiState.collectAsState()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package de.berlindroid.zeapp.zealteregos.vm

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import de.berlindroid.zeapp.zeservices.ZeUserApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject

data class User(
val uuid: String,
Expand All @@ -25,9 +23,7 @@ data class UiState(
val selectedUser: User? = null,
)

@HiltViewModel
class AlterEgosVm
@Inject
constructor(
private val userApi: ZeUserApi,
) : ViewModel() {
Expand Down
Loading