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

Commit 224d956

Browse files
committed
feat(app): refactor CopyButton and add missing spacing
1 parent 5dd7c91 commit 224d956

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ fun PasswordEntryScreen(
4949
)
5050
},
5151
) { paddingValues ->
52-
val clipboard = LocalClipboardManager.current
5352
Box(modifier = modifier.fillMaxSize().padding(paddingValues)) {
5453
Column(modifier = Modifier.padding(8.dp)) {
5554
Text(
5655
text = entryName,
5756
style = MaterialTheme.typography.headlineSmall,
57+
modifier = Modifier.padding(bottom = 8.dp),
5858
)
5959
if (entry.password != null) {
60-
PasswordField(value = entry.password!!, label = "Password", initialVisibility = false)
60+
PasswordField(
61+
value = entry.password!!,
62+
label = "Password",
63+
initialVisibility = false,
64+
modifier = Modifier.padding(bottom = 8.dp),
65+
)
6166
}
6267
if (entry.hasTotp()) {
6368
val totp by entry.totp.collectAsState(runBlocking { entry.totp.first() })
@@ -66,7 +71,8 @@ fun PasswordEntryScreen(
6671
onValueChange = {},
6772
readOnly = true,
6873
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
69-
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(totp.value)) } }
74+
trailingIcon = { CopyButton({ totp.value }) },
75+
modifier = Modifier.padding(bottom = 8.dp),
7076
)
7177
}
7278
if (entry.username != null) {
@@ -75,7 +81,8 @@ fun PasswordEntryScreen(
7581
onValueChange = {},
7682
readOnly = true,
7783
label = { Text("Username") },
78-
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(entry.username!!)) } },
84+
trailingIcon = { CopyButton({ entry.username!! }) },
85+
modifier = Modifier.padding(bottom = 8.dp),
7986
)
8087
}
8188
}
@@ -84,9 +91,14 @@ fun PasswordEntryScreen(
8491
}
8592

8693
@Composable
87-
private fun CopyButton(onClick: () -> Unit) {
94+
private fun CopyButton(
95+
textToCopy: () -> String,
96+
modifier: Modifier = Modifier,
97+
) {
98+
val clipboard = LocalClipboardManager.current
8899
IconButton(
89-
onClick = onClick,
100+
onClick = { clipboard.setText(AnnotatedString(textToCopy())) },
101+
modifier = modifier,
90102
) {
91103
Icon(
92104
painter = painterResource(R.drawable.ic_content_copy),

0 commit comments

Comments
 (0)