Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit f2ab436

Browse files
committed
feat(app): make DecryptScreen properly standalone
1 parent cb373db commit f2ab436

File tree

2 files changed

+47
-22
lines changed
  • app/src/main/java/app/passwordstore/ui/crypto
  • ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme

2 files changed

+47
-22
lines changed

app/src/main/java/app/passwordstore/ui/crypto/DecryptScreen.kt

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package app.passwordstore.ui.crypto
33
import androidx.compose.foundation.layout.Box
44
import androidx.compose.foundation.layout.Column
55
import androidx.compose.foundation.layout.fillMaxSize
6+
import androidx.compose.foundation.layout.padding
67
import androidx.compose.material3.ExperimentalMaterial3Api
78
import androidx.compose.material3.Icon
89
import androidx.compose.material3.IconButton
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Scaffold
912
import androidx.compose.material3.Text
1013
import androidx.compose.material3.TextField
1114
import androidx.compose.runtime.Composable
@@ -17,8 +20,11 @@ import androidx.compose.ui.res.painterResource
1720
import androidx.compose.ui.res.stringResource
1821
import androidx.compose.ui.text.AnnotatedString
1922
import androidx.compose.ui.tooling.preview.Preview
23+
import androidx.compose.ui.unit.dp
2024
import app.passwordstore.R
2125
import app.passwordstore.data.passfile.PasswordEntry
26+
import app.passwordstore.ui.APSAppBar
27+
import app.passwordstore.ui.compose.theme.APSThemePreview
2228
import app.passwordstore.util.time.UserClock
2329
import app.passwordstore.util.totp.UriTotpFinder
2430
import kotlin.time.ExperimentalTime
@@ -32,28 +38,42 @@ fun PasswordEntryScreen(
3238
entry: PasswordEntry,
3339
modifier: Modifier = Modifier,
3440
) {
35-
val clipboard = LocalClipboardManager.current
36-
Box(modifier = modifier.fillMaxSize()) {
37-
Column {
38-
Text(entryName)
39-
if (entry.password != null) {
40-
TextField(
41-
value = entry.password!!,
42-
onValueChange = {},
43-
readOnly = true,
44-
label = { Text("Password") },
45-
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(entry.password!!)) } },
46-
)
47-
}
48-
if (entry.hasTotp()) {
49-
val totp by entry.totp.collectAsState(runBlocking { entry.totp.first() })
50-
TextField(
51-
value = totp.value,
52-
onValueChange = {},
53-
readOnly = true,
54-
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
55-
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(totp.value)) } }
41+
Scaffold(
42+
topBar = {
43+
APSAppBar(
44+
title = "",
45+
navigationIcon = painterResource(R.drawable.ic_arrow_back_black_24dp),
46+
onNavigationIconClick = {},
47+
backgroundColor = MaterialTheme.colorScheme.surface,
48+
)
49+
},
50+
) { paddingValues ->
51+
val clipboard = LocalClipboardManager.current
52+
Box(modifier = modifier.fillMaxSize().padding(paddingValues)) {
53+
Column(modifier = Modifier.padding(8.dp)) {
54+
Text(
55+
text = entryName,
56+
style = MaterialTheme.typography.headlineSmall,
5657
)
58+
if (entry.password != null) {
59+
TextField(
60+
value = entry.password!!,
61+
onValueChange = {},
62+
readOnly = true,
63+
label = { Text("Password") },
64+
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(entry.password!!)) } },
65+
)
66+
}
67+
if (entry.hasTotp()) {
68+
val totp by entry.totp.collectAsState(runBlocking { entry.totp.first() })
69+
TextField(
70+
value = totp.value,
71+
onValueChange = {},
72+
readOnly = true,
73+
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
74+
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(totp.value)) } }
75+
)
76+
}
5777
}
5878
}
5979
}
@@ -74,7 +94,7 @@ private fun CopyButton(onClick: () -> Unit) {
7494
@Preview
7595
@Composable
7696
private fun PasswordEntryPreview() {
77-
PasswordEntryScreen("Test Entry", createTestEntry())
97+
APSThemePreview { PasswordEntryScreen("Test Entry", createTestEntry()) }
7898
}
7999

80100
fun createTestEntry() =

ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ public fun APSTheme(
7070
) {
7171
MaterialTheme(colorScheme = colors, typography = AppTypography, content = content)
7272
}
73+
74+
@Composable
75+
public fun APSThemePreview(content: @Composable () -> Unit) {
76+
MaterialTheme(colorScheme = LightThemeColors, typography = AppTypography, content = content)
77+
}

0 commit comments

Comments
 (0)