Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Replace empty `AuthorItem`'s picture with `Icons.Filled.Person`

Simon Marquise5b2b22b03ef
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,