Skip to content

Commit

Permalink
add decrypt content button to the details screen
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed Jan 8, 2024
1 parent b502c45 commit c079620
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -35,6 +36,7 @@ fun EventData(
applicationName: String?,
event: Event,
rawJson: String,
type: SignerType,
onAccept: () -> Unit,
onReject: () -> Unit
) {
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ 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
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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ fun SingleEventHomeScreen(
applicationName,
event,
intentData.data,
intentData.type,
{
if (event.pubKey != account.keyPair.pubKey.toHexKey()) {
coroutineScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +36,7 @@ fun EventDataPreview() {
null,
event,
data,
SignerType.SIGN_EVENT,
{ },
{ }
)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit c079620

Please sign in to comment.