Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
IanGClifton authored Jul 29, 2024
2 parents 09286cb + 1f287cb commit 4a51094
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 21 deletions.
9 changes: 3 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
alias(libs.plugins.compose.compiler)
}

android {
compileSdk = libs.versions.compileSdk.get().toInt()
buildFeatures {
dataBinding = true
}

defaultConfig {
applicationId = "com.google.samples.apps.sunflower"
minSdk = libs.versions.minSdk.get().toInt()
Expand Down Expand Up @@ -76,9 +75,6 @@ android {
dataBinding = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
packagingOptions {
// Multiple dependency bring these files in. Exclude them to enable
// our test APK to build (has no effect on our AARs)
Expand Down Expand Up @@ -142,6 +138,7 @@ dependencies {
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.runtime.livedata)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.glide)
implementation(libs.accompanist.systemuicontroller)
debugImplementation(libs.androidx.compose.ui.tooling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -47,6 +46,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.bumptech.glide.integration.compose.GlideImage
import com.google.samples.apps.sunflower.R
Expand All @@ -65,7 +65,7 @@ fun GardenScreen(
onAddPlantClick: () -> Unit,
onPlantClick: (PlantAndGardenPlantings) -> Unit
) {
val gardenPlants by viewModel.plantAndGardenPlantings.collectAsState(initial = emptyList())
val gardenPlants by viewModel.plantAndGardenPlantings.collectAsStateWithLifecycle()
GardenScreen(
gardenPlants = gardenPlants,
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,10 @@ private fun HomeTopAppBar(
) {
CenterAlignedTopAppBar(
title = {
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
) {
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.displaySmall
style = MaterialTheme.typography.headlineSmall
)
}
},
modifier = modifier,
actions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState

import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
Expand All @@ -82,6 +82,7 @@ import androidx.compose.ui.viewinterop.AndroidViewBinding
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.core.text.HtmlCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.bumptech.glide.integration.compose.GlideImage
import com.bumptech.glide.load.DataSource
Expand Down Expand Up @@ -116,7 +117,7 @@ fun PlantDetailsScreen(
onGalleryClick: (Plant) -> Unit,
) {
val plant = plantDetailsViewModel.plant.observeAsState().value
val isPlanted = plantDetailsViewModel.isPlanted.collectAsState(initial = false).value
val isPlanted = plantDetailsViewModel.isPlanted.collectAsStateWithLifecycle().value
val showSnackbar = plantDetailsViewModel.showSnackbar.observeAsState().value

if (plant != null && showSnackbar != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@
package com.google.samples.apps.sunflower.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.samples.apps.sunflower.data.GardenPlantingRepository
import com.google.samples.apps.sunflower.data.PlantAndGardenPlantings
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class GardenPlantingListViewModel @Inject internal constructor(
gardenPlantingRepository: GardenPlantingRepository
) : ViewModel() {
val plantAndGardenPlantings: Flow<List<PlantAndGardenPlantings>> =
gardenPlantingRepository.getPlantedGardens()
val plantAndGardenPlantings: StateFlow<List<PlantAndGardenPlantings>> =
gardenPlantingRepository
.getPlantedGardens()
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000),
emptyList()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import com.google.samples.apps.sunflower.BuildConfig
import com.google.samples.apps.sunflower.data.GardenPlantingRepository
import com.google.samples.apps.sunflower.data.PlantRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -42,6 +44,11 @@ class PlantDetailViewModel @Inject constructor(
val plantId: String = savedStateHandle.get<String>(PLANT_ID_SAVED_STATE_KEY)!!

val isPlanted = gardenPlantingRepository.isPlanted(plantId)
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000),
false
)
val plant = plantRepository.getPlant(plantId).asLiveData()

private val _showSnackbar = MutableLiveData(false)
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ plugins {
alias(libs.plugins.android.test) apply false
alias(libs.plugins.gradle.versions)
alias(libs.plugins.version.catalog.update)
alias(libs.plugins.compose.compiler)
}

apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ guava = "33.1.0-jre"
hilt = "2.51.1"
hiltNavigationCompose = "1.2.0"
junit = "4.13.2"
kotlin = "1.9.23"
ksp = "1.9.23-1.0.20"
kotlin = "2.0.0"
ksp = "2.0.0-1.0.21"
# @keep
ktlint = "0.40.0"
ktx = "1.13.1"
Expand Down Expand Up @@ -87,6 +87,7 @@ androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", vers
androidx-espresso-intents = { module = "androidx.test.espresso:espresso-intents", version.ref = "espresso" }
androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifecycle" }
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "viewModelCompose" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "viewModelCompose" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
androidx-monitor = { module = "androidx.test:monitor", version.ref = "monitor" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation" }
Expand Down Expand Up @@ -123,3 +124,4 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

0 comments on commit 4a51094

Please sign in to comment.