From 5137009f5f3ce23865fe44bb7359fd598e463b6f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 23 Jun 2023 11:36:50 -0400 Subject: [PATCH] Improves rendering time of the Channel header --- .../ui/screen/loggedIn/ChannelScreen.kt | 69 ++++++++----------- 1 file changed, 27 insertions(+), 42 deletions(-) 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 836ada65a..87b3ef89c 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 @@ -517,11 +517,10 @@ fun ChannelHeader( nav: (String) -> Unit ) { var baseChannel by remember { mutableStateOf(LocalCache.channels[channelHex]) } - val scope = rememberCoroutineScope() if (baseChannel == null) { LaunchedEffect(key1 = channelHex) { - scope.launch(Dispatchers.IO) { + launch(Dispatchers.IO) { baseChannel = LocalCache.checkGetOrCreateChannel(channelHex) } } @@ -548,30 +547,26 @@ fun ChannelHeader( accountViewModel: AccountViewModel, nav: (String) -> Unit ) { - val channelState by baseChannel.live.observeAsState() - val channel = remember(channelState) { channelState?.channel } ?: return - - val context = LocalContext.current.applicationContext - Column( - Modifier.clickable { + Modifier.fillMaxWidth().clickable { nav("Channel/${baseChannel.idHex}") } ) { - if (channel is LiveActivitiesChannel) { - val streamingUrl by remember(channelState) { - derivedStateOf { - channel.info?.streaming() - } - } + val channelState by baseChannel.live.observeAsState() + val channel = remember(channelState) { channelState?.channel } ?: return - if (streamingUrl != null && showVideo) { - Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.heightIn(max = 300.dp)) { - VideoView( - videoUri = streamingUrl!!, - description = null - ) - } + val streamingUrl by remember(channelState) { + derivedStateOf { + (channel as? LiveActivitiesChannel)?.info?.streaming() + } + } + + if (streamingUrl != null && showVideo) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = remember { Modifier.heightIn(max = 300.dp) }) { + VideoView( + videoUri = streamingUrl!!, + description = null + ) } } @@ -580,7 +575,7 @@ fun ChannelHeader( RobohashAsyncImageProxy( robot = channel.idHex, model = channel.profilePicture(), - contentDescription = context.getString(R.string.profile_image), + contentDescription = stringResource(R.string.profile_image), modifier = Modifier .width(Size35dp) .height(Size35dp) @@ -681,35 +676,25 @@ private fun LiveChannelActionOptions( accountViewModel: AccountViewModel, nav: (String) -> Unit ) { - val isMe by remember(accountViewModel) { - derivedStateOf { - channel.creator == accountViewModel.account.userProfile() - } - } - val isLive by remember(channel) { derivedStateOf { channel.info?.status() == "live" } } - if (isMe) { - // EditButton(accountViewModel, channel) - } else { - val note = remember(channel.idHex) { - LocalCache.getNoteIfExists(channel.idHex) - } + val note = remember(channel.idHex) { + LocalCache.getNoteIfExists(channel.idHex) + } - note?.let { - if (isLive) { - LiveFlag() - Spacer(modifier = StdHorzSpacer) - } - - LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) + note?.let { + if (isLive) { + LiveFlag() Spacer(modifier = StdHorzSpacer) - ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) } + + LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) + Spacer(modifier = StdHorzSpacer) + ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel) } }