diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-10-07 19:11:06 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-10-07 19:11:06 +0530 |
commit | f2ab436c54a452d0c6264a8fdc16e80c0a4bbd03 (patch) | |
tree | e47c3af9c204669953d49575b1b86ea69ba3f5d4 | |
parent | cb373db35d3bb9b1beeae07e9d16c30e9b197c10 (diff) |
feat(app): make `DecryptScreen` properly standalone
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/crypto/DecryptScreen.kt | 64 | ||||
-rw-r--r-- | ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt | 5 |
2 files changed, 47 insertions, 22 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/crypto/DecryptScreen.kt b/app/src/main/java/app/passwordstore/ui/crypto/DecryptScreen.kt index 469cb4d2..41687985 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/DecryptScreen.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/DecryptScreen.kt @@ -3,9 +3,12 @@ package app.passwordstore.ui.crypto import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TextField 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.text.AnnotatedString import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp import app.passwordstore.R 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.totp.UriTotpFinder import kotlin.time.ExperimentalTime @@ -32,28 +38,42 @@ fun PasswordEntryScreen( entry: PasswordEntry, modifier: Modifier = Modifier, ) { - val clipboard = LocalClipboardManager.current - Box(modifier = modifier.fillMaxSize()) { - Column { - Text(entryName) - 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)) } } + Scaffold( + topBar = { + APSAppBar( + title = "", + navigationIcon = painterResource(R.drawable.ic_arrow_back_black_24dp), + onNavigationIconClick = {}, + backgroundColor = MaterialTheme.colorScheme.surface, + ) + }, + ) { paddingValues -> + val clipboard = LocalClipboardManager.current + Box(modifier = modifier.fillMaxSize().padding(paddingValues)) { + Column(modifier = Modifier.padding(8.dp)) { + Text( + text = entryName, + style = MaterialTheme.typography.headlineSmall, ) + 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 @Composable private fun PasswordEntryPreview() { - PasswordEntryScreen("Test Entry", createTestEntry()) + APSThemePreview { PasswordEntryScreen("Test Entry", createTestEntry()) } } fun createTestEntry() = diff --git a/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt index 695ff6cc..b11aa7c1 100644 --- a/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt +++ b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt @@ -70,3 +70,8 @@ public fun APSTheme( ) { MaterialTheme(colorScheme = colors, typography = AppTypography, content = content) } + +@Composable +public fun APSThemePreview(content: @Composable () -> Unit) { + MaterialTheme(colorScheme = LightThemeColors, typography = AppTypography, content = content) +} |