diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2023-07-05 14:20:22 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2023-07-05 14:24:35 +0530 |
commit | fa03ca0ad7e556e60a13a355cbbd44675c135f88 (patch) | |
tree | f498644dab8590e626c10a3763eab48868dda4d3 /ui-compose/src/main/kotlin | |
parent | 4c28098cbb682c99a0a4983c70671e3f872de211 (diff) |
feat(ui): add a dedicated Compose screen for editing passwords
Diffstat (limited to 'ui-compose/src/main/kotlin')
-rw-r--r-- | ui-compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt index ee202486..d2a04777 100644 --- a/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt +++ b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt @@ -1,5 +1,6 @@ package app.passwordstore.ui.compose +import androidx.annotation.StringRes import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text @@ -10,7 +11,10 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.VisualTransformation @@ -19,8 +23,8 @@ public fun PasswordField( value: String, label: String, initialVisibility: Boolean, - readOnly: Boolean, modifier: Modifier = Modifier, + readOnly: Boolean = false, ) { var visible by remember { mutableStateOf(initialVisibility) } TextField( @@ -58,3 +62,21 @@ private fun ToggleButton( ) } } + +@Composable +public fun CopyButton( + textToCopy: String, + @StringRes buttonLabelRes: Int, + modifier: Modifier = Modifier, +) { + val clipboard = LocalClipboardManager.current + IconButton( + onClick = { clipboard.setText(AnnotatedString(textToCopy)) }, + modifier = modifier, + ) { + Icon( + painter = painterResource(R.drawable.ic_content_copy), + contentDescription = stringResource(buttonLabelRes), + ) + } +} |