From e5b2b22b03ef5e3d88a1b236564628e9fbd90594 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Fri, 13 May 2022 01:03:45 +0200 Subject: [PATCH] Replace empty `AuthorItem`'s picture with `Icons.Filled.Person` Duplicated from `NewsResourceAuthors`. Fixes #20 --- .../feature/foryou/AuthorsCarousel.kt | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt index df6b8bbda..a56fc08bb 100644 --- a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt +++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt @@ -16,6 +16,7 @@ package com.google.samples.apps.nowinandroid.feature.foryou +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -28,6 +29,10 @@ import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.selection.toggleable import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Android +import androidx.compose.material.icons.filled.Person +import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -95,15 +100,29 @@ fun AuthorItem( stateDescription = "$followDescription ${author.name}" } ) { - Box(modifier = Modifier.fillMaxWidth()) { - AsyncImage( - modifier = Modifier - .size(48.dp) - .clip(CircleShape), - model = author.imageUrl, - contentScale = ContentScale.Fit, - contentDescription = null - ) + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.Center, + ) { + val authorImageModifier = Modifier + .size(48.dp) + .clip(CircleShape) + if (author.imageUrl.isEmpty()) { + Icon( + modifier = authorImageModifier + .background(MaterialTheme.colorScheme.surface) + .padding(4.dp), + imageVector = Icons.Filled.Person, + contentDescription = null // decorative image + ) + } else { + AsyncImage( + modifier = authorImageModifier, + model = author.imageUrl, + contentScale = ContentScale.Fit, + contentDescription = null + ) + } FollowButton( following = following, backgroundColor = MaterialTheme.colorScheme.surface,