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

Commit

Permalink
Remove deprecated SunflowerImage Glide wrapper in favor of GlideImage…
Browse files Browse the repository at this point in the history
… composable.

The SunflowerImage() wrapper was introduced as a workaround for the issue bumptech/glide#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.
  • Loading branch information
sabiou committed Jan 2, 2024
1 parent 40be469 commit 36a044e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -117,7 +116,7 @@ private fun GardenList(
}

@OptIn(
ExperimentalMaterial3Api::class
ExperimentalGlideComposeApi::class
)
@Composable
private fun GardenListItem(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -293,6 +294,7 @@ private fun PlantDetailsContent(
}
}

@OptIn(ExperimentalGlideComposeApi::class)
@Composable
private fun PlantImage(
imageUrl: String,
Expand All @@ -315,7 +317,7 @@ private fun PlantImage(
.background(placeholderColor)
)
}
SunflowerImage(
GlideImage(
model = imageUrl,
contentDescription = null,
modifier = Modifier
Expand Down Expand Up @@ -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)
)
}
Expand Down Expand Up @@ -479,7 +481,7 @@ private fun PlantHeaderActions(
.then(iconModifier)
) {
Icon(
Icons.Filled.ArrowBack,
Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.a11y_back)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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(
Expand All @@ -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
Expand Down

This file was deleted.

0 comments on commit 36a044e

Please sign in to comment.