diff options
Diffstat (limited to 'ui-compose')
-rw-r--r-- | ui-compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt | 24 | ||||
-rw-r--r-- | ui-compose/src/main/res/drawable/ic_content_copy.xml | 15 |
2 files changed, 38 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), + ) + } +} diff --git a/ui-compose/src/main/res/drawable/ic_content_copy.xml b/ui-compose/src/main/res/drawable/ic_content_copy.xml new file mode 100644 index 00000000..8afc9846 --- /dev/null +++ b/ui-compose/src/main/res/drawable/ic_content_copy.xml @@ -0,0 +1,15 @@ +<!-- + ~ Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + ~ SPDX-License-Identifier: GPL-3.0-only + --> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="?attr/colorControlNormal" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FFFFFF" + android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM15,5L8,5c-1.1,0 -1.99,0.9 -1.99,2L6,21c0,1.1 0.89,2 1.99,2L19,23c1.1,0 2,-0.9 2,-2L21,11l-6,-6zM8,21L8,7h6v5h5v9L8,21z" /> +</vector> |