diff --git a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUserComposables.kt b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUserComposables.kt index 4c239cac4c08..6c73964e91a1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUserComposables.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUserComposables.kt @@ -32,30 +32,32 @@ import coil.compose.AsyncImage import coil.request.ImageRequest import org.wordpress.android.R import org.wordpress.android.ui.compose.theme.M3Theme -import uniffi.wp_api.UserWithEditContext @Composable fun UserAvatar( - user: UserWithEditContext, - onUserAvatarClick: ((UserWithEditContext) -> Unit)? = null, + avatarUrl: String?, + onAvatarClick: ((String?) -> Unit)? = null, ) { - val avatarUrl = user.avatarUrls?.values?.firstOrNull() ?: "" - if (avatarUrl.isEmpty()) { + val extraModifier = if (onAvatarClick != null) { + Modifier.clickable { + onAvatarClick(avatarUrl) + } + } else { + Modifier + } + + if (avatarUrl.isNullOrEmpty()) { Icon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_user_placeholder_primary_24), contentDescription = null, tint = MaterialTheme.colorScheme.onSurface, modifier = Modifier .size(48.dp) + .then( + extraModifier + ) ) } else { - val extraModifier = if (onUserAvatarClick != null) { - Modifier.clickable { - onUserAvatarClick(user) - } - } else { - Modifier - } AsyncImage( model = ImageRequest.Builder(LocalContext.current) .data(avatarUrl) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersActivity.kt index 5a1fdb157adc..29425a069574 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersActivity.kt @@ -48,8 +48,8 @@ class SelfHostedUsersActivity : LocaleAwareActivity() { onUserClick = { user -> viewModel.onUserClick(user) }, - onUserAvatarClick = { user -> - viewModel.onUserAvatarClick(user) + onUserAvatarClick = { avatarUrl -> + viewModel.onUserAvatarClick(avatarUrl) } ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersScreen.kt index 4d4a1056b5a7..06c3d2b6ab5f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersScreen.kt @@ -35,7 +35,7 @@ fun SelfHostedUsersScreen( uiState: StateFlow, onCloseClick: () -> Unit = {}, onUserClick: (UserWithEditContext) -> Unit = {}, - onUserAvatarClick: (UserWithEditContext) -> Unit = {}, + onUserAvatarClick: (avatarUrl: String?) -> Unit = {}, ) { val state = uiState.collectAsState().value @@ -126,7 +126,7 @@ private fun UserLazyRow( .clickable { onUserClick(user) } ) { item { - UserAvatar(user) + UserAvatar(user.avatarUrls?.values?.firstOrNull()) } item { @@ -159,7 +159,7 @@ private fun UserLazyRow( @Composable private fun UserDetail( user: UserWithEditContext, - onUserAvatarClick: (UserWithEditContext) -> Unit = {}, + onAvatarClick: (String?) -> Unit = {}, ) { Row( modifier = Modifier @@ -168,8 +168,8 @@ private fun UserDetail( ) { Column { UserAvatar( - user, - onUserAvatarClick + avatarUrl = user.avatarUrls?.values?.firstOrNull(), + onAvatarClick = onAvatarClick ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersViewModel.kt index cab7dd48200a..23ac93d2de1b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersViewModel.kt @@ -76,9 +76,9 @@ class SelfHostedUsersViewModel @Inject constructor( /** * Called when the avatar of a user is clicked in the detail screen */ - fun onUserAvatarClick(user: UserWithEditContext) { - user.avatarUrls?.values?.firstOrNull()?.let { avatarUrl -> - _uiState.value = SelfHostedUserState.UserAvatar(avatarUrl) + fun onUserAvatarClick(avatarUrl: String?) { + avatarUrl?.let { + _uiState.value = SelfHostedUserState.UserAvatar(it) } }