Normalizes the click to open relay info dialog
This commit is contained in:
+83
-68
@@ -47,13 +47,16 @@ 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.google.common.collect.Multimaps.index
|
||||||
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.components.SetDialogToEdgeToEdge
|
||||||
|
import com.vitorpamplona.amethyst.ui.navigation.EmptyNav.nav
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.INav
|
import com.vitorpamplona.amethyst.ui.navigation.INav
|
||||||
import com.vitorpamplona.amethyst.ui.note.buttons.CloseButton
|
import com.vitorpamplona.amethyst.ui.note.buttons.CloseButton
|
||||||
import com.vitorpamplona.amethyst.ui.note.buttons.SaveButton
|
import com.vitorpamplona.amethyst.ui.note.buttons.SaveButton
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.publicChannels.ephemChat.header.loadRelayInfo
|
||||||
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
|
||||||
@@ -84,8 +87,6 @@ fun RelaySelectionDialog(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
var relays by remember {
|
var relays by remember {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
accountViewModel.account.client.connectedRelayList().map {
|
accountViewModel.account.client.connectedRelayList().map {
|
||||||
@@ -99,18 +100,6 @@ fun RelaySelectionDialog(
|
|||||||
|
|
||||||
val hasSelectedRelay by remember { derivedStateOf { relays.any { it.isSelected } } }
|
val hasSelectedRelay by remember { derivedStateOf { relays.any { it.isSelected } } }
|
||||||
|
|
||||||
var relayInfo: RelayInfoDialog? by remember { mutableStateOf(null) }
|
|
||||||
|
|
||||||
relayInfo?.let {
|
|
||||||
RelayInformationDialog(
|
|
||||||
onClose = { relayInfo = null },
|
|
||||||
relayInfo = it.relayInfo,
|
|
||||||
relay = it.relay,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var selected by remember { mutableStateOf(true) }
|
var selected by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
@@ -156,7 +145,7 @@ fun RelaySelectionDialog(
|
|||||||
Modifier.padding(pad).padding(start = 10.dp, end = 10.dp, top = 10.dp),
|
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(R.string.select_deselect_all),
|
||||||
checked = selected,
|
checked = selected,
|
||||||
onClick = {
|
onClick = {
|
||||||
selected = !selected
|
selected = !selected
|
||||||
@@ -171,9 +160,8 @@ fun RelaySelectionDialog(
|
|||||||
relays,
|
relays,
|
||||||
key = { _, item -> item.relay },
|
key = { _, item -> item.relay },
|
||||||
) { index, item ->
|
) { index, item ->
|
||||||
RelaySwitch(
|
RenderRelaySwitch(
|
||||||
text = item.relay.displayUrl(),
|
item,
|
||||||
checked = item.isSelected,
|
|
||||||
onClick = {
|
onClick = {
|
||||||
relays =
|
relays =
|
||||||
relays.mapIndexed { j, item ->
|
relays.mapIndexed { j, item ->
|
||||||
@@ -184,56 +172,8 @@ fun RelaySelectionDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPress = {
|
accountViewModel,
|
||||||
accountViewModel.retrieveRelayDocument(
|
nav,
|
||||||
relay = item.relay,
|
|
||||||
onInfo = {
|
|
||||||
relayInfo =
|
|
||||||
RelayInfoDialog(
|
|
||||||
item.relay,
|
|
||||||
it,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onError = { relay, errorCode, exceptionMessage ->
|
|
||||||
val msg =
|
|
||||||
when (errorCode) {
|
|
||||||
Nip11Retriever.ErrorCode.FAIL_TO_ASSEMBLE_URL ->
|
|
||||||
stringRes(
|
|
||||||
context,
|
|
||||||
R.string.relay_information_document_error_assemble_url,
|
|
||||||
relay.url,
|
|
||||||
exceptionMessage,
|
|
||||||
)
|
|
||||||
Nip11Retriever.ErrorCode.FAIL_TO_REACH_SERVER ->
|
|
||||||
stringRes(
|
|
||||||
context,
|
|
||||||
R.string.relay_information_document_error_assemble_url,
|
|
||||||
relay.url,
|
|
||||||
exceptionMessage,
|
|
||||||
)
|
|
||||||
Nip11Retriever.ErrorCode.FAIL_TO_PARSE_RESULT ->
|
|
||||||
stringRes(
|
|
||||||
context,
|
|
||||||
R.string.relay_information_document_error_assemble_url,
|
|
||||||
relay.url,
|
|
||||||
exceptionMessage,
|
|
||||||
)
|
|
||||||
Nip11Retriever.ErrorCode.FAIL_WITH_HTTP_STATUS ->
|
|
||||||
stringRes(
|
|
||||||
context,
|
|
||||||
R.string.relay_information_document_error_assemble_url,
|
|
||||||
relay.url,
|
|
||||||
exceptionMessage,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountViewModel.toastManager.toast(
|
|
||||||
stringRes(context, R.string.unable_to_download_relay_document),
|
|
||||||
msg,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,6 +182,81 @@ fun RelaySelectionDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun RenderRelaySwitch(
|
||||||
|
item: RelayList,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: INav,
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val relayInfo by loadRelayInfo(item.relay, accountViewModel)
|
||||||
|
|
||||||
|
var openRelayDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (openRelayDialog) {
|
||||||
|
RelayInformationDialog(
|
||||||
|
onClose = { openRelayDialog = false },
|
||||||
|
relayInfo = relayInfo,
|
||||||
|
relay = item.relay,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
RelaySwitch(
|
||||||
|
text = item.relay.displayUrl(),
|
||||||
|
checked = item.isSelected,
|
||||||
|
onClick = onClick,
|
||||||
|
onLongPress = {
|
||||||
|
openRelayDialog = true
|
||||||
|
accountViewModel.retrieveRelayDocument(
|
||||||
|
relay = item.relay,
|
||||||
|
onInfo = { },
|
||||||
|
onError = { relay, errorCode, exceptionMessage ->
|
||||||
|
val msg =
|
||||||
|
when (errorCode) {
|
||||||
|
Nip11Retriever.ErrorCode.FAIL_TO_ASSEMBLE_URL ->
|
||||||
|
stringRes(
|
||||||
|
context,
|
||||||
|
R.string.relay_information_document_error_assemble_url,
|
||||||
|
relay.url,
|
||||||
|
exceptionMessage,
|
||||||
|
)
|
||||||
|
Nip11Retriever.ErrorCode.FAIL_TO_REACH_SERVER ->
|
||||||
|
stringRes(
|
||||||
|
context,
|
||||||
|
R.string.relay_information_document_error_assemble_url,
|
||||||
|
relay.url,
|
||||||
|
exceptionMessage,
|
||||||
|
)
|
||||||
|
Nip11Retriever.ErrorCode.FAIL_TO_PARSE_RESULT ->
|
||||||
|
stringRes(
|
||||||
|
context,
|
||||||
|
R.string.relay_information_document_error_assemble_url,
|
||||||
|
relay.url,
|
||||||
|
exceptionMessage,
|
||||||
|
)
|
||||||
|
Nip11Retriever.ErrorCode.FAIL_WITH_HTTP_STATUS ->
|
||||||
|
stringRes(
|
||||||
|
context,
|
||||||
|
R.string.relay_information_document_error_assemble_url,
|
||||||
|
relay.url,
|
||||||
|
exceptionMessage,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
accountViewModel.toastManager.toast(
|
||||||
|
stringRes(context, R.string.unable_to_download_relay_document),
|
||||||
|
msg,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun RelaySwitch(
|
fun RelaySwitch(
|
||||||
|
|||||||
+9
-12
@@ -244,15 +244,13 @@ fun RenderRelayLinePublicChat(
|
|||||||
var openRelayDialog by remember { mutableStateOf(false) }
|
var openRelayDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
if (openRelayDialog) {
|
if (openRelayDialog) {
|
||||||
relayInfo?.let {
|
RelayInformationDialog(
|
||||||
RelayInformationDialog(
|
onClose = { openRelayDialog = false },
|
||||||
onClose = { openRelayDialog = false },
|
relayInfo = relayInfo,
|
||||||
relayInfo = it,
|
relay = relay,
|
||||||
relay = relay,
|
accountViewModel = accountViewModel,
|
||||||
accountViewModel = accountViewModel,
|
nav = nav,
|
||||||
nav = nav,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = LocalClipboardManager.current
|
||||||
@@ -263,11 +261,10 @@ fun RenderRelayLinePublicChat(
|
|||||||
clipboardManager.setText(AnnotatedString(relay.url))
|
clipboardManager.setText(AnnotatedString(relay.url))
|
||||||
},
|
},
|
||||||
onClick = {
|
onClick = {
|
||||||
|
openRelayDialog = true
|
||||||
accountViewModel.retrieveRelayDocument(
|
accountViewModel.retrieveRelayDocument(
|
||||||
relay = relay,
|
relay = relay,
|
||||||
onInfo = {
|
onInfo = {},
|
||||||
openRelayDialog = true
|
|
||||||
},
|
|
||||||
onError = { relay, errorCode, exceptionMessage ->
|
onError = { relay, errorCode, exceptionMessage ->
|
||||||
accountViewModel.toastManager.toast(
|
accountViewModel.toastManager.toast(
|
||||||
R.string.unable_to_download_relay_document,
|
R.string.unable_to_download_relay_document,
|
||||||
|
|||||||
+11
-9
@@ -29,9 +29,9 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.FeatureSetType
|
import com.vitorpamplona.amethyst.model.FeatureSetType
|
||||||
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
||||||
import com.vitorpamplona.amethyst.ui.actions.RelayInfoDialog
|
|
||||||
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.chats.publicChannels.ephemChat.header.loadRelayInfo
|
||||||
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
|
||||||
|
|
||||||
@@ -42,14 +42,17 @@ fun BasicRelaySetupInfoDialog(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
) {
|
) {
|
||||||
var relayInfo: RelayInfoDialog? by remember { mutableStateOf(null) }
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
relayInfo?.let {
|
val relayInfo by loadRelayInfo(item.relay, accountViewModel)
|
||||||
|
|
||||||
|
var openRelayDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (openRelayDialog) {
|
||||||
RelayInformationDialog(
|
RelayInformationDialog(
|
||||||
onClose = { relayInfo = null },
|
onClose = { openRelayDialog = false },
|
||||||
relayInfo = it.relayInfo,
|
relayInfo = relayInfo,
|
||||||
relay = it.relay,
|
relay = item.relay,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav,
|
nav = nav,
|
||||||
)
|
)
|
||||||
@@ -62,11 +65,10 @@ fun BasicRelaySetupInfoDialog(
|
|||||||
onDelete = onDelete,
|
onDelete = onDelete,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
openRelayDialog = true
|
||||||
accountViewModel.retrieveRelayDocument(
|
accountViewModel.retrieveRelayDocument(
|
||||||
relay = item.relay,
|
relay = item.relay,
|
||||||
onInfo = {
|
onInfo = { },
|
||||||
relayInfo = RelayInfoDialog(item.relay, it)
|
|
||||||
},
|
|
||||||
onError = { relay, errorCode, exceptionMessage ->
|
onError = { relay, errorCode, exceptionMessage ->
|
||||||
val msg =
|
val msg =
|
||||||
when (errorCode) {
|
when (errorCode) {
|
||||||
|
|||||||
Reference in New Issue
Block a user