From e6ec3f1ce48ddc68e97aaad512ffe11ac3e5cc9b Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 23 Jun 2023 20:44:58 -0400 Subject: [PATCH] - Adds picture of the User to the Stream header. - BugFix for the Click on UserPicture event --- .../amethyst/ui/note/NoteCompose.kt | 28 +++++++++++++------ .../amethyst/ui/note/UserCompose.kt | 3 +- .../amethyst/ui/note/ZapNoteCompose.kt | 2 +- .../ui/screen/loggedIn/ChannelScreen.kt | 23 +++++++++++---- .../ui/screen/loggedIn/ProfileScreen.kt | 3 +- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index 17a215d6c..996cc6cb6 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -2935,10 +2935,10 @@ private fun DisplayBlankAuthor(size: Dp, modifier: Modifier) { @Composable fun UserPicture( user: User, - nav: (String) -> Unit, - accountViewModel: AccountViewModel, size: Dp, - pictureModifier: Modifier = Modifier + pictureModifier: Modifier = remember { Modifier }, + accountViewModel: AccountViewModel, + nav: (String) -> Unit ) { val route by remember { derivedStateOf { @@ -2946,9 +2946,19 @@ fun UserPicture( } } - ClickableUserPicture(user, size, accountViewModel, pictureModifier) { - nav(route) - } + val scope = rememberCoroutineScope() + + ClickableUserPicture( + baseUser = user, + size = size, + accountViewModel = accountViewModel, + modifier = pictureModifier, + onClick = { + scope.launch { + nav(route) + } + } + ) } @OptIn(ExperimentalFoundationApi::class) @@ -2991,7 +3001,7 @@ fun ClickableUserPicture( } Box(modifier = myModifier, contentAlignment = TopEnd) { - UserPicture(baseUser, size, accountViewModel, modifier) + BaseUserPicture(baseUser, size, accountViewModel, modifier) } } @@ -3007,12 +3017,12 @@ fun NonClickableUserPicture( } Box(myBoxModifier, contentAlignment = TopEnd) { - UserPicture(baseUser, size, accountViewModel, modifier) + BaseUserPicture(baseUser, size, accountViewModel, modifier) } } @Composable -fun UserPicture( +fun BaseUserPicture( baseUser: User, size: Dp, accountViewModel: AccountViewModel, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt index e16dc87fd..1fb6d116c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserCompose.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding import androidx.compose.material.Divider import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -39,7 +38,7 @@ fun UserCompose( modifier = overallModifier, verticalAlignment = Alignment.CenterVertically ) { - UserPicture(baseUser, nav, accountViewModel, 55.dp) + UserPicture(baseUser, 55.dp, accountViewModel = accountViewModel, nav = nav) Column(modifier = Modifier.padding(start = 10.dp).weight(1f)) { Row(verticalAlignment = Alignment.CenterVertically) { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt index cae2d2a01..82b3f4193 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ZapNoteCompose.kt @@ -106,7 +106,7 @@ private fun RenderZapNote( }, verticalAlignment = Alignment.CenterVertically ) { - UserPicture(baseAuthor, nav, accountViewModel, 55.dp) + UserPicture(baseAuthor, 55.dp, accountViewModel = accountViewModel, nav = nav) Column( modifier = remember { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt index 5a198f062..7f4f717fb 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt @@ -94,6 +94,7 @@ import com.vitorpamplona.amethyst.ui.components.VideoView import com.vitorpamplona.amethyst.ui.navigation.Route import com.vitorpamplona.amethyst.ui.note.ChatroomMessageCompose import com.vitorpamplona.amethyst.ui.note.LikeReaction +import com.vitorpamplona.amethyst.ui.note.UserPicture import com.vitorpamplona.amethyst.ui.note.ZapReaction import com.vitorpamplona.amethyst.ui.screen.NostrChannelFeedViewModel import com.vitorpamplona.amethyst.ui.screen.RefreshingChatroomFeedView @@ -518,7 +519,7 @@ fun ChannelHeader( accountViewModel: AccountViewModel, nav: (String) -> Unit ) { - var baseChannel by remember { mutableStateOf(LocalCache.channels[channelHex]) } + var baseChannel by remember { mutableStateOf(LocalCache.channels[channelHex]) } if (baseChannel == null) { LaunchedEffect(key1 = channelHex) { @@ -550,9 +551,11 @@ fun ChannelHeader( nav: (String) -> Unit ) { Column( - Modifier.fillMaxWidth().clickable { - nav("Channel/${baseChannel.idHex}") - } + Modifier + .fillMaxWidth() + .clickable { + nav("Channel/${baseChannel.idHex}") + } ) { val channelState by baseChannel.live.observeAsState() val channel = remember(channelState) { channelState?.channel } ?: return @@ -574,6 +577,15 @@ fun ChannelHeader( Column(modifier = modifier) { Row(verticalAlignment = Alignment.CenterVertically) { + channel.creator?.let { + UserPicture( + user = it, + size = Size35dp, + accountViewModel = accountViewModel, + nav = nav + ) + } + RobohashAsyncImageProxy( robot = channel.idHex, model = channel.profilePicture(), @@ -581,6 +593,7 @@ fun ChannelHeader( modifier = Modifier .width(Size35dp) .height(Size35dp) + .padding(start = 10.dp) .clip(shape = CircleShape) ) @@ -592,7 +605,7 @@ fun ChannelHeader( ) { Row(verticalAlignment = Alignment.CenterVertically) { Text( - channel.toBestDisplayName(), + channel.toBestDisplayName() + channel.idHex.split(":")[2], fontWeight = FontWeight.Bold, maxLines = 1, overflow = TextOverflow.Ellipsis diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt index fd34d3f90..f1529be8c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt @@ -104,7 +104,6 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import java.math.BigDecimal @Composable @@ -116,7 +115,7 @@ fun ProfileScreen(userId: String?, accountViewModel: AccountViewModel, nav: (Str if (userBase == null) { LaunchedEffect(userId) { // waits to resolve. - withContext(Dispatchers.IO) { + launch(Dispatchers.IO) { val newUserBase = LocalCache.checkGetOrCreateUser(userId) if (newUserBase != userBase) { userBase = newUserBase