mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-11 00:15:08 +02:00
add select all switch, fix switch not clickable when relay name is too long
This commit is contained in:
@@ -24,9 +24,11 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
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.model.RelayInformation
|
import com.vitorpamplona.amethyst.model.RelayInformation
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
@@ -79,6 +81,10 @@ fun RelaySelectionDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selected by remember {
|
||||||
|
mutableStateOf(true)
|
||||||
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = { onClose() },
|
onDismissRequest = { onClose() },
|
||||||
properties = DialogProperties(
|
properties = DialogProperties(
|
||||||
@@ -126,6 +132,17 @@ fun RelaySelectionDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RelaySwitch(
|
||||||
|
text = stringResource(R.string.select_deselect_all),
|
||||||
|
checked = selected,
|
||||||
|
onClick = {
|
||||||
|
selected = !selected
|
||||||
|
relays = relays.mapIndexed { j, item ->
|
||||||
|
item.copy(isSelected = selected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
contentPadding = PaddingValues(
|
contentPadding = PaddingValues(
|
||||||
top = 10.dp,
|
top = 10.dp,
|
||||||
@@ -136,12 +153,12 @@ fun RelaySelectionDialog(
|
|||||||
relays,
|
relays,
|
||||||
key = { _, item -> item.relay.url }
|
key = { _, item -> item.relay.url }
|
||||||
) { index, item ->
|
) { index, item ->
|
||||||
Row(
|
RelaySwitch(
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
text = item.relay.url
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
.removePrefix("ws://")
|
||||||
modifier = Modifier
|
.removePrefix("wss://")
|
||||||
.fillMaxWidth()
|
.removeSuffix("/"),
|
||||||
.combinedClickable(
|
checked = item.isSelected,
|
||||||
onClick = {
|
onClick = {
|
||||||
relays = relays.mapIndexed { j, item ->
|
relays = relays.mapIndexed { j, item ->
|
||||||
if (index == j) {
|
if (index == j) {
|
||||||
@@ -151,33 +168,40 @@ fun RelaySelectionDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongClick = {
|
onLongPress = {
|
||||||
loadRelayInfo(item.relay.url, context, scope) {
|
loadRelayInfo(item.relay.url, context, scope) {
|
||||||
relayInfo = it
|
relayInfo = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
item.relay.url
|
|
||||||
.removePrefix("ws://")
|
|
||||||
.removePrefix("wss://")
|
|
||||||
.removeSuffix("/")
|
|
||||||
)
|
|
||||||
Switch(
|
|
||||||
checked = item.isSelected,
|
|
||||||
onCheckedChange = {
|
|
||||||
relays = relays.mapIndexed { j, item ->
|
|
||||||
if (index == j) {
|
|
||||||
item.copy(isSelected = !item.isSelected)
|
|
||||||
} else { item }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun RelaySwitch(text: String, checked: Boolean, onClick: () -> Unit, onLongPress: () -> Unit = { }) {
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.combinedClickable(
|
||||||
|
onClick = onClick,
|
||||||
|
onLongClick = onLongPress
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
text = text
|
||||||
|
)
|
||||||
|
Switch(
|
||||||
|
checked = checked,
|
||||||
|
onCheckedChange = {
|
||||||
|
onClick()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -506,4 +506,5 @@
|
|||||||
<string name="nip05_verified">Nostr address was verified</string>
|
<string name="nip05_verified">Nostr address was verified</string>
|
||||||
<string name="nip05_failed">Nostr address failed verification</string>
|
<string name="nip05_failed">Nostr address failed verification</string>
|
||||||
<string name="nip05_checking">Checking Nostr address</string>
|
<string name="nip05_checking">Checking Nostr address</string>
|
||||||
|
<string name="select_deselect_all">Select/Deselect all</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user