Presenting a Drop Down menu to copy keys and channel IDs.

This commit is contained in:
Vitor Pamplona
2023-02-01 14:05:59 -03:00
parent c3c19ebb49
commit 912ca72d68
2 changed files with 40 additions and 6 deletions

View File

@@ -15,6 +15,8 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Divider import androidx.compose.material.Divider
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.LocalTextStyle import androidx.compose.material.LocalTextStyle
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
@@ -63,6 +65,7 @@ import com.vitorpamplona.amethyst.ui.actions.NewPostView
import com.vitorpamplona.amethyst.ui.actions.PostButton import com.vitorpamplona.amethyst.ui.actions.PostButton
import com.vitorpamplona.amethyst.ui.navigation.Route import com.vitorpamplona.amethyst.ui.navigation.Route
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import nostr.postr.toNpub
@Composable @Composable
fun ChannelScreen(channelId: String?, accountViewModel: AccountViewModel, accountStateViewModel: AccountStateViewModel, navController: NavController) { fun ChannelScreen(channelId: String?, accountViewModel: AccountViewModel, accountStateViewModel: AccountStateViewModel, navController: NavController) {
@@ -214,10 +217,11 @@ private fun NoteCopyButton(
note: Channel note: Channel
) { ) {
val clipboardManager = LocalClipboardManager.current val clipboardManager = LocalClipboardManager.current
var popupExpanded by remember { mutableStateOf(false) }
Button( Button(
modifier = Modifier.padding(horizontal = 3.dp).width(50.dp), modifier = Modifier.padding(horizontal = 3.dp).width(50.dp),
onClick = { clipboardManager.setText(AnnotatedString(note.id.toNote())) }, onClick = { popupExpanded = true },
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
colors = ButtonDefaults colors = ButtonDefaults
.buttonColors( .buttonColors(
@@ -229,6 +233,15 @@ private fun NoteCopyButton(
imageVector = Icons.Default.Share, imageVector = Icons.Default.Share,
contentDescription = "Copies the Note ID to the clipboard for sharing" contentDescription = "Copies the Note ID to the clipboard for sharing"
) )
DropdownMenu(
expanded = popupExpanded,
onDismissRequest = { popupExpanded = false }
) {
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(note.id.toNote())); popupExpanded = false }) {
Text("Copy Channel ID (Note) to the Clipboard")
}
}
} }
} }

View File

@@ -34,6 +34,7 @@ import androidx.compose.material.TabRowDefaults
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.EditNote import androidx.compose.material.icons.filled.EditNote
import androidx.compose.material.icons.filled.Key
import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Password import androidx.compose.material.icons.filled.Password
import androidx.compose.material.icons.filled.Share import androidx.compose.material.icons.filled.Share
@@ -377,23 +378,33 @@ private fun NSecCopyButton(
account: Account account: Account
) { ) {
val clipboardManager = LocalClipboardManager.current val clipboardManager = LocalClipboardManager.current
var popupExpanded by remember { mutableStateOf(false) }
Button( Button(
modifier = Modifier modifier = Modifier
.padding(horizontal = 3.dp) .padding(horizontal = 3.dp)
.width(50.dp), .width(50.dp),
onClick = { account.loggedIn.privKey?.let { clipboardManager.setText(AnnotatedString(it.toNsec())) } }, onClick = { popupExpanded = true },
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
colors = ButtonDefaults colors = ButtonDefaults
.buttonColors( .buttonColors(
backgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) backgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
), )
) { ) {
Icon( Icon(
tint = Color.White, tint = Color.White,
imageVector = Icons.Default.Password, imageVector = Icons.Default.Key,
contentDescription = "Copies the Nsec ID (your password) to the clipboard for backup" contentDescription = "Copies the Nsec ID (your password) to the clipboard for backup"
) )
DropdownMenu(
expanded = popupExpanded,
onDismissRequest = { popupExpanded = false }
) {
DropdownMenuItem(onClick = { account.loggedIn.privKey?.let { clipboardManager.setText(AnnotatedString(it.toNsec())) }; popupExpanded = false }) {
Text("Copy Private Key to the Clipboard")
}
}
} }
} }
@@ -402,12 +413,13 @@ private fun NPubCopyButton(
user: User user: User
) { ) {
val clipboardManager = LocalClipboardManager.current val clipboardManager = LocalClipboardManager.current
var popupExpanded by remember { mutableStateOf(false) }
Button( Button(
modifier = Modifier modifier = Modifier
.padding(horizontal = 3.dp) .padding(horizontal = 3.dp)
.width(50.dp), .width(50.dp),
onClick = { clipboardManager.setText(AnnotatedString(user.pubkey.toNpub())) }, onClick = { popupExpanded = true },
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
colors = ButtonDefaults colors = ButtonDefaults
.buttonColors( .buttonColors(
@@ -417,8 +429,17 @@ private fun NPubCopyButton(
Icon( Icon(
tint = Color.White, tint = Color.White,
imageVector = Icons.Default.Share, imageVector = Icons.Default.Share,
contentDescription = "Copies the Note ID to the clipboard for sharing" contentDescription = "Copies the public key to the clipboard for sharing"
) )
DropdownMenu(
expanded = popupExpanded,
onDismissRequest = { popupExpanded = false }
) {
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(user.pubkey.toNpub())); popupExpanded = false }) {
Text("Copy Public Key (NPub) to the Clipboard")
}
}
} }
} }