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 f74e93cbe..d700dbf32 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 @@ -86,13 +86,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 @@ -122,7 +123,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), @@ -293,6 +294,7 @@ private fun PlantDetailsContent( } } +@OptIn(ExperimentalGlideComposeApi::class) @Composable private fun PlantImage( imageUrl: String, @@ -315,7 +317,7 @@ private fun PlantImage( .background(placeholderColor) ) } - SunflowerImage( + GlideImage( model = imageUrl, contentDescription = null, modifier = Modifier @@ -416,7 +418,7 @@ private fun PlantDetailsToolbar( Modifier.align(Alignment.CenterVertically) ) { Icon( - Icons.Filled.ArrowBack, + Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(id = R.string.a11y_back) ) } @@ -479,7 +481,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)) - ) -}