|
| 1 | +package app.plugbrain.android.ui.designsystem.components.listitem |
| 2 | + |
| 3 | +import android.content.res.Configuration |
| 4 | +import androidx.compose.foundation.background |
| 5 | +import androidx.compose.foundation.border |
| 6 | +import androidx.compose.foundation.clickable |
| 7 | +import androidx.compose.foundation.layout.Arrangement |
| 8 | +import androidx.compose.foundation.layout.Column |
| 9 | +import androidx.compose.foundation.layout.Row |
| 10 | +import androidx.compose.foundation.layout.padding |
| 11 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 12 | +import androidx.compose.material.icons.Icons |
| 13 | +import androidx.compose.material.icons.filled.Search |
| 14 | +import androidx.compose.material.icons.rounded.Layers |
| 15 | +import androidx.compose.material3.MaterialTheme |
| 16 | +import androidx.compose.material3.Text |
| 17 | +import androidx.compose.runtime.Composable |
| 18 | +import androidx.compose.ui.Alignment |
| 19 | +import androidx.compose.ui.Modifier |
| 20 | +import androidx.compose.ui.draw.alpha |
| 21 | +import androidx.compose.ui.graphics.vector.ImageVector |
| 22 | +import androidx.compose.ui.tooling.preview.Preview |
| 23 | +import androidx.compose.ui.unit.dp |
| 24 | +import app.plugbrain.android.ui.theme.MathlockAppTheme |
| 25 | + |
| 26 | +@Composable |
| 27 | +fun PlugPermissionListItem( |
| 28 | + title: String, |
| 29 | + description: String, |
| 30 | + icon: ImageVector, |
| 31 | + isGranted: Boolean, |
| 32 | + onClick: () -> Unit, |
| 33 | +) { |
| 34 | + Row( |
| 35 | + horizontalArrangement = Arrangement.spacedBy(12.dp), |
| 36 | + verticalAlignment = Alignment.CenterVertically, |
| 37 | + modifier = Modifier |
| 38 | + .alpha(if (isGranted) 0.5f else 1f) |
| 39 | + .border( |
| 40 | + width = 1.dp, |
| 41 | + color = MaterialTheme.colorScheme.outlineVariant, |
| 42 | + shape = RoundedCornerShape(8.dp), |
| 43 | + ) |
| 44 | + .background(MaterialTheme.colorScheme.surface) |
| 45 | + .background( |
| 46 | + color = if (isGranted) MaterialTheme.colorScheme.primary.copy(0.1f) else MaterialTheme.colorScheme.surface, |
| 47 | + shape = RoundedCornerShape(8.dp), |
| 48 | + ) |
| 49 | + .clickable(onClick = onClick) |
| 50 | + .padding(vertical = 12.dp, horizontal = 16.dp), |
| 51 | + ) { |
| 52 | + LeadingIcon( |
| 53 | + icon = icon, |
| 54 | + isSelected = isGranted, |
| 55 | + modifier = Modifier.align(Alignment.Top).padding(top = 3.dp), |
| 56 | + ) |
| 57 | + Column( |
| 58 | + verticalArrangement = Arrangement.spacedBy(4.dp), |
| 59 | + modifier = Modifier.weight(1f), |
| 60 | + ) { |
| 61 | + Text(title, style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onSurface) |
| 62 | + Text(description, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurface) |
| 63 | + } |
| 64 | + TrailingIcon(isGranted) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +@Preview( |
| 69 | + name = "Light Mode", |
| 70 | + showBackground = true, |
| 71 | + uiMode = Configuration.UI_MODE_NIGHT_NO, |
| 72 | +) |
| 73 | +@Preview( |
| 74 | + name = "Dark Mode", |
| 75 | + showBackground = true, |
| 76 | + uiMode = Configuration.UI_MODE_NIGHT_YES, |
| 77 | +) |
| 78 | +@Composable |
| 79 | +private fun PermissionListItemPreview() { |
| 80 | + MathlockAppTheme(dynamicColor = false) { |
| 81 | + Column( |
| 82 | + verticalArrangement = Arrangement.spacedBy(8.dp), |
| 83 | + modifier = Modifier |
| 84 | + .background(MaterialTheme.colorScheme.surface) |
| 85 | + .padding(32.dp), |
| 86 | + ) { |
| 87 | + PlugPermissionListItem( |
| 88 | + title = "App Usage access", |
| 89 | + description = "Lets PlugBrain track app usage so it can block distracting apps at the right time.", |
| 90 | + isGranted = true, |
| 91 | + icon = Icons.Filled.Search, |
| 92 | + onClick = {}, |
| 93 | + ) |
| 94 | + PlugPermissionListItem( |
| 95 | + title = "Display over other apps", |
| 96 | + description = "Allows PlugBrain to display a challenge while you use a distracting app.", |
| 97 | + isGranted = false, |
| 98 | + icon = Icons.Rounded.Layers, |
| 99 | + onClick = {}, |
| 100 | + ) |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments