feat(app): refactor CopyButton and add missing spacing

This commit is contained in:
Harsh Shandilya 2022-10-08 18:35:16 +05:30
parent 5dd7c91038
commit 224d956e28
No known key found for this signature in database

View file

@ -49,15 +49,20 @@ fun PasswordEntryScreen(
) )
}, },
) { paddingValues -> ) { paddingValues ->
val clipboard = LocalClipboardManager.current
Box(modifier = modifier.fillMaxSize().padding(paddingValues)) { Box(modifier = modifier.fillMaxSize().padding(paddingValues)) {
Column(modifier = Modifier.padding(8.dp)) { Column(modifier = Modifier.padding(8.dp)) {
Text( Text(
text = entryName, text = entryName,
style = MaterialTheme.typography.headlineSmall, style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(bottom = 8.dp),
) )
if (entry.password != null) { if (entry.password != null) {
PasswordField(value = entry.password!!, label = "Password", initialVisibility = false) PasswordField(
value = entry.password!!,
label = "Password",
initialVisibility = false,
modifier = Modifier.padding(bottom = 8.dp),
)
} }
if (entry.hasTotp()) { if (entry.hasTotp()) {
val totp by entry.totp.collectAsState(runBlocking { entry.totp.first() }) val totp by entry.totp.collectAsState(runBlocking { entry.totp.first() })
@ -66,7 +71,8 @@ fun PasswordEntryScreen(
onValueChange = {}, onValueChange = {},
readOnly = true, readOnly = true,
label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") }, label = { Text("OTP (expires in ${totp.remainingTime.inWholeSeconds}s)") },
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(totp.value)) } } trailingIcon = { CopyButton({ totp.value }) },
modifier = Modifier.padding(bottom = 8.dp),
) )
} }
if (entry.username != null) { if (entry.username != null) {
@ -75,7 +81,8 @@ fun PasswordEntryScreen(
onValueChange = {}, onValueChange = {},
readOnly = true, readOnly = true,
label = { Text("Username") }, label = { Text("Username") },
trailingIcon = { CopyButton { clipboard.setText(AnnotatedString(entry.username!!)) } }, trailingIcon = { CopyButton({ entry.username!! }) },
modifier = Modifier.padding(bottom = 8.dp),
) )
} }
} }
@ -84,9 +91,14 @@ fun PasswordEntryScreen(
} }
@Composable @Composable
private fun CopyButton(onClick: () -> Unit) { private fun CopyButton(
textToCopy: () -> String,
modifier: Modifier = Modifier,
) {
val clipboard = LocalClipboardManager.current
IconButton( IconButton(
onClick = onClick, onClick = { clipboard.setText(AnnotatedString(textToCopy())) },
modifier = modifier,
) { ) {
Icon( Icon(
painter = painterResource(R.drawable.ic_content_copy), painter = painterResource(R.drawable.ic_content_copy),