From efde14a3483a467ac03fd08ec00111da36d36847 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 28 Aug 2024 16:17:08 -0300 Subject: [PATCH 1/2] Show relay ping with the relay icon --- .../amethyst/ui/note/RelayListRow.kt | 58 ++++++++++++++++--- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt index c9c3bed9a..76b8c7b4b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt @@ -20,14 +20,18 @@ */ package com.vitorpamplona.amethyst.ui.note +import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ChevronRight import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -36,6 +40,10 @@ import androidx.compose.runtime.remember 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.text.TextStyle +import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.FeatureSetType @@ -54,6 +62,8 @@ import com.vitorpamplona.amethyst.ui.theme.StdStartPadding import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.relayIconModifier import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache +import com.vitorpamplona.ammolite.relays.RelayStats +import com.vitorpamplona.quartz.encoders.RelayUrlFormatter @Composable public fun RelayBadgesHorizontal( @@ -192,13 +202,43 @@ fun RenderRelayIcon( loadRobohash: Boolean, iconModifier: Modifier = MaterialTheme.colorScheme.relayIconModifier, ) { - RobohashFallbackAsyncImage( - robot = displayUrl, - model = iconUrl, - contentDescription = stringRes(id = R.string.relay_info, displayUrl), - colorFilter = RelayIconFilter, - modifier = iconModifier, - loadProfilePicture = loadProfilePicture, - loadRobohash = loadRobohash, - ) + Box( + contentAlignment = Alignment.TopEnd, + ) { + RobohashFallbackAsyncImage( + robot = displayUrl, + model = iconUrl, + contentDescription = stringRes(id = R.string.relay_info, displayUrl), + colorFilter = RelayIconFilter, + modifier = iconModifier, + loadProfilePicture = loadProfilePicture, + loadRobohash = loadRobohash, + ) + + Box( + modifier = + Modifier + .clip(RoundedCornerShape(8.dp)) + .background( + Color.Gray, + ), + ) { + val pingInMs = RelayStats.get(RelayUrlFormatter.normalize(displayUrl)).pingInMs + Text( + modifier = Modifier.padding(4.dp), + style = + TextStyle( + color = + if (pingInMs <= 150) { + Color.Green + } else if (pingInMs <= 300) { + Color.Yellow + } else { + Color.Red + }, + ), + text = "$pingInMs", + ) + } + } } From 06f37ab81d1428da37cf73b8b642faf2d5523326 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 28 Aug 2024 16:20:55 -0300 Subject: [PATCH 2/2] Fix relay icons when using complete ui --- .../relays/BasicRelaySetupInfoClickableRow.kt | 1 + .../ui/actions/relays/Kind3RelayListView.kt | 1 + .../relays/Kind3RelaySetupInfoProposalRow.kt | 1 + .../actions/relays/RelayInformationDialog.kt | 1 + .../amethyst/ui/note/RelayListRow.kt | 54 +++++++++---------- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoClickableRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoClickableRow.kt index eed6048c6..02625904e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoClickableRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoClickableRow.kt @@ -65,6 +65,7 @@ fun BasicRelaySetupInfoClickableRow( iconUrlFromRelayInfoDoc ?: item.briefInfo.favIcon, loadProfilePicture, loadRobohash, + item.relayStat.pingInMs, MaterialTheme.colorScheme.largeRelayIconModifier, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt index 60b3f6ae5..9b1ccebde 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt @@ -322,6 +322,7 @@ fun ClickableRelayItem( iconUrlFromRelayInfoDoc ?: item.briefInfo.favIcon, loadProfilePicture, loadRobohash, + item.relayStat.pingInMs, MaterialTheme.colorScheme.largeRelayIconModifier, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelaySetupInfoProposalRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelaySetupInfoProposalRow.kt index d9772a034..f40b29330 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelaySetupInfoProposalRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelaySetupInfoProposalRow.kt @@ -93,6 +93,7 @@ fun Kind3RelaySetupInfoProposalRow( iconUrlFromRelayInfoDoc ?: item.briefInfo.favIcon, loadProfilePicture, loadRobohash, + item.relayStat.pingInMs, MaterialTheme.colorScheme.largeRelayIconModifier, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt index ed8b0c643..8816ecbce 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt @@ -135,6 +135,7 @@ fun RelayInformationDialog( iconUrl = relayInfo.icon ?: relayBriefInfo.favIcon, loadProfilePicture = accountViewModel.settings.showProfilePictures.value, loadRobohash = accountViewModel.settings.featureSet != FeatureSetType.PERFORMANCE, + RelayStats.get(url = relayBriefInfo.url).pingInMs, iconModifier = MaterialTheme.colorScheme.largeRelayIconModifier, ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt index 76b8c7b4b..6fb0691fc 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt @@ -62,8 +62,6 @@ import com.vitorpamplona.amethyst.ui.theme.StdStartPadding import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.relayIconModifier import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache -import com.vitorpamplona.ammolite.relays.RelayStats -import com.vitorpamplona.quartz.encoders.RelayUrlFormatter @Composable public fun RelayBadgesHorizontal( @@ -189,6 +187,7 @@ fun RenderRelay( displayUrl = relay.displayUrl, iconUrl = relayInfo?.icon ?: relay.favIcon, loadProfilePicture = accountViewModel.settings.showProfilePictures.value, + pingInMs = 0, loadRobohash = accountViewModel.settings.featureSet != FeatureSetType.PERFORMANCE, ) } @@ -200,6 +199,7 @@ fun RenderRelayIcon( iconUrl: String?, loadProfilePicture: Boolean, loadRobohash: Boolean, + pingInMs: Long, iconModifier: Modifier = MaterialTheme.colorScheme.relayIconModifier, ) { Box( @@ -214,31 +214,31 @@ fun RenderRelayIcon( loadProfilePicture = loadProfilePicture, loadRobohash = loadRobohash, ) - - Box( - modifier = - Modifier - .clip(RoundedCornerShape(8.dp)) - .background( - Color.Gray, - ), - ) { - val pingInMs = RelayStats.get(RelayUrlFormatter.normalize(displayUrl)).pingInMs - Text( - modifier = Modifier.padding(4.dp), - style = - TextStyle( - color = - if (pingInMs <= 150) { - Color.Green - } else if (pingInMs <= 300) { - Color.Yellow - } else { - Color.Red - }, - ), - text = "$pingInMs", - ) + if (pingInMs > 0) { + Box( + modifier = + Modifier + .clip(RoundedCornerShape(8.dp)) + .background( + Color.Gray, + ), + ) { + Text( + modifier = Modifier.padding(4.dp), + style = + TextStyle( + color = + if (pingInMs <= 150) { + Color.Green + } else if (pingInMs <= 300) { + Color.Yellow + } else { + Color.Red + }, + ), + text = "$pingInMs", + ) + } } } }