mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 23:14:13 +02:00
add long press to show relay info, fix validation, show relay url without prefix
This commit is contained in:
@@ -107,7 +107,8 @@ fun NewMediaView(uri: Uri, onClose: () -> Unit, postViewModel: NewMediaModel, ac
|
|||||||
onPost = {
|
onPost = {
|
||||||
relayList = it
|
relayList = it
|
||||||
},
|
},
|
||||||
account = account
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -163,7 +163,8 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
|
|||||||
onPost = {
|
onPost = {
|
||||||
relayList = it
|
relayList = it
|
||||||
},
|
},
|
||||||
account = account
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.actions
|
package com.vitorpamplona.amethyst.ui.actions
|
||||||
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
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.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
@@ -26,8 +27,9 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
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.model.Account
|
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 kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
data class RelayList(
|
data class RelayList(
|
||||||
@@ -35,15 +37,22 @@ data class RelayList(
|
|||||||
val isSelected: Boolean
|
val isSelected: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun RelaySelectionDialog(list: List<Relay>, onClose: () -> Unit, onPost: (list: List<Relay>) -> Unit, account: Account) {
|
fun RelaySelectionDialog(
|
||||||
|
list: List<Relay>,
|
||||||
|
onClose: () -> Unit,
|
||||||
|
onPost: (list: List<Relay>) -> Unit,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: (String) -> Unit
|
||||||
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val relayList = account.activeRelays()?.filter {
|
val relayList = accountViewModel.account.activeRelays()?.filter {
|
||||||
it.write
|
it.write
|
||||||
}?.map {
|
}?.map {
|
||||||
it
|
it
|
||||||
} ?: account.convertLocalRelays().filter {
|
} ?: accountViewModel.account.convertLocalRelays().filter {
|
||||||
it.write
|
it.write
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +66,18 @@ fun RelaySelectionDialog(list: List<Relay>, onClose: () -> Unit, onPost: (list:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
var relayInfo: RelayInformation? by remember { mutableStateOf(null) }
|
||||||
|
|
||||||
|
if (relayInfo != null) {
|
||||||
|
RelayInformationDialog(
|
||||||
|
onClose = {
|
||||||
|
relayInfo = null
|
||||||
|
},
|
||||||
|
relayInfo = relayInfo!!,
|
||||||
|
accountViewModel,
|
||||||
|
nav
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = { onClose() },
|
onDismissRequest = { onClose() },
|
||||||
@@ -95,8 +116,8 @@ fun RelaySelectionDialog(list: List<Relay>, onClose: () -> Unit, onPost: (list:
|
|||||||
if (selectedRelays.isEmpty()) {
|
if (selectedRelays.isEmpty()) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
Toast.makeText(context, "Select a relay to continue", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "Select a relay to continue", Toast.LENGTH_SHORT).show()
|
||||||
return@launch
|
|
||||||
}
|
}
|
||||||
|
return@PostButton
|
||||||
}
|
}
|
||||||
onPost(selectedRelays.map { it.relay })
|
onPost(selectedRelays.map { it.relay })
|
||||||
onClose()
|
onClose()
|
||||||
@@ -120,7 +141,8 @@ fun RelaySelectionDialog(list: List<Relay>, onClose: () -> Unit, onPost: (list:
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable {
|
.combinedClickable(
|
||||||
|
onClick = {
|
||||||
relays = relays.mapIndexed { j, item ->
|
relays = relays.mapIndexed { j, item ->
|
||||||
if (index == j) {
|
if (index == j) {
|
||||||
item.copy(isSelected = !item.isSelected)
|
item.copy(isSelected = !item.isSelected)
|
||||||
@@ -128,9 +150,20 @@ fun RelaySelectionDialog(list: List<Relay>, onClose: () -> Unit, onPost: (list:
|
|||||||
item
|
item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onLongClick = {
|
||||||
|
loadRelayInfo(item.relay.url, context, scope) {
|
||||||
|
relayInfo = it
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
Text(text = item.relay.url)
|
Text(
|
||||||
|
item.relay.url
|
||||||
|
.removePrefix("ws://")
|
||||||
|
.removePrefix("wss://")
|
||||||
|
.removeSuffix("/")
|
||||||
|
)
|
||||||
Switch(
|
Switch(
|
||||||
checked = item.isSelected,
|
checked = item.isSelected,
|
||||||
onCheckedChange = {
|
onCheckedChange = {
|
||||||
|
Reference in New Issue
Block a user