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 c9c3bed9a..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 @@ -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 @@ -179,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, ) } @@ -190,15 +199,46 @@ fun RenderRelayIcon( iconUrl: String?, loadProfilePicture: Boolean, loadRobohash: Boolean, + pingInMs: Long, 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, + ) + 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", + ) + } + } + } }