feat(app): make DecryptScreen properly standalone

This commit is contained in:
Harsh Shandilya 2022-10-07 19:11:06 +05:30
parent cb373db35d
commit f2ab436c54
No known key found for this signature in database
2 changed files with 47 additions and 22 deletions

View file

@ -3,9 +3,12 @@ package app.passwordstore.ui.crypto
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -17,8 +20,11 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import app.passwordstore.R import app.passwordstore.R
import app.passwordstore.data.passfile.PasswordEntry import app.passwordstore.data.passfile.PasswordEntry
import app.passwordstore.ui.APSAppBar
import app.passwordstore.ui.compose.theme.APSThemePreview
import app.passwordstore.util.time.UserClock import app.passwordstore.util.time.UserClock
import app.passwordstore.util.totp.UriTotpFinder import app.passwordstore.util.totp.UriTotpFinder
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
@ -32,28 +38,42 @@ fun PasswordEntryScreen(
entry: PasswordEntry, entry: PasswordEntry,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val clipboard = LocalClipboardManager.current Scaffold(
Box(modifier = modifier.fillMaxSize()) { topBar = {
Column { APSAppBar(
Text(entryName) title = "",
if (entry.password != null) { navigationIcon = painterResource(R.drawable.ic_arrow_back_black_24dp),
TextField( onNavigationIconClick = {},
value = entry.password!!, backgroundColor = MaterialTheme.colorScheme.surface,
onValueChange = {}, )
readOnly = true, },
label = { Text("Password") }, ) { paddingValues ->
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(entry.password!!)) } }, val clipboard = LocalClipboardManager.current
) Box(modifier = modifier.fillMaxSize().padding(paddingValues)) {
} Column(modifier = Modifier.padding(8.dp)) {
if (entry.hasTotp()) { Text(
val totp by entry.totp.collectAsState(runBlocking { entry.totp.first() }) text = entryName,
TextField( style = MaterialTheme.typography.headlineSmall,
value = totp.value,
onValueChange = {},
readOnly = true,
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(totp.value)) } }
) )
if (entry.password != null) {
TextField(
value = entry.password!!,
onValueChange = {},
readOnly = true,
label = { Text("Password") },
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(entry.password!!)) } },
)
}
if (entry.hasTotp()) {
val totp by entry.totp.collectAsState(runBlocking { entry.totp.first() })
TextField(
value = totp.value,
onValueChange = {},
readOnly = true,
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(totp.value)) } }
)
}
} }
} }
} }
@ -74,7 +94,7 @@ private fun CopyButton(onClick: () -> Unit) {
@Preview @Preview
@Composable @Composable
private fun PasswordEntryPreview() { private fun PasswordEntryPreview() {
PasswordEntryScreen("Test Entry", createTestEntry()) APSThemePreview { PasswordEntryScreen("Test Entry", createTestEntry()) }
} }
fun createTestEntry() = fun createTestEntry() =

View file

@ -70,3 +70,8 @@ public fun APSTheme(
) { ) {
MaterialTheme(colorScheme = colors, typography = AppTypography, content = content) MaterialTheme(colorScheme = colors, typography = AppTypography, content = content)
} }
@Composable
public fun APSThemePreview(content: @Composable () -> Unit) {
MaterialTheme(colorScheme = LightThemeColors, typography = AppTypography, content = content)
}