Skip to content

Commit

Permalink
Merge branch 'issue/self-hosted-user-avatar' of https://github.com/wo…
Browse files Browse the repository at this point in the history
…rdpress-mobile/WordPress-Android into issue/self-hosted-user-detail

Conflicts:
	WordPress/src/main/java/org/wordpress/android/ui/selfhostedusers/SelfHostedUsersViewModel.kt
  • Loading branch information
nbradbury committed Oct 2, 2024
2 parents 282e451 + aeab663 commit a6d9dec
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wordpress.android.ui.selfhostedusers

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -33,7 +35,10 @@ import org.wordpress.android.ui.compose.theme.M3Theme
import uniffi.wp_api.UserWithEditContext

@Composable
fun UserAvatar(user: UserWithEditContext) {
fun UserAvatar(
user: UserWithEditContext,
onUserAvatarClick: ((UserWithEditContext) -> Unit)? = null,
) {
val avatarUrl = user.avatarUrls?.values?.firstOrNull() ?: ""
if (avatarUrl.isEmpty()) {
Icon(
Expand All @@ -44,6 +49,13 @@ fun UserAvatar(user: UserWithEditContext) {
.size(48.dp)
)
} else {
val extraModifier = if (onUserAvatarClick != null) {
Modifier.clickable {
onUserAvatarClick(user)
}
} else {
Modifier
}
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(avatarUrl)
Expand All @@ -54,11 +66,30 @@ fun UserAvatar(user: UserWithEditContext) {
contentDescription = null,
modifier = Modifier
.clip(CircleShape)
.size(48.dp),
)
.size(48.dp)
.then(
extraModifier
)
)
}
}

@Composable
fun UserLargeAvatar(avatarUrl: String) {
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
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
)
}

@Composable
fun UserEmptyView(emptyText: String) {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class SelfHostedUsersActivity : LocaleAwareActivity() {
},
onUserClick = { user ->
viewModel.onUserClick(user)
},
onUserAvatarClick = { user ->
viewModel.onUserAvatarClick(user)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ fun SelfHostedUsersScreen(
uiState: StateFlow<SelfHostedUsersViewModel.SelfHostedUserState>,
onCloseClick: () -> Unit = {},
onUserClick: (UserWithEditContext) -> Unit = {},
onUserAvatarClick: (UserWithEditContext) -> Unit = {},
) {
val state = uiState.collectAsState().value

val title = when(state) {
is SelfHostedUsersViewModel.SelfHostedUserState.UserDetail -> state.user.name
is SelfHostedUsersViewModel.SelfHostedUserState.UserAvatar -> ""
else -> stringResource(R.string.users)
}

val closeIcon = when(state) {
is SelfHostedUsersViewModel.SelfHostedUserState.UserDetail -> Icons.Default.Close
is SelfHostedUsersViewModel.SelfHostedUserState.UserAvatar -> Icons.Default.Close
else -> Icons.AutoMirrored.Filled.ArrowBack
}

Expand Down Expand Up @@ -73,8 +76,15 @@ fun SelfHostedUsersScreen(
UserEmptyView(stringResource(R.string.no_users))
}

is SelfHostedUsersViewModel.SelfHostedUserState.UserAvatar -> {
UserLargeAvatar(state.avatarUrl)
}

is SelfHostedUsersViewModel.SelfHostedUserState.UserDetail -> {
UserDetail(state.user)
UserDetail(
state.user,
onUserAvatarClick
)
}

is SelfHostedUsersViewModel.SelfHostedUserState.Offline -> {
Expand Down Expand Up @@ -148,14 +158,18 @@ private fun UserLazyRow(
@Composable
private fun UserDetail(
user: UserWithEditContext,
onUserAvatarClick: (UserWithEditContext) -> Unit = {},
) {
Row(
modifier = Modifier
.padding(all = userScreenPaddingDp)
.fillMaxWidth()
) {
Column {
UserAvatar(user)
UserAvatar(
user,
onUserAvatarClick
)
}

Column(
Expand Down

0 comments on commit a6d9dec

Please sign in to comment.