Skip to content

Commit

Permalink
Moved avatar to it's own composable
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Sep 26, 2024
1 parent 6feee8b commit 0fafc7b
Showing 1 changed file with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,7 @@ fun UserRow(user: UserWithEditContext) {
modifier = Modifier.align(Alignment.CenterVertically)
) {
val avatarUrl = user.avatarUrls?.values?.firstOrNull()
if (avatarUrl.isNullOrEmpty()) {
Icon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_user_placeholder_primary_24),
contentDescription = null,
tint = MaterialTheme.colorScheme.outline,
modifier = Modifier
.size(48.dp)
)
} else {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(avatarUrl)
.error(R.drawable.ic_user_placeholder_primary_24)
.crossfade(true)
.build(),
contentScale = ContentScale.Fit,
contentDescription = null,
modifier = Modifier
.size(48.dp)
)
}
UserAvatar(avatarUrl)
}
Column(
modifier = Modifier
Expand Down Expand Up @@ -145,6 +125,31 @@ fun UserRow(user: UserWithEditContext) {
}
}

@Composable
private fun UserAvatar(avatarUrl: String?) {
if (avatarUrl.isNullOrEmpty()) {
Icon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_user_placeholder_primary_24),
contentDescription = null,
tint = MaterialTheme.colorScheme.outline,
modifier = Modifier
.size(48.dp)
)
} else {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(avatarUrl)
.error(R.drawable.ic_user_placeholder_primary_24)
.crossfade(true)
.build(),
contentScale = ContentScale.Fit,
contentDescription = null,
modifier = Modifier
.size(48.dp)
)
}
}

@Composable
private fun EmptyView() {
Column(
Expand Down

0 comments on commit 0fafc7b

Please sign in to comment.