add decrypt content button to the details screen

This commit is contained in:
greenart7c3
2024-01-08 08:43:38 -03:00
parent b502c45765
commit c079620bb4
6 changed files with 38 additions and 3 deletions
@@ -104,7 +104,9 @@ fun EncryptDecryptData(
RawJson(
content,
Modifier.weight(1f),
stringResource(R.string.encrypted_decrypted_data)
stringResource(R.string.encrypted_decrypted_data),
type,
onCopy
) {
clipboardManager.setText(AnnotatedString(onCopy()))
@@ -23,6 +23,7 @@ import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.service.model.AmberEvent
import com.vitorpamplona.quartz.events.Event
@@ -35,6 +36,7 @@ fun EventData(
applicationName: String?,
event: Event,
rawJson: String,
type: SignerType,
onAccept: () -> Unit,
onReject: () -> Unit
) {
@@ -85,7 +87,7 @@ fun EventData(
if (!showMore) stringResource(R.string.show_details) else stringResource(R.string.hide_details)
)
if (showMore) {
RawJson(rawJson, Modifier.weight(1f))
RawJson(rawJson, Modifier.weight(1f), type = type)
} else {
Spacer(modifier = Modifier.weight(1f))
}
@@ -8,7 +8,11 @@ import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
@@ -16,6 +20,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.TextFieldValue
import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.ui.theme.ButtonBorder
import kotlinx.coroutines.launch
@@ -24,19 +29,41 @@ fun RawJson(
rawJson: String,
modifier: Modifier,
label: String = stringResource(R.string.copy_raw_json),
type: SignerType,
onDecrypt: (() -> String)? = null,
onCopy: (() -> Unit)? = null
) {
val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current
val clipboardManager = LocalClipboardManager.current
var currentContent by remember {
mutableStateOf(rawJson)
}
OutlinedTextField(
modifier = modifier
.fillMaxWidth(),
value = TextFieldValue(rawJson),
value = TextFieldValue(currentContent),
onValueChange = { },
readOnly = true
)
if (type == SignerType.NIP04_DECRYPT || type == SignerType.NIP44_DECRYPT) {
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Button(
shape = ButtonBorder,
onClick = {
if (onDecrypt != null) {
currentContent = onDecrypt()
}
}
) {
Text(stringResource(R.string.decrypt_content))
}
}
}
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
@@ -197,6 +197,7 @@ fun SingleEventHomeScreen(
applicationName,
event,
intentData.data,
intentData.type,
{
if (event.pubKey != account.keyPair.pubKey.toHexKey()) {
coroutineScope.launch {
@@ -9,6 +9,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.models.TimeUtils
import com.greenart7c3.nostrsigner.ui.components.EventData
import com.greenart7c3.nostrsigner.ui.theme.NostrSignerTheme
@@ -35,6 +36,7 @@ fun EventDataPreview() {
null,
event,
data,
SignerType.SIGN_EVENT,
{ },
{ }
)
+1
View File
@@ -66,4 +66,5 @@
<string name="go_to_top">go to top</string>
<string name="event_copied_to_the_clipboard">Event copied to the clipboard</string>
<string name="select_deselect_all">Select/Deselect all</string>
<string name="decrypt_content">Decrypt content</string>
</resources>