From e5b2b22b03ef5e3d88a1b236564628e9fbd90594 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Fri, 13 May 2022 01:03:45 +0200 Subject: [PATCH 1/3] 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, From 1959ee53d2413c5a4220dfac45ffc7297451081b Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Tue, 17 May 2022 20:12:52 +0200 Subject: [PATCH 2/3] Replace Filled.Android with Filled.Person icon in InterestsIcon --- .../nowinandroid/feature/foryou/AuthorsCarousel.kt | 1 - .../nowinandroid/feature/interests/InterestsItem.kt | 12 +++++++----- 2 files changed, 7 insertions(+), 6 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 a56fc08bb..d5dbdbf72 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 @@ -30,7 +30,6 @@ 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 diff --git a/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt b/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt index b9c2afadd..8a615d6e7 100644 --- a/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt +++ b/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt @@ -16,6 +16,7 @@ package com.google.samples.apps.nowinandroid.feature.interests +import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -23,8 +24,8 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.material.icons.Icons.Filled -import androidx.compose.material.icons.filled.Android +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Person import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface @@ -105,10 +106,11 @@ private fun InterestContent(name: String, description: String, modifier: Modifie private fun InterestsIcon(topicImageUrl: String, modifier: Modifier = Modifier) { if (topicImageUrl.isEmpty()) { Icon( - imageVector = Filled.Android, - tint = Color.Magenta, - contentDescription = null, modifier = modifier + .background(MaterialTheme.colorScheme.surface) + .padding(4.dp), + imageVector = Icons.Filled.Person, + contentDescription = null, // decorative image ) } else { AsyncImage( From e917cd827c33c38272b942cbae0751c174fb1018 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Thu, 19 May 2022 21:01:31 +0200 Subject: [PATCH 3/3] Fix format violation Command: ./gradlew :feature-interests:spotlessApply --- .../samples/apps/nowinandroid/feature/interests/InterestsItem.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt b/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt index 8a615d6e7..ca1b03c71 100644 --- a/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt +++ b/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt @@ -33,7 +33,6 @@ import androidx.compose.material3.Text 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.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp