From 9a00783cf8e24358f665b49b5f71fc75adc33b8e Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Thu, 28 Dec 2023 08:44:57 -0800 Subject: [PATCH] Update Glide implementation and item key ID. (#941) Change-Id: I3d9182d209ac85dc338f2b7b123b2a788e4453ed --- .../apps/sunflower/compose/gallery/GalleryScreen.kt | 3 +-- .../sunflower/compose/plantdetail/PlantDetailView.kt | 10 +++++----- .../apps/sunflower/compose/utils/SunflowerImage.kt | 10 ++++------ gradle/libs.versions.toml | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt index 3df1ffd7f..db8192378 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt @@ -107,14 +107,13 @@ private fun GalleryScreen( .padding(padding) .nestedScroll(pullToRefreshState.nestedScrollConnection) ) { - LazyVerticalGrid( columns = GridCells.Fixed(2), contentPadding = PaddingValues(all = dimensionResource(id = R.dimen.card_side_margin)) ) { items( count = pagingItems.itemCount, - key = pagingItems.itemKey { it } + key = pagingItems.itemKey { it.id } ) { index -> val photo = pagingItems[index] ?: return@items PhotoListItem(photo = photo) { 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 b290f4da5..f74e93cbe 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 @@ -326,7 +326,7 @@ private fun PlantImage( override fun onLoadFailed( e: GlideException?, model: Any?, - target: Target?, + target: Target, isFirstResource: Boolean ): Boolean { isLoading = false @@ -334,10 +334,10 @@ private fun PlantImage( } override fun onResourceReady( - resource: Drawable?, - model: Any?, + resource: Drawable, + model: Any, target: Target?, - dataSource: DataSource?, + dataSource: DataSource, isFirstResource: Boolean ): Boolean { isLoading = false @@ -596,4 +596,4 @@ private fun PlantDetailContentPreview() { ) } } -} \ No newline at end of file +} 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 index a1f57d20a..98881dd5d 100644 --- 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 @@ -22,12 +22,14 @@ 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 @@ -65,10 +67,6 @@ fun SunflowerImage( alpha = alpha, colorFilter = colorFilter, requestBuilderTransform = requestBuilderTransform, - loading = placeholder { - Box(modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { - CircularProgressIndicator(Modifier.size(40.dp)) - } - } + loading = placeholder(ColorPainter(MaterialTheme.colorScheme.secondary)) ) -} \ No newline at end of file +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5dedaf8c0..4ddb0b355 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,7 +27,7 @@ constraintLayoutCompose = "1.0.1" coreTesting = "2.2.0" coroutines = "1.6.4" espresso = "3.4.0" -glide = "1.0.0-alpha.3" +glide = "1.0.0-beta01" gradle = "7.2.0" gson = "2.9.0" guava = "31.1-android"