contacts: apply grouped-cards visual pattern across list, groups and details
- Commit
374412c49693583e21b348ab1258e14fc068e5f0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-05-29 23:47 UTC (6 months ago)
- Parents
ca62c5d
Diff
contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsPage.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsPage.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsPage.ktindex caffbaa8f7..f2b9d1efc0 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsPage.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsPage.kt@@ -181,80 +181,101 @@ fun ContactDetailsPage( ) } - items(details.phoneNumbers, key = { it.id }) { phone ->- var showCallDropdown by remember { mutableStateOf(false) }- var showSmsDropdown by remember { mutableStateOf(false) }- val hasAlternativeApps = isSignalInstalled || isWhatsAppInstalled+ if (details.phoneNumbers.isNotEmpty()) {+ item {+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {+ details.phoneNumbers.forEachIndexed { index, phone ->+ var showCallDropdown by remember(phone.id) { mutableStateOf(false) }+ var showSmsDropdown by remember(phone.id) { mutableStateOf(false) }+ val hasAlternativeApps = isSignalInstalled || isWhatsAppInstalled - DetailItem(- icon = painterResource(R.drawable.outline_call_24),- data = formatPhoneNumber(phone.number),- label = phone.typeString(context),- trailingIcon = painterResource(R.drawable.outline_chat_24),- onTrailingIconClick = {- if (hasAlternativeApps) {- showSmsDropdown = true- } else {- val intent = Intent(Intent.ACTION_SENDTO)- intent.data = "sms:${phone.number}".toUri()- context.startActivity(intent)- }- },- onClick = {- if (hasAlternativeApps) {- showCallDropdown = true- } else {- val intent = Intent(Intent.ACTION_DIAL)- intent.data = "tel:${phone.number}".toUri()- context.startActivity(intent)+ DetailItem(+ icon = painterResource(R.drawable.outline_call_24),+ data = formatPhoneNumber(phone.number),+ label = phone.typeString(context),+ trailingIcon = painterResource(R.drawable.outline_chat_24),+ onTrailingIconClick = {+ if (hasAlternativeApps) {+ showSmsDropdown = true+ } else {+ val intent = Intent(Intent.ACTION_SENDTO)+ intent.data = "sms:${phone.number}".toUri()+ context.startActivity(intent)+ }+ },+ onClick = {+ if (hasAlternativeApps) {+ showCallDropdown = true+ } else {+ val intent = Intent(Intent.ACTION_DIAL)+ intent.data = "tel:${phone.number}".toUri()+ context.startActivity(intent)+ }+ },+ dropdownContent = {+ CommunicationDropdown(+ expanded = showCallDropdown,+ onDismiss = { showCallDropdown = false },+ number = phone.number,+ type = CommunicationType.CALL,+ isSignalInstalled = isSignalInstalled,+ isWhatsAppInstalled = isWhatsAppInstalled+ )+ },+ trailingDropdownContent = {+ CommunicationDropdown(+ expanded = showSmsDropdown,+ onDismiss = { showSmsDropdown = false },+ number = phone.number,+ type = CommunicationType.SMS,+ isSignalInstalled = isSignalInstalled,+ isWhatsAppInstalled = isWhatsAppInstalled+ )+ },+ shape = groupShape(index, details.phoneNumbers.size),+ ) }- },- dropdownContent = {- CommunicationDropdown(- expanded = showCallDropdown,- onDismiss = { showCallDropdown = false },- number = phone.number,- type = CommunicationType.CALL,- isSignalInstalled = isSignalInstalled,- isWhatsAppInstalled = isWhatsAppInstalled- )- },- trailingDropdownContent = {- CommunicationDropdown(- expanded = showSmsDropdown,- onDismiss = { showSmsDropdown = false },- number = phone.number,- type = CommunicationType.SMS,- isSignalInstalled = isSignalInstalled,- isWhatsAppInstalled = isWhatsAppInstalled- ) }- )+ } }- items(details.emails, key = { it.id }) { email ->- DetailItem(- icon = painterResource(R.drawable.outline_mail_24),- data = email.address,- label = email.typeString(context),- onClick = {- val intent = Intent(Intent.ACTION_SENDTO)- intent.data = "mailto:${email.address}".toUri()- context.startActivity(intent)+ if (details.emails.isNotEmpty()) {+ item {+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {+ details.emails.forEachIndexed { index, email ->+ DetailItem(+ icon = painterResource(R.drawable.outline_mail_24),+ data = email.address,+ label = email.typeString(context),+ onClick = {+ val intent = Intent(Intent.ACTION_SENDTO)+ intent.data = "mailto:${email.address}".toUri()+ context.startActivity(intent)+ },+ shape = groupShape(index, details.emails.size),+ )+ } }- )+ } }- items(details.addresses, key = { it.id }) { address ->- DetailItem(- icon = painterResource(R.drawable.outline_location_on_24),- data = address.formattedAddress,- label = address.typeString(context),- trailingIcon = painterResource(R.drawable.outline_directions_24),- onTrailingIconClick = {- val gmmIntentURI = "geo:0,0?q=${Uri.encode(address.formattedAddress)}".toUri()- val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentURI)- context.startActivity(mapIntent)+ if (details.addresses.isNotEmpty()) {+ item {+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {+ details.addresses.forEachIndexed { index, address ->+ DetailItem(+ icon = painterResource(R.drawable.outline_location_on_24),+ data = address.formattedAddress,+ label = address.typeString(context),+ trailingIcon = painterResource(R.drawable.outline_directions_24),+ onTrailingIconClick = {+ val gmmIntentURI = "geo:0,0?q=${Uri.encode(address.formattedAddress)}".toUri()+ val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentURI)+ context.startActivity(mapIntent)+ },+ shape = groupShape(index, details.addresses.size),+ )+ } }- )+ } } if(details.dates.isNotEmpty()) {@@ -475,10 +496,16 @@ fun DetailItem( onTrailingIconClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null, dropdownContent: (@Composable () -> Unit)? = null,- trailingDropdownContent: (@Composable () -> Unit)? = null+ trailingDropdownContent: (@Composable () -> Unit)? = null,+ /**+ * Outer shape of the card. Pass [groupShape] when this item is part of a+ * vertically stacked sibling group so corners between siblings are+ * squared off while the group's outer corners stay rounded.+ */+ shape: androidx.compose.ui.graphics.Shape = RoundedCornerShape(16.dp), ) { Surface(- shape = RoundedCornerShape(16.dp),+ shape = shape, color = MaterialTheme.colorScheme.surfaceVariant, modifier = Modifier .fillMaxWidth()@@ -510,6 +537,35 @@ fun DetailItem( enum class CommunicationType { CALL, SMS } +/**+ * Outer shape for a card that sits at a given [index] inside a vertically+ * stacked sibling group of [size] items. Outer corners (top of first item,+ * bottom of last item) stay rounded at [outerRadius]; inner corners are+ * flattened to [innerRadius] (≈ a small right-angle) so each card reads as a+ * distinct row but the whole group still feels like one section.+ *+ * Pass [flatTop] / [flatBottom] when the group is visually attached to+ * another card above/below — e.g. an expanded group header that bleeds into+ * its contacts list — so the boundary corners between them stay flat.+ */+fun groupShape(+ index: Int,+ size: Int,+ outerRadius: androidx.compose.ui.unit.Dp = 16.dp,+ innerRadius: androidx.compose.ui.unit.Dp = 4.dp,+ flatTop: Boolean = false,+ flatBottom: Boolean = false,+): androidx.compose.ui.graphics.Shape {+ val isFirst = index == 0 && !flatTop+ val isLast = index == size - 1 && !flatBottom+ return RoundedCornerShape(+ topStart = if (isFirst) outerRadius else innerRadius,+ topEnd = if (isFirst) outerRadius else innerRadius,+ bottomStart = if (isLast) outerRadius else innerRadius,+ bottomEnd = if (isLast) outerRadius else innerRadius,+ )+}+ @Composable fun CommunicationDropdown( expanded: Boolean,
contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.ktindex 456c53fdc4..771e648f27 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt@@ -243,33 +243,31 @@ fun ContactList( if (favorites.isNotEmpty()) { item(key = "favorites-header") { FavoritesHeader() } item(key = "favorites-card") {- ContactSectionCard {- favorites.forEachIndexed { idx, contact ->- if (idx > 0) ContactRowDivider()- ContactItem(- contact = contact,- isSelected = if (isSelectionMode) contact.id in selectedIds else selectedID == contact.id,- showAccountLabels = showAccountLabels,- viewModel = viewModel,- embeddedInCard = true,- onClick = {- if (isSelectionMode) {- if (contact.id in selectedIds) {- selectedIds.remove(contact.id)- } else {- selectedIds.add(contact.id)- }+ GroupedContactSection(count = favorites.size) { idx ->+ val contact = favorites[idx]+ ContactItem(+ contact = contact,+ isSelected = if (isSelectionMode) contact.id in selectedIds else selectedID == contact.id,+ showAccountLabels = showAccountLabels,+ viewModel = viewModel,+ embeddedInCard = true,+ onClick = {+ if (isSelectionMode) {+ if (contact.id in selectedIds) {+ selectedIds.remove(contact.id) } else {- onContactClick(contact)- }- },- onLongClick = {- if (!isSelectionMode) { selectedIds.add(contact.id) }+ } else {+ onContactClick(contact) }- )- }+ },+ onLongClick = {+ if (!isSelectionMode) {+ selectedIds.add(contact.id)+ }+ }+ ) } } }@@ -277,33 +275,31 @@ fun ContactList( groupedContacts.forEach { (letter, contactsInGroup) -> item(key = "letter-header-$letter") { LetterHeader(letter) } item(key = "letter-card-$letter") {- ContactSectionCard {- contactsInGroup.forEachIndexed { idx, contact ->- if (idx > 0) ContactRowDivider()- ContactItem(- contact = contact,- isSelected = if (isSelectionMode) contact.id in selectedIds else selectedID == contact.id,- showAccountLabels = showAccountLabels,- viewModel = viewModel,- embeddedInCard = true,- onClick = {- if (isSelectionMode) {- if (contact.id in selectedIds) {- selectedIds.remove(contact.id)- } else {- selectedIds.add(contact.id)- }+ GroupedContactSection(count = contactsInGroup.size) { idx ->+ val contact = contactsInGroup[idx]+ ContactItem(+ contact = contact,+ isSelected = if (isSelectionMode) contact.id in selectedIds else selectedID == contact.id,+ showAccountLabels = showAccountLabels,+ viewModel = viewModel,+ embeddedInCard = true,+ onClick = {+ if (isSelectionMode) {+ if (contact.id in selectedIds) {+ selectedIds.remove(contact.id) } else {- onContactClick(contact)- }- },- onLongClick = {- if (!isSelectionMode) { selectedIds.add(contact.id) }+ } else {+ onContactClick(contact) }- )- }+ },+ onLongClick = {+ if (!isSelectionMode) {+ selectedIds.add(contact.id)+ }+ }+ ) } } }@@ -333,11 +329,8 @@ fun ContactListPick(mimeType: String?, contacts: List<Contact>, onClick: (Uri) - if (favorites.isNotEmpty()) { item(key = "pick-favorites-header") { FavoritesHeader() } item(key = "pick-favorites-card") {- ContactSectionCard {- favorites.forEachIndexed { idx, contact ->- if (idx > 0) ContactRowDivider()- ContactItemPick(contact, mimeType, onClick)- }+ GroupedContactSection(count = favorites.size) { idx ->+ ContactItemPick(favorites[idx], mimeType, onClick) } } }@@ -345,11 +338,8 @@ fun ContactListPick(mimeType: String?, contacts: List<Contact>, onClick: (Uri) - groupedContacts.forEach { (letter, contactsInGroup) -> item(key = "pick-letter-header-$letter") { LetterHeader(letter) } item(key = "pick-letter-card-$letter") {- ContactSectionCard {- contactsInGroup.forEachIndexed { idx, contact ->- if (idx > 0) ContactRowDivider()- ContactItemPick(contact, mimeType, onClick)- }+ GroupedContactSection(count = contactsInGroup.size) { idx ->+ ContactItemPick(contactsInGroup[idx], mimeType, onClick) } } }@@ -483,6 +473,34 @@ fun ContactSectionCard( } } +/**+ * Grouped-cards pattern: each row is its own rounded [Surface], but the+ * corners that meet a sibling in the same group are flattened so the group+ * reads as one section while remaining visually distinct cards. Mirrors what+ * [DetailItem]+[groupShape] does on the contact details page.+ *+ * [row] should render a flat row (e.g. [ContactItem] with `embeddedInCard =+ * true`) — the outer Surface handles the background and clipping.+ */+@Composable+fun GroupedContactSection(+ count: Int,+ containerColor: Color = MaterialTheme.colorScheme.surfaceVariant,+ topAttached: Boolean = false,+ row: @Composable (index: Int) -> Unit,+) {+ if (count == 0) return+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {+ for (i in 0 until count) {+ Surface(+ modifier = Modifier.fillMaxWidth(),+ shape = groupShape(i, count, flatTop = topAttached && i == 0),+ color = containerColor,+ ) { row(i) }+ }+ }+}+ @Composable fun ContactRowDivider() { androidx.compose.material3.HorizontalDivider(
contacts/src/main/java/com/vayunmathur/contacts/ui/GroupsPage.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/GroupsPage.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/GroupsPage.ktindex 633892e52f..dfa5416428 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/GroupsPage.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/GroupsPage.kt@@ -1,5 +1,8 @@ package com.vayunmathur.contacts.ui +import androidx.compose.animation.AnimatedVisibility+import androidx.compose.animation.animateColorAsState+import androidx.compose.animation.core.animateDpAsState import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.*@@ -58,82 +61,107 @@ fun GroupsPage(viewModel: ContactViewModel, backStack: NavBackStack<Route>, expa ) { groups.forEach { group -> val isExpanded = group.id in expandedGroups- // Each group has its own item key. The contacts card (when- // expanded) is a separate item so its insertion animates.- item(key = "group-header-${group.id}") {- // Collect the count here too — small flow, just one .size read.+ // Combine each group's header + (optional) expanded contacts+ // into ONE item so we can:+ // - share the same `getContactsForGroup` collect between+ // "show count" and "render rows",+ // - animate the header color + bottom-corner radius alongside+ // the contacts list's expand/collapse without the LazyColumn+ // swapping items underneath us mid-animation.+ item(key = "group-${group.id}") { val contactsInGroup by viewModel.getContactsForGroup(group.id).collectAsState(initial = emptyList())- Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {- Spacer(Modifier.height(4.dp))- ListItem(- headlineContent = {- Text(- text = group.name,- style = MaterialTheme.typography.bodyLarge,- fontWeight = FontWeight.Medium- )- },- supportingContent = {- Text("${contactsInGroup.size} contacts")- },- leadingContent = {- Box(- modifier = Modifier- .size(50.dp)- .background(- color = getAvatarColor(group.id),- shape = CircleShape- ),- contentAlignment = Alignment.Center- ) {- Icon(- painter = painterResource(R.drawable.baseline_group_24),- contentDescription = null,- tint = Color.White- )- }- },- trailingContent = {- IconButton(onClick = { viewModel.deleteGroup(group.id) }) {- IconDelete()+ val attachContacts = isExpanded && contactsInGroup.isNotEmpty()++ val collapsedColor = MaterialTheme.colorScheme.surfaceVariant+ val expandedColor = MaterialTheme.colorScheme.secondaryContainer+ val headerColor by animateColorAsState(+ targetValue = if (attachContacts) expandedColor else collapsedColor,+ label = "groupHeaderColor",+ )+ val bottomRadius by animateDpAsState(+ targetValue = if (attachContacts) 4.dp else 16.dp,+ label = "groupHeaderBottomRadius",+ )+ val headerShape = RoundedCornerShape(+ topStart = 16.dp, topEnd = 16.dp,+ bottomStart = bottomRadius, bottomEnd = bottomRadius,+ )++ Column {+ Surface(+ onClick = {+ if (isExpanded) {+ expandedGroups.remove(group.id)+ } else {+ expandedGroups.add(group.id) } },- modifier = Modifier- .clip(RoundedCornerShape(16.dp))- .clickable {- if (isExpanded) {- expandedGroups.remove(group.id)- } else {- expandedGroups.add(group.id)+ modifier = Modifier.fillMaxWidth(),+ shape = headerShape,+ color = headerColor,+ ) {+ ListItem(+ headlineContent = {+ Text(+ text = group.name,+ style = MaterialTheme.typography.bodyLarge,+ fontWeight = FontWeight.Medium+ )+ },+ supportingContent = {+ Text("${contactsInGroup.size} contacts")+ },+ leadingContent = {+ Box(+ modifier = Modifier+ .size(50.dp)+ .background(+ color = getAvatarColor(group.id),+ shape = CircleShape+ ),+ contentAlignment = Alignment.Center+ ) {+ Icon(+ painter = painterResource(R.drawable.baseline_group_24),+ contentDescription = null,+ tint = Color.White+ )+ }+ },+ trailingContent = {+ IconButton(onClick = { viewModel.deleteGroup(group.id) }) {+ IconDelete() } },- colors = ListItemDefaults.colors(- containerColor = MaterialTheme.colorScheme.surfaceVariant+ colors = ListItemDefaults.colors(containerColor = Color.Transparent) )- )- }- }+ } - if (isExpanded) {- item(key = "group-contacts-${group.id}") {- val contactsInGroup by viewModel.getContactsForGroup(group.id).collectAsState(initial = emptyList())- // Different background colour from the group header so- // the relationship is obvious without indentation.- ContactSectionCard(- containerColor = MaterialTheme.colorScheme.surfaceContainerHighest- ) {- contactsInGroup.forEachIndexed { idx, contact ->- if (idx > 0) ContactRowDivider()- ContactItem(- contact = contact,- isSelected = false,- showAccountLabels = false,- viewModel = viewModel,- embeddedInCard = true,- onClick = {- backStack.add(Route.ContactDetail(contact.id))- }- )+ // Animate the contacts list expanding/collapsing in+ // sync with the header's shape+color animation. The+ // 2dp gap is part of the visible block so it appears+ // and disappears with the list rather than leaving a+ // gap when collapsed.+ AnimatedVisibility(visible = attachContacts) {+ Column {+ Spacer(Modifier.height(2.dp))+ GroupedContactSection(+ count = contactsInGroup.size,+ containerColor = MaterialTheme.colorScheme.surfaceContainerHighest,+ topAttached = true,+ ) { idx ->+ val contact = contactsInGroup[idx]+ ContactItem(+ contact = contact,+ isSelected = false,+ showAccountLabels = false,+ viewModel = viewModel,+ embeddedInCard = true,+ onClick = {+ backStack.add(Route.ContactDetail(contact.id))+ }+ )+ } } } }