From 68d735c28e3f164b3cb4b08a3043d8f8481ffb35 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 28 May 2024 00:42:40 +0530 Subject: [PATCH] feat(compose): add a password item composable --- .../passwordstore/ui/compose/PasswordItem.kt | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt diff --git a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt new file mode 100644 index 00000000..63cc8304 --- /dev/null +++ b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordItem.kt @@ -0,0 +1,81 @@ +package app.passwordstore.ui.compose + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.wrapContentWidth +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.minimumInteractiveComponentSize +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.unit.dp +import app.passwordstore.ui.compose.preview.DevicePreviews +import app.passwordstore.ui.compose.preview.ThemePreviews +import app.passwordstore.ui.compose.theme.APSTheme + +public enum class ItemType { + File, + Folder, +} + +@Composable +public fun PasswordItem( + label: String, + type: ItemType, + onClick: () -> Unit, + modifier: Modifier = Modifier +) { + Row( + modifier = + modifier + .clickable(enabled = true, onClick = onClick) + .background(MaterialTheme.colorScheme.background) + .minimumInteractiveComponentSize() + .padding(horizontal = 16.dp) + .fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = label, + modifier = Modifier.wrapContentWidth(), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onBackground, + ) + when (type) { + ItemType.File -> {} + ItemType.Folder -> { + Icon( + painter = rememberVectorPainter(Icons.AutoMirrored.Filled.KeyboardArrowRight), + contentDescription = "Folder indicator", + tint = MaterialTheme.colorScheme.onBackground, + ) + } + } + } +} + +@ThemePreviews +@DevicePreviews +@Composable +private fun PasswordItemPreview() { + APSTheme { + LazyColumn { + items(20) { + PasswordItem(label = "Title $it", type = ItemType.entries.random(), onClick = {}) + HorizontalDivider() + } + } + } +}