Merge pull request #21 from SimonMarquis/fix/empty-author-item-image

Replace empty `AuthorItem`'s picture with `Icons.Filled.Person`
pull/60/head
Jolanda Verhoef 3 years ago committed by GitHub
commit b46f94a089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,7 @@
package com.google.samples.apps.nowinandroid.feature.foryou package com.google.samples.apps.nowinandroid.feature.foryou
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
@ -28,6 +29,9 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.selection.toggleable import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
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.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -95,15 +99,29 @@ fun AuthorItem(
stateDescription = "$followDescription ${author.name}" stateDescription = "$followDescription ${author.name}"
} }
) { ) {
Box(modifier = Modifier.fillMaxWidth()) { Box(
AsyncImage( modifier = Modifier.fillMaxWidth(),
modifier = Modifier contentAlignment = Alignment.Center,
.size(48.dp) ) {
.clip(CircleShape), val authorImageModifier = Modifier
model = author.imageUrl, .size(48.dp)
contentScale = ContentScale.Fit, .clip(CircleShape)
contentDescription = null 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( FollowButton(
following = following, following = following,
backgroundColor = MaterialTheme.colorScheme.surface, backgroundColor = MaterialTheme.colorScheme.surface,

@ -16,6 +16,7 @@
package com.google.samples.apps.nowinandroid.feature.interests package com.google.samples.apps.nowinandroid.feature.interests
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row 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.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons.Filled 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.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
@ -32,7 +33,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
@ -105,10 +105,11 @@ private fun InterestContent(name: String, description: String, modifier: Modifie
private fun InterestsIcon(topicImageUrl: String, modifier: Modifier = Modifier) { private fun InterestsIcon(topicImageUrl: String, modifier: Modifier = Modifier) {
if (topicImageUrl.isEmpty()) { if (topicImageUrl.isEmpty()) {
Icon( Icon(
imageVector = Filled.Android,
tint = Color.Magenta,
contentDescription = null,
modifier = modifier modifier = modifier
.background(MaterialTheme.colorScheme.surface)
.padding(4.dp),
imageVector = Icons.Filled.Person,
contentDescription = null, // decorative image
) )
} else { } else {
AsyncImage( AsyncImage(

Loading…
Cancel
Save