Migrates Relay selection dialog to full bleed layout

This commit is contained in:
Vitor Pamplona
2025-04-28 20:58:23 -04:00
parent 96b1565de7
commit c07592f399
@@ -25,14 +25,16 @@ import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.Surface import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@@ -47,6 +49,7 @@ import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.window.DialogProperties
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.Nip11Retriever import com.vitorpamplona.amethyst.service.Nip11Retriever
import com.vitorpamplona.amethyst.ui.components.SetDialogToEdgeToEdge
import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.CloseButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.CloseButton
@@ -54,6 +57,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.SaveButton
import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.RelayInformationDialog import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.RelayInformationDialog
import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.FeedPadding import com.vitorpamplona.amethyst.ui.theme.FeedPadding
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache
import com.vitorpamplona.ammolite.relays.RelaySetupInfo import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.quartz.nip11RelayInfo.Nip11RelayInformation import com.vitorpamplona.quartz.nip11RelayInfo.Nip11RelayInformation
@@ -78,6 +82,22 @@ fun RelaySelectionDialog(
onPost: (list: ImmutableList<RelaySetupInfo>) -> Unit, onPost: (list: ImmutableList<RelaySetupInfo>) -> Unit,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) = RelaySelectionDialogEasy(
preSelectedList.map { it.url }.toImmutableList(),
onClose,
onPost,
accountViewModel,
nav,
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun RelaySelectionDialogEasy(
preSelectedList: ImmutableList<String>,
onClose: () -> Unit,
onPost: (list: ImmutableList<RelaySetupInfo>) -> Unit,
accountViewModel: AccountViewModel,
nav: INav,
) { ) {
val context = LocalContext.current val context = LocalContext.current
@@ -87,7 +107,7 @@ fun RelaySelectionDialog(
RelayList( RelayList(
relay = it, relay = it,
relayInfo = RelayBriefInfoCache.RelayBriefInfo(it.url), relayInfo = RelayBriefInfoCache.RelayBriefInfo(it.url),
isSelected = preSelectedList.any { relay -> it.url == relay.url }, isSelected = preSelectedList.any { relayUrl -> it.url == relayUrl },
) )
}, },
) )
@@ -118,22 +138,13 @@ fun RelaySelectionDialog(
decorFitsSystemWindows = false, decorFitsSystemWindows = false,
), ),
) { ) {
Surface( SetDialogToEdgeToEdge()
modifier = Modifier.fillMaxWidth().fillMaxHeight(),
) {
Column(
modifier =
Modifier.fillMaxWidth().fillMaxHeight().padding(start = 10.dp, end = 10.dp, top = 10.dp),
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
CloseButton(
onPress = { onClose() },
)
Scaffold(
modifier = Modifier.fillMaxSize(),
topBar = {
TopAppBar(
actions = {
SaveButton( SaveButton(
onPost = { onPost = {
val selectedRelays = relays.filter { it.isSelected } val selectedRelays = relays.filter { it.isSelected }
@@ -142,8 +153,24 @@ fun RelaySelectionDialog(
}, },
isActive = hasSelectedRelay, isActive = hasSelectedRelay,
) )
Spacer(modifier = StdHorzSpacer)
},
title = {},
navigationIcon = {
Row {
Spacer(modifier = StdHorzSpacer)
CloseButton(
onPress = { onClose() },
)
} }
},
)
},
) { pad ->
Column(
modifier =
Modifier.padding(pad).padding(start = 10.dp, end = 10.dp, top = 10.dp),
) {
RelaySwitch( RelaySwitch(
text = stringRes(context, R.string.select_deselect_all), text = stringRes(context, R.string.select_deselect_all),
checked = selected, checked = selected,