From 60a9daf13bf0dad876cfc63c778763772e1c457c Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Mon, 8 Jan 2024 14:55:54 -0800 Subject: [PATCH 01/12] Update dependencies and add update deps workflow (#948) * Add workflow to update dependencies. Change-Id: Ic667c05d37eee5738bc24b2a18b2182093abb5c0 * Update dependencies and add update deps workflow. Change-Id: Ia037b710c933db39aca71db19d5bcfdf476bf0e9 * Address PR comments and remove unused dependencies. Change-Id: I4c327c615af09020f07cc9efcae98e0195c820e7 --- .github/ci-gradle.properties | 26 +++++++ .github/workflows/update_deps.yml | 53 +++++++++++++ .../samples/apps/sunflower/MainApplication.kt | 8 +- build.gradle.kts | 9 +-- buildscripts/init.gradle.kts | 72 +++++++++++++++++ buildscripts/toml-updater-config.gradle | 17 ++++ gradle/libs.versions.toml | 78 +++++++++---------- gradle/wrapper/gradle-wrapper.properties | 4 +- .../BaselineProfileGenerator.kt | 4 +- 9 files changed, 215 insertions(+), 56 deletions(-) create mode 100644 .github/ci-gradle.properties create mode 100644 .github/workflows/update_deps.yml create mode 100644 buildscripts/init.gradle.kts diff --git a/.github/ci-gradle.properties b/.github/ci-gradle.properties new file mode 100644 index 000000000..0d2e120c3 --- /dev/null +++ b/.github/ci-gradle.properties @@ -0,0 +1,26 @@ +# +# Copyright 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +org.gradle.daemon=false +org.gradle.parallel=true +org.gradle.jvmargs=-Xmx5120m +org.gradle.workers.max=2 + +kotlin.incremental=false +kotlin.compiler.execution.strategy=in-process + +# Controls KotlinOptions.allWarningsAsErrors. This is used in CI and can be set in local properties. +warningsAsErrors=true diff --git a/.github/workflows/update_deps.yml b/.github/workflows/update_deps.yml new file mode 100644 index 000000000..ab89ac6b7 --- /dev/null +++ b/.github/workflows/update_deps.yml @@ -0,0 +1,53 @@ +# +# Copyright 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: Update Versions / Dependencies + +on: + schedule: + - cron: '9 0 1 * *' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Copy CI gradle.properties + run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'zulu' + cache: gradle + + - name: Update dependencies + run: ./gradlew versionCatalogUpdate + - name: Create pull request + id: cpr + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.PAT }} + commit-message: 🤖 Update Dependencies + committer: compose-devrel-github-bot + author: compose-devrel-github-bot + signoff: false + branch: bot-update-deps + delete-branch: true + title: '🤖 Update Dependencies' + body: Updated depedencies + reviewers: ${{ github.actor }} diff --git a/app/src/main/java/com/google/samples/apps/sunflower/MainApplication.kt b/app/src/main/java/com/google/samples/apps/sunflower/MainApplication.kt index 159512dfa..12bbc93af 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/MainApplication.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/MainApplication.kt @@ -22,8 +22,8 @@ import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class MainApplication : Application(), Configuration.Provider { - override fun getWorkManagerConfiguration(): Configuration = - Configuration.Builder() - .setMinimumLoggingLevel(if (BuildConfig.DEBUG) android.util.Log.DEBUG else android.util.Log.ERROR) - .build() + override val workManagerConfiguration: Configuration + get() = Configuration.Builder() + .setMinimumLoggingLevel(if (BuildConfig.DEBUG) android.util.Log.DEBUG else android.util.Log.ERROR) + .build() } diff --git a/build.gradle.kts b/build.gradle.kts index 7b15be8fa..1112b5044 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,11 +28,8 @@ plugins { alias(libs.plugins.spotless) alias(libs.plugins.ksp) apply false alias(libs.plugins.android.test) apply false + alias(libs.plugins.gradle.versions) + alias(libs.plugins.version.catalog.update) } -spotless { - kotlin { - target("**/*.kt") - ktlint(libs.versions.ktlint.get()).userData(mapOf("max_line_length" to "100")) - } -} +apply("${project.rootDir}/buildscripts/toml-updater-config.gradle") diff --git a/buildscripts/init.gradle.kts b/buildscripts/init.gradle.kts new file mode 100644 index 000000000..9e3524b24 --- /dev/null +++ b/buildscripts/init.gradle.kts @@ -0,0 +1,72 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +val ktlintVersion = "0.46.1" + +initscript { + val spotlessVersion = "6.10.0" + + repositories { + mavenCentral() + } + + dependencies { + classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") + } +} + +allprojects { + if (this == rootProject) { + return@allprojects + } + apply() + extensions.configure { + kotlin { + target("**/*.kt") + targetExclude("**/build/**/*.kt") + ktlint(ktlintVersion).editorConfigOverride( + mapOf( + "ktlint_code_style" to "android", + "ij_kotlin_allow_trailing_comma" to true, + // These rules were introduced in ktlint 0.46.0 and should not be + // enabled without further discussion. They are disabled for now. + // See: https://github.com/pinterest/ktlint/releases/tag/0.46.0 + "disabled_rules" to + "filename," + + "annotation,annotation-spacing," + + "argument-list-wrapping," + + "double-colon-spacing," + + "enum-entry-name-case," + + "multiline-if-else," + + "no-empty-first-line-in-method-block," + + "package-name," + + "trailing-comma," + + "spacing-around-angle-brackets," + + "spacing-between-declarations-with-annotations," + + "spacing-between-declarations-with-comments," + + "unary-op-spacing" + ) + ) + licenseHeaderFile(rootProject.file("spotless/copyright.kt")) + } + format("kts") { + target("**/*.kts") + targetExclude("**/build/**/*.kts") + // Look for the first line that doesn't have a block comment (assumed to be the license) + licenseHeaderFile(rootProject.file("spotless/copyright.kt"), "(^(?![\\/ ]\\*).*$)") + } + } +} diff --git a/buildscripts/toml-updater-config.gradle b/buildscripts/toml-updater-config.gradle index aeb54c5f8..fbb07f79d 100644 --- a/buildscripts/toml-updater-config.gradle +++ b/buildscripts/toml-updater-config.gradle @@ -26,3 +26,20 @@ versionCatalogUpdate { keepUnusedPlugins.set(true) } } + +def isNonStable = { String version -> + def regex = /^[0-9,.v-]+(-r)?$/ + return !(version ==~ regex) +} + +tasks.named("dependencyUpdates").configure { + resolutionStrategy { + componentSelection { + all { + if (isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)) { + reject('Release candidate') + } + } + } + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4ddb0b355..19c70374d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ ## -## Copyright 2022 Google LLC +## Copyright 2024 Google LLC ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. @@ -14,63 +14,64 @@ ## limitations under the License. ## [versions] -accessibilityTestFramework = "4.0.0" -activityCompose = "1.8.1" -androidGradlePlugin = "8.1.2" -benchmark = "1.1.0" +accessibilityTestFramework = "4.1.0" +activityCompose = "1.8.2" +androidGradlePlugin = "8.2.1" +benchmark = "1.2.2" # @keep compileSdk = "34" -composeLatest = "1.6.0-beta03" +# @keep +compose-compiler = "1.5.7" composeBom = "2023.10.01" -compose-compiler = "1.5.3" +composeLatest = "1.6.0-beta03" constraintLayoutCompose = "1.0.1" coreTesting = "2.2.0" -coroutines = "1.6.4" -espresso = "3.4.0" +coroutines = "1.7.3" +espresso = "3.5.1" glide = "1.0.0-beta01" gradle = "7.2.0" +gradle-versions = "0.50.0" gson = "2.9.0" -guava = "31.1-android" -hilt = "2.48" -hiltNavigationCompose = "1.0.0" +guava = "33.0.0-jre" +hilt = "2.50" +hiltNavigationCompose = "1.1.0" junit = "4.13.2" -kotlin = "1.9.10" +kotlin = "1.9.21" +ksp = "1.9.21-1.0.15" +# @keep ktlint = "0.40.0" ktx = "1.7.0" -lifecycle = "2.6.0-alpha04" +lifecycle = "2.6.2" material = "1.8.0-rc01" -material3 = "1.2.0-alpha11" +material3 = "1.2.0-beta01" # @keep -minSdk = "23" -monitor = "1.6.0" -navigation = "2.5.3" -okhttpLogging = "4.10.0" -pagingCompose = "1.0.0-alpha19" -profileInstaller = "1.2.0" -recyclerView = "1.3.0-alpha02" +minSdk = "24" +monitor = "1.6.1" +navigation = "2.7.6" +okhttpLogging = "4.12.0" +pagingCompose = "3.3.0-alpha02" +profileInstaller = "1.3.1" retrofit = "2.9.0" -room = "2.5.2" -runner = "1.0.1" +room = "2.6.1" +spotless = "6.23.3" +systemuicontroller = "0.32.0" # @keep targetSdk = "34" testExtJunit = "1.1.5" uiAutomator = "2.2.0" -viewModelCompose = "2.5.1" -work = "2.7.1" -systemuicontroller = "0.30.1" -ksp = "1.9.10-1.0.13" -spotless = "6.4.1" +version-catalog-update = "0.8.3" +viewModelCompose = "2.6.2" +work = "2.9.0" [libraries] accessibility-test-framework = { module = "com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework", version.ref = "accessibilityTestFramework" } -android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" } +accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "systemuicontroller" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" } androidx-arch-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "coreTesting" } androidx-benchmark-macro-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "benchmark" } androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" } androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "composeLatest" } androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout", version.ref = "composeLatest" } -androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "composeLatest" } androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" } androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "composeLatest" } androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata", version.ref = "composeLatest" } @@ -93,37 +94,32 @@ androidx-paging-compose = { module = "androidx.paging:paging-compose", version.r androidx-profileinstaller = { module = "androidx.profileinstaller:profileinstaller", version.ref = "profileInstaller" } androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" } androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" } -androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" } androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "testExtJunit" } androidx-test-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "uiAutomator" } -androidx-work-testing = { module = "androidx.work:work-testing", version.ref = "work" } androidx-work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "work" } +androidx-work-testing = { module = "androidx.work:work-testing", version.ref = "work" } glide = { module = "com.github.bumptech.glide:compose", version.ref = "glide" } gson = { module = "com.google.code.gson:gson", version.ref = "gson" } guava = { module = "com.google.guava:guava", version.ref = "guava" } hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" } hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" } -hilt-android-gradle-plugin = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "hilt" } hilt-android-testing = { module = "com.google.dagger:hilt-android-testing", version.ref = "hilt" } hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigationCompose" } junit = { module = "junit:junit", version.ref = "junit" } -kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" } kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } -kotlinx-coroutines-guava = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-guava", version.ref = "coroutines" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" } material = { module = "com.google.android.material:material", version.ref = "material" } -accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "systemuicontroller" } okhttp3-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttpLogging" } retrofit2 = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" } retrofit2-converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" } [plugins] 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" } -ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +gradle-versions = { id = "com.github.ben-manes.versions", version.ref = "gradle-versions" } hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } +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" } -kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin"} -kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d8882eb97..7411f462c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Oct 13 20:23:10 PDT 2020 +#Wed Jan 03 11:14:53 PST 2024 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/macrobenchmark/src/main/java/com/google/samples/apps/sunflower/macrobenchmark/BaselineProfileGenerator.kt b/macrobenchmark/src/main/java/com/google/samples/apps/sunflower/macrobenchmark/BaselineProfileGenerator.kt index 291b483fd..72b8b57ed 100644 --- a/macrobenchmark/src/main/java/com/google/samples/apps/sunflower/macrobenchmark/BaselineProfileGenerator.kt +++ b/macrobenchmark/src/main/java/com/google/samples/apps/sunflower/macrobenchmark/BaselineProfileGenerator.kt @@ -16,7 +16,6 @@ package com.google.samples.apps.sunflower.macrobenchmark -import androidx.benchmark.macro.ExperimentalBaselineProfilesApi import androidx.benchmark.macro.junit4.BaselineProfileRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.uiautomator.By @@ -25,7 +24,6 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -@OptIn(ExperimentalBaselineProfilesApi::class) @RunWith(AndroidJUnit4::class) class BaselineProfileGenerator { @@ -34,7 +32,7 @@ class BaselineProfileGenerator { @Test fun startPlantListPlantDetail() { - rule.collectBaselineProfile(PACKAGE_NAME) { + rule.collect(PACKAGE_NAME) { // start the app flow pressHome() startActivityAndWait() From 64f7606ebc3c74e8205182948ccd2fbc00384275 Mon Sep 17 00:00:00 2001 From: Farouk Sabiou Date: Wed, 10 Jan 2024 22:00:06 +0100 Subject: [PATCH 02/12] Remove deprecated SunflowerImage Glide wrapper in favor of GlideImage composable. (#945) The SunflowerImage() wrapper was introduced as a workaround for the issue https://github.com/bumptech/glide/issues/4977, and now that the issue has been resolved, there is no need for this wrapper in the codebase. Others minor changes: - Simplified expression if (plant != null && isPlanted != null && showSnackbar != null) to if (plant != null && showSnackbar != null) as (isPlanted != null) is always true. - Replaced deprecated Icons.Filled.ArrowBack with Icons.AutoMirrored.Filled.ArrowBack. Co-authored-by: Chris Arriola --- .../sunflower/compose/garden/GardenScreen.kt | 11 ++- .../compose/plantdetail/PlantDetailView.kt | 14 ++-- .../compose/plantlist/PlantListItemView.kt | 8 +-- .../sunflower/compose/utils/SunflowerImage.kt | 72 ------------------- 4 files changed, 17 insertions(+), 88 deletions(-) delete mode 100644 app/src/main/java/com/google/samples/apps/sunflower/compose/utils/SunflowerImage.kt diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt index 376081fe3..642b52c2c 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.imePadding -import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid @@ -33,7 +32,6 @@ import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.material3.Button import androidx.compose.material3.CardDefaults import androidx.compose.material3.ElevatedCard -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -49,15 +47,16 @@ 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 com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi +import com.bumptech.glide.integration.compose.GlideImage import com.google.samples.apps.sunflower.R -import com.google.samples.apps.sunflower.compose.utils.SunflowerImage import com.google.samples.apps.sunflower.data.GardenPlanting import com.google.samples.apps.sunflower.data.Plant import com.google.samples.apps.sunflower.data.PlantAndGardenPlantings import com.google.samples.apps.sunflower.ui.SunflowerTheme import com.google.samples.apps.sunflower.viewmodels.GardenPlantingListViewModel import com.google.samples.apps.sunflower.viewmodels.PlantAndGardenPlantingsViewModel -import java.util.* +import java.util.Calendar @Composable fun GardenScreen( @@ -117,7 +116,7 @@ private fun GardenList( } @OptIn( - ExperimentalMaterial3Api::class + ExperimentalGlideComposeApi::class ) @Composable private fun GardenListItem( @@ -140,7 +139,7 @@ private fun GardenListItem( colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer) ) { Column(Modifier.fillMaxWidth()) { - SunflowerImage( + GlideImage( model = vm.imageUrl, contentDescription = plant.plant.description, Modifier diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt index e1325c7d1..0d8b12f24 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt @@ -43,8 +43,8 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Add -import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.Share import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FloatingActionButton @@ -82,13 +82,14 @@ import androidx.compose.ui.viewinterop.AndroidViewBinding import androidx.constraintlayout.compose.ConstraintLayout import androidx.core.text.HtmlCompat import androidx.hilt.navigation.compose.hiltViewModel +import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi +import com.bumptech.glide.integration.compose.GlideImage import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target import com.google.samples.apps.sunflower.R import com.google.samples.apps.sunflower.compose.Dimens -import com.google.samples.apps.sunflower.compose.utils.SunflowerImage import com.google.samples.apps.sunflower.compose.utils.TextSnackbarContainer import com.google.samples.apps.sunflower.compose.visible import com.google.samples.apps.sunflower.data.Plant @@ -118,7 +119,7 @@ fun PlantDetailsScreen( val isPlanted = plantDetailsViewModel.isPlanted.collectAsState(initial = false).value val showSnackbar = plantDetailsViewModel.showSnackbar.observeAsState().value - if (plant != null && isPlanted != null && showSnackbar != null) { + if (plant != null && showSnackbar != null) { Surface { TextSnackbarContainer( snackbarText = stringResource(R.string.added_plant_to_garden), @@ -265,6 +266,7 @@ private fun PlantDetailsContent( } } +@OptIn(ExperimentalGlideComposeApi::class) @Composable private fun PlantImage( imageUrl: String, @@ -287,7 +289,7 @@ private fun PlantImage( .background(placeholderColor) ) } - SunflowerImage( + GlideImage( model = imageUrl, contentDescription = null, modifier = Modifier @@ -388,7 +390,7 @@ private fun PlantDetailsToolbar( Modifier.align(Alignment.CenterVertically) ) { Icon( - Icons.Filled.ArrowBack, + Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(id = R.string.a11y_back) ) } @@ -451,7 +453,7 @@ private fun PlantHeaderActions( .then(iconModifier) ) { Icon( - Icons.Filled.ArrowBack, + Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(id = R.string.a11y_back) ) } diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListItemView.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListItemView.kt index 7a05f4877..f921c0e9a 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListItemView.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListItemView.kt @@ -23,7 +23,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -33,8 +32,9 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign +import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi +import com.bumptech.glide.integration.compose.GlideImage import com.google.samples.apps.sunflower.R -import com.google.samples.apps.sunflower.compose.utils.SunflowerImage import com.google.samples.apps.sunflower.data.Plant import com.google.samples.apps.sunflower.data.UnsplashPhoto @@ -48,7 +48,7 @@ fun PhotoListItem(photo: UnsplashPhoto, onClick: () -> Unit) { ImageListItem(name = photo.user.name, imageUrl = photo.urls.small, onClick = onClick) } -@OptIn(ExperimentalMaterial3Api::class) +@OptIn(ExperimentalGlideComposeApi::class) @Composable fun ImageListItem(name: String, imageUrl: String, onClick: () -> Unit) { Card( @@ -59,7 +59,7 @@ fun ImageListItem(name: String, imageUrl: String, onClick: () -> Unit) { .padding(bottom = dimensionResource(id = R.dimen.card_bottom_margin)) ) { Column(Modifier.fillMaxWidth()) { - SunflowerImage( + GlideImage( model = imageUrl, contentDescription = stringResource(R.string.a11y_plant_item_image), Modifier diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/utils/SunflowerImage.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/utils/SunflowerImage.kt deleted file mode 100644 index 98881dd5d..000000000 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/utils/SunflowerImage.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.samples.apps.sunflower.compose.utils - -import android.graphics.drawable.Drawable -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.size -import androidx.compose.material3.CircularProgressIndicator -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ColorFilter -import androidx.compose.ui.graphics.DefaultAlpha -import androidx.compose.ui.graphics.painter.ColorPainter -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.platform.LocalInspectionMode -import androidx.compose.ui.unit.dp -import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi -import com.bumptech.glide.integration.compose.GlideImage -import com.bumptech.glide.integration.compose.RequestBuilderTransform -import com.bumptech.glide.integration.compose.placeholder - -/** - * Wrapper around a [GlideImage] so that composable previews work. - * This can be removed once https://github.com/bumptech/glide/issues/4977 is fixed. - */ -@OptIn(ExperimentalGlideComposeApi::class) -@Composable -fun SunflowerImage( - model: Any?, - contentDescription: String?, - modifier: Modifier = Modifier, - alignment: Alignment = Alignment.Center, - contentScale: ContentScale = ContentScale.Fit, - alpha: Float = DefaultAlpha, - colorFilter: ColorFilter? = null, - requestBuilderTransform: RequestBuilderTransform = { it }, -) { - if (LocalInspectionMode.current) { - Box(modifier = modifier.background(Color.Magenta)) - return - } - GlideImage( - model = model, - contentDescription = contentDescription, - modifier = modifier, - alignment = alignment, - contentScale = contentScale, - alpha = alpha, - colorFilter = colorFilter, - requestBuilderTransform = requestBuilderTransform, - loading = placeholder(ColorPainter(MaterialTheme.colorScheme.secondary)) - ) -} From 9d623bb0b02dbb4053decc62642ea56dde028c8d Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Wed, 24 Jan 2024 14:49:26 -0800 Subject: [PATCH 03/12] Use secrets.GITHUB_TOKEN for update_deps workflow. (#949) Change-Id: I7cd89bc19ed08eace4312a27245f92b4fe85d3ef --- .github/workflows/update_deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_deps.yml b/.github/workflows/update_deps.yml index ab89ac6b7..7c5533d18 100644 --- a/.github/workflows/update_deps.yml +++ b/.github/workflows/update_deps.yml @@ -41,7 +41,7 @@ jobs: id: cpr uses: peter-evans/create-pull-request@v4 with: - token: ${{ secrets.PAT }} + token: ${{ secrets.GITHUB_TOKEN }} commit-message: 🤖 Update Dependencies committer: compose-devrel-github-bot author: compose-devrel-github-bot From 1da678226a92631c315118f4c536f335524727f2 Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Wed, 24 Jan 2024 16:38:09 -0800 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=A4=96=20Update=20Dependencies=20(#?= =?UTF-8?q?951)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🤖 Update Dependencies * Use Compose Stable for Compose deps. Change-Id: Ia26118bbbca8932e1d33da08ea5010b1702e4188 --------- Co-authored-by: compose-devrel-github-bot --- gradle/libs.versions.toml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 19c70374d..bf5cd404c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,34 +16,34 @@ [versions] accessibilityTestFramework = "4.1.0" activityCompose = "1.8.2" -androidGradlePlugin = "8.2.1" -benchmark = "1.2.2" +androidGradlePlugin = "8.2.2" +benchmark = "1.2.3" # @keep compileSdk = "34" # @keep -compose-compiler = "1.5.7" -composeBom = "2023.10.01" -composeLatest = "1.6.0-beta03" +compose-compiler = "1.5.8" +composeBom = "2024.01.00" +composeLatest = "1.7.0-alpha01" constraintLayoutCompose = "1.0.1" coreTesting = "2.2.0" coroutines = "1.7.3" espresso = "3.5.1" glide = "1.0.0-beta01" gradle = "7.2.0" -gradle-versions = "0.50.0" +gradle-versions = "0.51.0" gson = "2.9.0" guava = "33.0.0-jre" hilt = "2.50" hiltNavigationCompose = "1.1.0" junit = "4.13.2" -kotlin = "1.9.21" -ksp = "1.9.21-1.0.15" +kotlin = "1.9.22" +ksp = "1.9.22-1.0.17" # @keep ktlint = "0.40.0" ktx = "1.7.0" -lifecycle = "2.6.2" +lifecycle = "2.7.0" material = "1.8.0-rc01" -material3 = "1.2.0-beta01" +material3 = "1.2.0-rc01" # @keep minSdk = "24" monitor = "1.6.1" @@ -53,14 +53,14 @@ pagingCompose = "3.3.0-alpha02" profileInstaller = "1.3.1" retrofit = "2.9.0" room = "2.6.1" -spotless = "6.23.3" +spotless = "6.25.0" systemuicontroller = "0.32.0" # @keep targetSdk = "34" testExtJunit = "1.1.5" uiAutomator = "2.2.0" version-catalog-update = "0.8.3" -viewModelCompose = "2.6.2" +viewModelCompose = "2.7.0" work = "2.9.0" [libraries] @@ -70,13 +70,13 @@ androidx-activity-compose = { module = "androidx.activity:activity-compose", ver androidx-arch-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "coreTesting" } androidx-benchmark-macro-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "benchmark" } androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" } -androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "composeLatest" } -androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout", version.ref = "composeLatest" } +androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" } +androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" } androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" } -androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "composeLatest" } -androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata", version.ref = "composeLatest" } -androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "composeLatest" } -androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "composeLatest" } +androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" } +androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" } +androidx-compose-ui = { module = "androidx.compose.ui:ui" } +androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } androidx-compose-ui-viewbinding = { module = "androidx.compose.ui:ui-viewbinding" } From 5a92650283244061bfd2847f2311cf3c5c033887 Mon Sep 17 00:00:00 2001 From: Connor Haskins Date: Thu, 8 Feb 2024 08:49:26 -0800 Subject: [PATCH 05/12] Comment update in PlantDetailViewModel (#953) ViewModel is used in PlantDetailsScreen not PlantDetailFragment Probably missed during migration from Fragments to Compose --- .../samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt b/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt index 6f6d1dab7..50b1af201 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt @@ -30,7 +30,7 @@ import kotlinx.coroutines.launch import javax.inject.Inject /** - * The ViewModel used in [PlantDetailFragment]. + * The ViewModel used in [PlantDetailsScreen]. */ @HiltViewModel class PlantDetailViewModel @Inject constructor( @@ -64,4 +64,4 @@ class PlantDetailViewModel @Inject constructor( companion object { private const val PLANT_ID_SAVED_STATE_KEY = "plantId" } -} \ No newline at end of file +} From 3057663622623c51351f923c5d222e3ca6001fab Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Fri, 9 Feb 2024 01:21:24 -0800 Subject: [PATCH 06/12] Update secret used by update_deps workflow. (#954) Change-Id: I7ae56528ce0a741aec27aee76951790450176011 --- .github/workflows/update_deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_deps.yml b/.github/workflows/update_deps.yml index 7c5533d18..ab89ac6b7 100644 --- a/.github/workflows/update_deps.yml +++ b/.github/workflows/update_deps.yml @@ -41,7 +41,7 @@ jobs: id: cpr uses: peter-evans/create-pull-request@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.PAT }} commit-message: 🤖 Update Dependencies committer: compose-devrel-github-bot author: compose-devrel-github-bot From 5f60c94c531d49aeea390527bc61027ab6e8c8ef Mon Sep 17 00:00:00 2001 From: compose-devrel-github-bot <118755852+compose-devrel-github-bot@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:15:17 +0000 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=A4=96=20Update=20Dependencies=20(#?= =?UTF-8?q?955)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle/libs.versions.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bf5cd404c..fe06285c1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,7 +22,7 @@ benchmark = "1.2.3" compileSdk = "34" # @keep compose-compiler = "1.5.8" -composeBom = "2024.01.00" +composeBom = "2024.02.00" composeLatest = "1.7.0-alpha01" constraintLayoutCompose = "1.0.1" coreTesting = "2.2.0" @@ -47,19 +47,19 @@ material3 = "1.2.0-rc01" # @keep minSdk = "24" monitor = "1.6.1" -navigation = "2.7.6" +navigation = "2.7.7" okhttpLogging = "4.12.0" -pagingCompose = "3.3.0-alpha02" +pagingCompose = "3.3.0-alpha03" profileInstaller = "1.3.1" retrofit = "2.9.0" room = "2.6.1" spotless = "6.25.0" -systemuicontroller = "0.32.0" +systemuicontroller = "0.34.0" # @keep targetSdk = "34" testExtJunit = "1.1.5" uiAutomator = "2.2.0" -version-catalog-update = "0.8.3" +version-catalog-update = "0.8.4" viewModelCompose = "2.7.0" work = "2.9.0" From 9dc0ea02a90d77a2a9f25d85fbae4065cfca9f08 Mon Sep 17 00:00:00 2001 From: compose-devrel-github-bot <118755852+compose-devrel-github-bot@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:33:17 +0100 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=A4=96=20Update=20Dependencies=20(#?= =?UTF-8?q?958)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🤖 Update Dependencies * Fix build errors --------- Co-authored-by: Simona Milanovic --- gradle/libs.versions.toml | 26 ++++++++++++------------ gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fe06285c1..f843d04bf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,42 +14,42 @@ ## limitations under the License. ## [versions] -accessibilityTestFramework = "4.1.0" -activityCompose = "1.8.2" -androidGradlePlugin = "8.2.2" -benchmark = "1.2.3" +accessibilityTestFramework = "4.1.1" +activityCompose = "1.9.0" +androidGradlePlugin = "8.3.2" +benchmark = "1.2.4" # @keep compileSdk = "34" # @keep compose-compiler = "1.5.8" -composeBom = "2024.02.00" +composeBom = "2024.04.01" composeLatest = "1.7.0-alpha01" constraintLayoutCompose = "1.0.1" coreTesting = "2.2.0" -coroutines = "1.7.3" +coroutines = "1.8.0" espresso = "3.5.1" glide = "1.0.0-beta01" gradle = "7.2.0" gradle-versions = "0.51.0" gson = "2.9.0" -guava = "33.0.0-jre" -hilt = "2.50" -hiltNavigationCompose = "1.1.0" +guava = "33.1.0-jre" +hilt = "2.51.1" +hiltNavigationCompose = "1.2.0" junit = "4.13.2" kotlin = "1.9.22" ksp = "1.9.22-1.0.17" # @keep ktlint = "0.40.0" -ktx = "1.7.0" +ktx = "1.13.0" lifecycle = "2.7.0" material = "1.8.0-rc01" -material3 = "1.2.0-rc01" +material3 = "1.2.1" # @keep minSdk = "24" monitor = "1.6.1" navigation = "2.7.7" okhttpLogging = "4.12.0" -pagingCompose = "3.3.0-alpha03" +pagingCompose = "3.3.0-beta01" profileInstaller = "1.3.1" retrofit = "2.9.0" room = "2.6.1" @@ -58,7 +58,7 @@ systemuicontroller = "0.34.0" # @keep targetSdk = "34" testExtJunit = "1.1.5" -uiAutomator = "2.2.0" +uiAutomator = "2.3.0" version-catalog-update = "0.8.4" viewModelCompose = "2.7.0" work = "2.9.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7411f462c..fa9f05d61 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Jan 03 11:14:53 PST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 15898e5e5c2212cb7d174e6d182f92baee2d6cae Mon Sep 17 00:00:00 2001 From: compose-devrel-github-bot <118755852+compose-devrel-github-bot@users.noreply.github.com> Date: Thu, 2 May 2024 19:48:38 +0100 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=A4=96=20Update=20Dependencies=20(#?= =?UTF-8?q?967)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🤖 Update Dependencies * Update deps --------- Co-authored-by: Simona Milanovic --- gradle/libs.versions.toml | 20 ++++++++++---------- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f843d04bf..151b6f294 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,13 +16,13 @@ [versions] accessibilityTestFramework = "4.1.1" activityCompose = "1.9.0" -androidGradlePlugin = "8.3.2" +androidGradlePlugin = "8.4.0" benchmark = "1.2.4" # @keep compileSdk = "34" # @keep -compose-compiler = "1.5.8" -composeBom = "2024.04.01" +compose-compiler = "1.5.13" +composeBom = "2024.05.00" composeLatest = "1.7.0-alpha01" constraintLayoutCompose = "1.0.1" coreTesting = "2.2.0" @@ -31,27 +31,27 @@ espresso = "3.5.1" glide = "1.0.0-beta01" gradle = "7.2.0" gradle-versions = "0.51.0" -gson = "2.9.0" +gson = "2.10.1" guava = "33.1.0-jre" hilt = "2.51.1" hiltNavigationCompose = "1.2.0" junit = "4.13.2" -kotlin = "1.9.22" -ksp = "1.9.22-1.0.17" +kotlin = "1.9.23" +ksp = "1.9.23-1.0.20" # @keep ktlint = "0.40.0" -ktx = "1.13.0" +ktx = "1.13.1" lifecycle = "2.7.0" -material = "1.8.0-rc01" +material = "1.13.0-alpha01" material3 = "1.2.1" # @keep minSdk = "24" monitor = "1.6.1" navigation = "2.7.7" okhttpLogging = "4.12.0" -pagingCompose = "3.3.0-beta01" +pagingCompose = "3.3.0-rc01" profileInstaller = "1.3.1" -retrofit = "2.9.0" +retrofit = "2.11.0" room = "2.6.1" spotless = "6.25.0" systemuicontroller = "0.34.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fa9f05d61..f982653be 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Jan 03 11:14:53 PST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 8c93618a44bca9faf6219a0034a1103ec1f2b1d0 Mon Sep 17 00:00:00 2001 From: Anselmo Alexandre Date: Wed, 3 Jul 2024 05:21:57 +0200 Subject: [PATCH 10/12] Updated kotlin version and migrated compose compiler (#974) --- app/build.gradle.kts | 4 +--- build.gradle.kts | 1 + gradle/libs.versions.toml | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 51d6e0480..e4b1aaad4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -19,6 +19,7 @@ plugins { alias(libs.plugins.kotlin.android) alias(libs.plugins.ksp) alias(libs.plugins.hilt) + alias(libs.plugins.compose.compiler) } android { @@ -76,9 +77,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) diff --git a/build.gradle.kts b/build.gradle.kts index 1112b5044..dab44ce22 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 151b6f294..e99d05de7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -123,3 +123,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" } From 6ba253c1599eed5f19d790a29a1c209ddf66398c Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Wed, 3 Jul 2024 12:23:27 +0900 Subject: [PATCH 11/12] Remove duplicated buildFeatures. (#966) Co-authored-by: Ben Trengrove --- app/build.gradle.kts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e4b1aaad4..66b6a823d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -24,9 +24,7 @@ plugins { android { compileSdk = libs.versions.compileSdk.get().toInt() - buildFeatures { - dataBinding = true - } + defaultConfig { applicationId = "com.google.samples.apps.sunflower" minSdk = libs.versions.minSdk.get().toInt() From 2b60ca9beabe7030384d03eebddd339cf2a114ef Mon Sep 17 00:00:00 2001 From: Juho Park Date: Wed, 3 Jul 2024 13:04:28 +0900 Subject: [PATCH 12/12] Modify collectAsState to collectAsStateWithLifecycle (#976) Co-authored-by: Ben Trengrove --- app/build.gradle.kts | 1 + .../apps/sunflower/compose/garden/GardenScreen.kt | 4 ++-- .../compose/plantdetail/PlantDetailView.kt | 5 +++-- .../viewmodels/GardenPlantingListViewModel.kt | 15 ++++++++++++--- .../sunflower/viewmodels/PlantDetailViewModel.kt | 7 +++++++ gradle/libs.versions.toml | 1 + 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 66b6a823d..4a7ac33b6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -138,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) diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt index 642b52c2c..aa9b17f80 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt @@ -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 @@ -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 @@ -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, diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt index 0d8b12f24..20a36a7e2 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt @@ -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 @@ -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 @@ -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) { diff --git a/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/GardenPlantingListViewModel.kt b/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/GardenPlantingListViewModel.kt index f6acf5836..b97143cc4 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/GardenPlantingListViewModel.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/GardenPlantingListViewModel.kt @@ -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> = - gardenPlantingRepository.getPlantedGardens() + val plantAndGardenPlantings: StateFlow> = + gardenPlantingRepository + .getPlantedGardens() + .stateIn( + viewModelScope, + SharingStarted.WhileSubscribed(5000), + emptyList() + ) } \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt b/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt index 50b1af201..d3b581a88 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt @@ -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 @@ -42,6 +44,11 @@ class PlantDetailViewModel @Inject constructor( val plantId: String = savedStateHandle.get(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) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e99d05de7..a758a68b6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" }