diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfo.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfo.kt index 22dc3db91..aba820179 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfo.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfo.kt @@ -55,7 +55,7 @@ data class Kind3RelayProposalSetupInfo( val feedTypes: Set, val relayStat: RelayStat, val paidRelay: Boolean = false, - val users: Set, + val users: List, ) { val briefInfo: RelayBriefInfoCache.RelayBriefInfo = RelayBriefInfoCache.RelayBriefInfo(url) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt index cce626c04..67f268894 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt @@ -164,7 +164,7 @@ class Kind3RelayListViewModel : ViewModel() { write = false, feedTypes = setOf(FeedType.FOLLOWS), relayStat = RelayStats.get(it.url), - users = it.users, + users = it.users.sorted(), ) } else { null 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 29c1211d5..5bf41ad5b 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 @@ -22,12 +22,14 @@ package com.vitorpamplona.amethyst.ui.actions.relays import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons @@ -40,21 +42,26 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.service.Nip11CachedRetriever +import com.vitorpamplona.amethyst.ui.components.mockAccountViewModel import com.vitorpamplona.amethyst.ui.note.AddRelayButton import com.vitorpamplona.amethyst.ui.note.RenderRelayIcon import com.vitorpamplona.amethyst.ui.note.UserPicture import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.HalfHorzPadding import com.vitorpamplona.amethyst.ui.theme.ReactionRowHeightChatMaxWidth import com.vitorpamplona.amethyst.ui.theme.Size25dp +import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn import com.vitorpamplona.amethyst.ui.theme.allGoodColor import com.vitorpamplona.amethyst.ui.theme.largeRelayIconModifier +import com.vitorpamplona.ammolite.relays.COMMON_FEED_TYPES +import com.vitorpamplona.ammolite.relays.RelayStat @OptIn(ExperimentalLayoutApi::class) @Composable @@ -111,24 +118,10 @@ fun Kind3RelaySetupInfoProposalRow( ) } } - - FlowRow(verticalArrangement = Arrangement.Center) { - item.users.take(3).forEach { - UserPicture( - userHex = it, - size = Size25dp, - accountViewModel = accountViewModel, - nav = nav, - ) - } - if (item.users.size > 3) { - Text( - text = stringResource(R.string.and_more), - ) - } - } } + UsedBy(item, accountViewModel, nav) + Column( Modifier .padding(start = 10.dp), @@ -140,3 +133,68 @@ fun Kind3RelaySetupInfoProposalRow( HorizontalDivider(thickness = DividerThickness) } } + +@Preview +@Composable +fun UsedByPreview() { + val accountViewModel = mockAccountViewModel() + ThemeComparisonColumn { + UsedBy( + item = + Kind3RelayProposalSetupInfo( + "wss://nos.lol", + true, + true, + COMMON_FEED_TYPES, + relayStat = RelayStat(), + paidRelay = false, + users = listOf("User1", "User2", "User3", "User4"), + ), + accountViewModel = accountViewModel, + ) { + } + } +} + +@OptIn(ExperimentalLayoutApi::class) +@Composable +fun UsedBy( + item: Kind3RelayProposalSetupInfo, + accountViewModel: AccountViewModel, + nav: (String) -> Unit, +) { + FlowRow(verticalArrangement = Arrangement.Center) { + item.users.getOrNull(0)?.let { + UserPicture( + userHex = it, + size = Size25dp, + accountViewModel = accountViewModel, + nav = nav, + ) + } + item.users.getOrNull(1)?.let { + UserPicture( + userHex = it, + size = Size25dp, + accountViewModel = accountViewModel, + nav = nav, + ) + } + item.users.getOrNull(2)?.let { + UserPicture( + userHex = it, + size = Size25dp, + accountViewModel = accountViewModel, + nav = nav, + ) + } + if (item.users.size > 3) { + Box(contentAlignment = Alignment.Center, modifier = Modifier.height(Size25dp)) { + Text( + text = stringRes(R.string.and_more, item.users.size - 3), + maxLines = 1, + ) + } + } + } +} diff --git a/amethyst/src/main/res/values-pl-rPL/strings.xml b/amethyst/src/main/res/values-pl-rPL/strings.xml index 1910474c2..6b14550d8 100644 --- a/amethyst/src/main/res/values-pl-rPL/strings.xml +++ b/amethyst/src/main/res/values-pl-rPL/strings.xml @@ -805,5 +805,5 @@ Dodaj serwer NIP-96 Usuń wszystko Czy na pewno chcesz usunąć wszystkie wersje robocze? - " ... i więcej" + " ... i %1$s więcej" diff --git a/amethyst/src/main/res/values-zh-rCN/strings.xml b/amethyst/src/main/res/values-zh-rCN/strings.xml index ca2e01273..bff4ac820 100644 --- a/amethyst/src/main/res/values-zh-rCN/strings.xml +++ b/amethyst/src/main/res/values-zh-rCN/strings.xml @@ -805,5 +805,5 @@ 添加 NIP-96 服务器 删除所有 确定要删除所有草稿吗? - " ... 和更多" + " ... 和 %1$s 更多" diff --git a/amethyst/src/main/res/values/strings.xml b/amethyst/src/main/res/values/strings.xml index b758d941e..ae003f70f 100644 --- a/amethyst/src/main/res/values/strings.xml +++ b/amethyst/src/main/res/values/strings.xml @@ -951,5 +951,5 @@ Add a NIP-96 Server Delete all Are you sure you want to delete all drafts? - " ... and more" + " ... and %1$s more"