|
| 1 | +package app.passwordstore.ui.compose |
| 2 | + |
| 3 | +import androidx.compose.foundation.background |
| 4 | +import androidx.compose.foundation.clickable |
| 5 | +import androidx.compose.foundation.layout.Arrangement |
| 6 | +import androidx.compose.foundation.layout.Row |
| 7 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 8 | +import androidx.compose.foundation.layout.padding |
| 9 | +import androidx.compose.foundation.layout.wrapContentWidth |
| 10 | +import androidx.compose.foundation.lazy.LazyColumn |
| 11 | +import androidx.compose.material.icons.Icons |
| 12 | +import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight |
| 13 | +import androidx.compose.material3.HorizontalDivider |
| 14 | +import androidx.compose.material3.Icon |
| 15 | +import androidx.compose.material3.MaterialTheme |
| 16 | +import androidx.compose.material3.Text |
| 17 | +import androidx.compose.material3.minimumInteractiveComponentSize |
| 18 | +import androidx.compose.runtime.Composable |
| 19 | +import androidx.compose.ui.Alignment |
| 20 | +import androidx.compose.ui.Modifier |
| 21 | +import androidx.compose.ui.graphics.vector.rememberVectorPainter |
| 22 | +import androidx.compose.ui.unit.dp |
| 23 | +import app.passwordstore.ui.compose.preview.DevicePreviews |
| 24 | +import app.passwordstore.ui.compose.preview.ThemePreviews |
| 25 | +import app.passwordstore.ui.compose.theme.APSTheme |
| 26 | + |
| 27 | +public enum class ItemType { |
| 28 | + File, |
| 29 | + Folder, |
| 30 | +} |
| 31 | + |
| 32 | +@Composable |
| 33 | +public fun PasswordItem( |
| 34 | + label: String, |
| 35 | + type: ItemType, |
| 36 | + onClick: () -> Unit, |
| 37 | + modifier: Modifier = Modifier |
| 38 | +) { |
| 39 | + Row( |
| 40 | + modifier = |
| 41 | + modifier |
| 42 | + .clickable(enabled = true, onClick = onClick) |
| 43 | + .background(MaterialTheme.colorScheme.background) |
| 44 | + .minimumInteractiveComponentSize() |
| 45 | + .padding(horizontal = 16.dp) |
| 46 | + .fillMaxWidth(), |
| 47 | + horizontalArrangement = Arrangement.SpaceBetween, |
| 48 | + verticalAlignment = Alignment.CenterVertically, |
| 49 | + ) { |
| 50 | + Text( |
| 51 | + text = label, |
| 52 | + modifier = Modifier.wrapContentWidth(), |
| 53 | + style = MaterialTheme.typography.titleMedium, |
| 54 | + color = MaterialTheme.colorScheme.onBackground, |
| 55 | + ) |
| 56 | + when (type) { |
| 57 | + ItemType.File -> {} |
| 58 | + ItemType.Folder -> { |
| 59 | + Icon( |
| 60 | + painter = rememberVectorPainter(Icons.AutoMirrored.Filled.KeyboardArrowRight), |
| 61 | + contentDescription = "Folder indicator", |
| 62 | + tint = MaterialTheme.colorScheme.onBackground, |
| 63 | + ) |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +@ThemePreviews |
| 70 | +@DevicePreviews |
| 71 | +@Composable |
| 72 | +private fun PasswordItemPreview() { |
| 73 | + APSTheme { |
| 74 | + LazyColumn { |
| 75 | + items(20) { |
| 76 | + PasswordItem(label = "Title $it", type = ItemType.entries.random(), onClick = {}) |
| 77 | + HorizontalDivider() |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments