Repository navigation
Networking 1/5: Hilt and build setup #8
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.roomie | ||
|
|
||
| import android.app.Application | ||
| import dagger.hilt.android.HiltAndroidApp | ||
|
|
||
| @HiltAndroidApp | ||
| class RoomieApplication : Application() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.example.roomie.data | ||
|
|
||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
|
|
||
| /** Lets ViewModels inject the in-memory data until each screen moves to its real repository. */ | ||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object FakeDataModule { | ||
|
|
||
| @Provides | ||
| fun provideFakeRoomieRepository(): FakeRoomieRepository = FakeRoomieRepository | ||
| } |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, preview?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Format the file
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is so much business logic in composable functions. This is what the VM is for. For instance, you shouldn't see |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,6 @@ import androidx.compose.ui.unit.sp | |
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import androidx.lifecycle.viewModelScope | ||
| import androidx.lifecycle.viewmodel.compose.viewModel | ||
| import com.example.roomie.R | ||
| import com.example.roomie.data.ChoreRules | ||
| import com.example.roomie.data.FakeRoomieRepository | ||
|
|
@@ -104,8 +103,12 @@ import java.time.DayOfWeek | |
| import java.time.LocalDate | ||
| import java.time.format.TextStyle | ||
| import java.util.Locale | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import javax.inject.Inject | ||
| import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel | ||
|
|
||
| class ChoresViewModel(private val repo: FakeRoomieRepository = FakeRoomieRepository) : ViewModel() { | ||
| @HiltViewModel | ||
| class ChoresViewModel @Inject constructor(private val repo: FakeRoomieRepository) : ViewModel() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this vm just sitting around in the same file |
||
| val state: StateFlow<RoomieState> = repo.state.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), repo.state.value) | ||
| fun today(): LocalDate = repo.today() | ||
| fun toggleDone(id: String) = repo.toggleChoreDone(id) | ||
|
|
@@ -135,7 +138,7 @@ fun ChoresScreen( | |
| onOpenSettings: () -> Unit, | ||
| onOpenChore: (String) -> Unit, | ||
| onManageRotations: () -> Unit, | ||
| vm: ChoresViewModel = viewModel(), | ||
| vm: ChoresViewModel = hiltViewModel(), | ||
| ) { | ||
| val state by vm.state.collectAsStateWithLifecycle() | ||
| val house = state.house ?: return | ||
|
|
@@ -498,7 +501,7 @@ private fun AddChoreSheet( | |
|
|
||
| /** "Chore details": who has it, when it's due, and Mark Complete. */ | ||
| @Composable | ||
| fun ChoreDetailScreen(choreId: String, onBack: () -> Unit, onViewRotation: (String) -> Unit, vm: ChoresViewModel = viewModel()) { | ||
| fun ChoreDetailScreen(choreId: String, onBack: () -> Unit, onViewRotation: (String) -> Unit, vm: ChoresViewModel = hiltViewModel()) { | ||
| val state by vm.state.collectAsStateWithLifecycle() | ||
| val me = state.session?.userId | ||
| val chore = ChoreRules.choreById(state, choreId) | ||
|
|
@@ -562,7 +565,7 @@ fun ChoreDetailScreen(choreId: String, onBack: () -> Unit, onViewRotation: (Stri | |
|
|
||
| /** "Manage Rotations": every rotation in the house with who's next. */ | ||
| @Composable | ||
| fun ManageRotationsScreen(onBack: () -> Unit, onOpenRotation: (String) -> Unit, vm: ChoresViewModel = viewModel()) { | ||
| fun ManageRotationsScreen(onBack: () -> Unit, onOpenRotation: (String) -> Unit, vm: ChoresViewModel = hiltViewModel()) { | ||
| val state by vm.state.collectAsStateWithLifecycle() | ||
| val today = vm.today() | ||
|
|
||
|
|
@@ -603,7 +606,7 @@ fun ManageRotationsScreen(onBack: () -> Unit, onOpenRotation: (String) -> Unit, | |
|
|
||
| /** "Edit rotation": change people and pace from a future week, with a preview of the next turns. */ | ||
| @Composable | ||
| fun EditRotationScreen(rotationId: String, onBack: () -> Unit, vm: ChoresViewModel = viewModel()) { | ||
| fun EditRotationScreen(rotationId: String, onBack: () -> Unit, vm: ChoresViewModel = hiltViewModel()) { | ||
| val state by vm.state.collectAsStateWithLifecycle() | ||
| val house = state.house ?: return | ||
| val rotation = state.rotations.firstOrNull { it.id == rotationId } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Format file |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- Allows plain HTTP only to the local backend / mock server; everything else stays HTTPS. --> | ||
| <network-security-config> | ||
| <domain-config cleartextTrafficPermitted="true"> | ||
| <domain includeSubdomains="false">10.0.2.2</domain> | ||
| <domain includeSubdomains="false">localhost</domain> | ||
| </domain-config> | ||
| </network-security-config> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,11 @@ kotlin = "2.2.10" | |||||
| composeBom = "2026.02.01" | ||||||
| navigationCompose = "2.9.5" | ||||||
| desugarJdkLibs = "2.1.5" | ||||||
| retrofit = "2.11.0" | ||||||
| okhttp = "4.12.0" | ||||||
| hilt = "2.60.1" | ||||||
| hiltAndroidx = "1.3.0" | ||||||
| ksp = "2.3.13" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pin KSP to 2.3.14 to avoid the concurrent-execution regression in 2.3.13. KSP 2.3.13 has a known regression (google/ksp#3286). When KSP executions overlap in one JVM, one execution can clear the shared Overlapping KSP executions need parallel task execution. KSP 2.3.14 fixes the regression. Change the pin: Update the KSP version pin
Committable suggestion
|
||||||
|
|
||||||
| [libraries] | ||||||
| androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } | ||||||
|
|
@@ -30,8 +35,18 @@ androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "u | |||||
| androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } | ||||||
| androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } | ||||||
| androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" } | ||||||
| retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" } | ||||||
| retrofit-converter-gson = { group = "com.squareup.retrofit2", name = "converter-gson", version.ref = "retrofit" } | ||||||
| okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" } | ||||||
| okhttp-logging-interceptor = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" } | ||||||
| okhttp-mockwebserver = { group = "com.squareup.okhttp3", name = "mockwebserver", version.ref = "okhttp" } | ||||||
| hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" } | ||||||
| hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" } | ||||||
| androidx-hilt-lifecycle-viewmodel-compose = { group = "androidx.hilt", name = "hilt-lifecycle-viewmodel-compose", version.ref = "hiltAndroidx" } | ||||||
|
|
||||||
| [plugins] | ||||||
| android-application = { id = "com.android.application", version.ref = "agp" } | ||||||
| kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } | ||||||
| hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } | ||||||
| ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is mega messy and needs serious cleaning up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good start would be to take these components out into their own files (with previews).