From 4515bfa375c64e8a69df3691c9236a4ab3f58b10 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Fri, 24 Apr 2026 01:14:53 +0200 Subject: [PATCH] Show profile avatars on search --- .../compose/database/model/Profile.kt | 6 ++- .../compose/ui/composable/SearchScreen.kt | 45 ++++++++++--------- .../widgets/detail/MetadataEventDetail.kt | 2 +- .../widgets/profile/ProfileAvatar.kt | 7 ++- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/Profile.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/Profile.kt index e0d7a1d7..eaae1b96 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/Profile.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/Profile.kt @@ -74,7 +74,11 @@ data class Profile( override val broadcastedAt: Instant? = null, ): NostrEventEntity, TimestampedEntity, LocalStoreEntity, UserViewableEntity, BroadcastableEntity, SoftDeletableEntity { fun humanReadableNameOrPubkey(): String { - return displayName ?: userName ?: nip05 ?: twitter ?: publicKey + return displayName ?: userName ?: lud16 ?: nip05 ?: twitter ?: publicKey + } + + fun staticIdentifier(): String { + return lud16 ?: nip05 ?: "" } @Composable diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/SearchScreen.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/SearchScreen.kt index c2762d30..3e0ab86d 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/SearchScreen.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/SearchScreen.kt @@ -5,6 +5,7 @@ import ac.cord.auxiliary.compose.repository.SearchRepository import ac.cord.auxiliary.compose.ui.composable.navigation.routes.NostrEventDetailRoute import ac.cord.auxiliary.compose.ui.composable.navigation.routes.Route import ac.cord.auxiliary.compose.ui.composable.navigation.routes.SearchResultRoute +import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileAvatar import ac.cord.auxiliary.compose.ui.theme.AuxTheme import ac.cord.auxiliary.compose.ui.view.model.SearchViewModel import ac.cord.auxiliary.compose.ui.view.state.SearchUIState @@ -21,6 +22,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.text.input.rememberTextFieldState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBackIosNew @@ -52,6 +54,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.semantics.isTraversalGroup import androidx.compose.ui.semantics.semantics @@ -221,25 +224,27 @@ fun SearchScreen( ) } - itemsIndexed(searchViewModel.filteredProfiles) { index, profile -> + items( + items = searchViewModel.filteredProfiles + ) { profile -> ListItem( - headlineContent = { Text(profile.humanReadableNameOrPubkey()) }, + headlineContent = { + Text( + profile.humanReadableNameOrPubkey(), + maxLines = 1, + ) + }, supportingContent = { - Text("Profile") + Text( + text = profile.staticIdentifier(), + maxLines = 1, + ) }, leadingContent = { - IconButton( - onClick = { - onNavigateToProfile.invoke( - NostrEventDetailRoute(profile.nostrEventId) - ) - } - ) { - Icon( - Icons.Default.Person, - contentDescription = "Person" - ) - } + ProfileAvatar( + profile = profile, + publicKey = profile.publicKey + ) }, modifier = Modifier .clickable { @@ -274,7 +279,7 @@ fun SearchScreen( LazyRow { items(searchViewModel.searchableProfiles) { profile -> - val profileName = profile.displayName ?: profile.userName ?: profile.nip05 ?: profile.nostrEventId + val profileName = profile.humanReadableNameOrPubkey() Column( modifier = Modifier.padding(10.dp).width(70.dp), horizontalAlignment = Alignment.CenterHorizontally, @@ -291,10 +296,10 @@ fun SearchScreen( ) } ) { - Icon( - modifier = Modifier.size(70.dp), - imageVector = Icons.Default.Person, - contentDescription = profileName + ProfileAvatar( + size = 70.dp, + profile = profile, + publicKey = profile.publicKey ) } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt index 1414be75..f98a54cf 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt @@ -152,7 +152,7 @@ fun MetadataEventDetail( verticalAlignment = Alignment.CenterVertically ) { ProfileAvatar( - modifier = Modifier.size(75.dp).clip(shape = CircleShape), + size = 75.dp, profile = profile, publicKey = localNostrEvent.nostrEvent.pubKey ) diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt index 9ea507de..aafb6816 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt @@ -17,19 +17,24 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import coil3.compose.AsyncImage import kotlin.math.abs @Composable fun ProfileAvatar( - modifier: Modifier = Modifier.size(55.dp).clip(shape = CircleShape), + size: Dp = 55.dp, + shape: Shape = CircleShape, publicKey: String, profile: Profile? ) { + val modifier = Modifier.size(size).clip(shape = shape) + val tintColor = Color.hsl( hue = abs( publicKey.hashCode()