aboutsummaryrefslogtreecommitdiff
path: root/ui-compose/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2023-07-05 14:20:22 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2023-07-05 14:24:35 +0530
commitfa03ca0ad7e556e60a13a355cbbd44675c135f88 (patch)
treef498644dab8590e626c10a3763eab48868dda4d3 /ui-compose/src/main
parent4c28098cbb682c99a0a4983c70671e3f872de211 (diff)
feat(ui): add a dedicated Compose screen for editing passwords
Diffstat (limited to 'ui-compose/src/main')
-rw-r--r--ui-compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt24
-rw-r--r--ui-compose/src/main/res/drawable/ic_content_copy.xml15
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>