From 0fafc7bf5b8470fcf3b2b33bf37401aeb1999127 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Thu, 26 Sep 2024 14:51:43 -0400 Subject: [PATCH] Moved avatar to it's own composable --- .../ui/selfhostedusers/UserListScreen.kt | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/UserListScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/UserListScreen.kt index e4fc17607747..40890283f310 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/UserListScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/UserListScreen.kt @@ -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 @@ -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(