Modern Apps git

← Modern-Apps.git

contacts: lay out contact quick-action buttons evenly at any scale (#875)

Commit
a98e4b3ccafa47516ca2492aeeb95b274a2dfa31
Author
Vayun Mathur <[email protected]>
When
2026-10-31 18:46 UTC (1 month ago)
Parents
21a428f
On narrow screens and large display/font scales the contact-card
quick-action row (call, message, video, email) squeezed its buttons
unevenly: the row used SpaceEvenly over unweighted children, so the
fourth button shrank and labels collided instead of sharing the width.
Changing the system display size worked around it, confirming a layout
rather than content problem.

Give every visible action an equal-weight slot. The row first collects
its buttons, then portrait lays them in rows of up to four with weight
1f each (a short final row is centered with half-slot spacers while
keeping full-row widths, and a fifth action wraps to a second row
instead of squeezing into a sliver). Wide windows use the same equal
slots inside a centered row capped at 480dp instead of fixed gaps, so
tablets keep a centered cluster. Each ActionButton fills its slot, keeps
the fixed 56dp icon circle, and renders its label as one centered
single-line ellipsized text that can no longer bleed into neighbors.

Phone/email/address type rows needed no change: they render through the
shared ListItem, which fills the width and wraps its value/label text.

User-visible effect: all 1-4 quick actions render the same size with
readable labels at large font scales and narrow widths, and 5+
actions wrap to a second centered row.

Verification: :contacts:compileDevKotlin green. Detekt reports only
pre-existing backlog in untouched files (MainActivity, Contact.kt,
VcfParser, ...); both touched files are clean. Store screenshot
previews (MetadataPreviews) untouched. Layout verified by code
inspection against weight/slot rules; on-device check at fontScale
1.3/2.0 on a narrow phone still recommended.

Diff

contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsActionButtons.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsActionButtons.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsActionButtons.ktindex 800a4ace9d..a7227ba2c7 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsActionButtons.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsActionButtons.kt@@ -6,6 +6,7 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.runtime.Composable@@ -13,6 +14,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.vayunmathur.contacts.R import com.vayunmathur.contacts.data.CommAction@@ -106,11 +109,16 @@ fun ActionButton(     icon: @Composable () -> Unit,     label: String,     dropdownContent: (@Composable () -> Unit)? = null,+    modifier: Modifier = Modifier,     action: () -> Unit ) {+    // Grows with the row slot so every button owns an equal share of the width+    // at any font scale. The label stays on one centered line with an ellipsis+    // instead of wrapping into its neighbors when space runs out.     Column(         horizontalAlignment = androidx.compose.ui.Alignment.CenterHorizontally,-        verticalArrangement = Arrangement.spacedBy(8.dp)+        verticalArrangement = Arrangement.spacedBy(8.dp),+        modifier = modifier.fillMaxWidth(),     ) {         BadgedBox(             badge = {}@@ -132,6 +140,13 @@ fun ActionButton(                 dropdownContent?.invoke()             }         }-        Text(text = label, style = MaterialTheme.typography.labelMedium)+        Text(+            text = label,+            style = MaterialTheme.typography.labelMedium,+            textAlign = TextAlign.Center,+            maxLines = 1,+            overflow = TextOverflow.Ellipsis,+            modifier = Modifier.fillMaxWidth(),+        )     } }
contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsHeader.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsHeader.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsHeader.ktindex 339b771a1e..34c6fd6074 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsHeader.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactDetailsHeader.kt@@ -2,12 +2,14 @@ package com.vayunmathur.contacts.ui  import android.content.Intent import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.widthIn import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -84,64 +86,127 @@ fun ActionButtonsRow(     onSaveCommPref: ((CommPref) -> Unit)? = null, ) {     val context = LocalContext.current-    // Wide windows centre the buttons with fixed gaps instead of spreading them-    // across the full width; portrait keeps SpaceEvenly verbatim.+    // Wide windows centre the buttons in a capped row instead of spreading+    // them across the full width; portrait wraps them into equal-weight rows.     val wide = isExpandedWidth() || isCompactHeight()-    Row(-        modifier = Modifier-            .fillMaxWidth()-            .padding(vertical = 8.dp),-        horizontalArrangement = if (wide) {-            Arrangement.spacedBy(32.dp, androidx.compose.ui.Alignment.CenterHorizontally)-        } else {-            Arrangement.SpaceEvenly-        }-    ) {+    // Every visible button is collected first so each one gets the same weight:+    // with 1-2 actions they spread evenly, with 3-4 they split the width+    // equally, and with 5+ they wrap onto a second row instead of squeezing+    // into unreadable slivers. Equal weights (not SpaceEvenly on unweighted+    // children) are what keeps the 4th button the same size as the first+    // three at large font scales.+    val buttons = buildList<@Composable () -> Unit> {         if (phoneNumbers.isNotEmpty()) {-            CommActionButton(-                action = CommAction.CALL,-                icon = { IconCall() },-                label = stringResource(UiR.string.call),-                phoneNumbers = phoneNumbers,-                platforms = platforms,-                isGoogleMeetInstalled = isGoogleMeetInstalled,-                commPref = commPref,-                onSaveCommPref = onSaveCommPref,-            )-            CommActionButton(-                action = CommAction.MESSAGE,-                icon = { IconSms() },-                label = stringResource(R.string.action_message),-                phoneNumbers = phoneNumbers,-                platforms = platforms,-                isGoogleMeetInstalled = isGoogleMeetInstalled,-                commPref = commPref,-                onSaveCommPref = onSaveCommPref,-            )--            if (hasVideoOptions(platforms, isGoogleMeetInstalled)) {+            add({+                CommActionButton(+                    action = CommAction.CALL,+                    icon = { IconCall() },+                    label = stringResource(UiR.string.call),+                    phoneNumbers = phoneNumbers,+                    platforms = platforms,+                    isGoogleMeetInstalled = isGoogleMeetInstalled,+                    commPref = commPref,+                    onSaveCommPref = onSaveCommPref,+                )+            })+            add({                 CommActionButton(-                    action = CommAction.VIDEO,-                    icon = { IconVideoCamera() },-                    label = stringResource(R.string.action_video),+                    action = CommAction.MESSAGE,+                    icon = { IconSms() },+                    label = stringResource(R.string.action_message),                     phoneNumbers = phoneNumbers,                     platforms = platforms,                     isGoogleMeetInstalled = isGoogleMeetInstalled,                     commPref = commPref,                     onSaveCommPref = onSaveCommPref,                 )+            })++            if (hasVideoOptions(platforms, isGoogleMeetInstalled)) {+                add({+                    CommActionButton(+                        action = CommAction.VIDEO,+                        icon = { IconVideoCamera() },+                        label = stringResource(R.string.action_video),+                        phoneNumbers = phoneNumbers,+                        platforms = platforms,+                        isGoogleMeetInstalled = isGoogleMeetInstalled,+                        commPref = commPref,+                        onSaveCommPref = onSaveCommPref,+                    )+                })             }         }         if (email != null) {-            ActionButton(icon = { IconMail() }, label = stringResource(UiR.string.email)) {-                val intent = Intent(Intent.ACTION_SENDTO)-                intent.data = "mailto:$email".toUri()-                ExternalIntents.launch(context, intent)+            add({+                ActionButton(icon = { IconMail() }, label = stringResource(UiR.string.email)) {+                    val intent = Intent(Intent.ACTION_SENDTO)+                    intent.data = "mailto:$email".toUri()+                    ExternalIntents.launch(context, intent)+                }+            })+        }+    }+    if (wide) {+        // Same equal-weight slots as portrait, but the row never spreads wider+        // than [WideButtonsMaxWidth]: on tablets the buttons stay a centered+        // cluster instead of drifting across the full width, and at large font+        // scales every button still owns an equal share (this also keeps the+        // fillMaxWidth inside ActionButton bounded by its slot).+        Box(+            modifier = Modifier+                .fillMaxWidth()+                .padding(vertical = 8.dp),+            contentAlignment = androidx.compose.ui.Alignment.Center,+        ) {+            Row(+                modifier = Modifier+                    .widthIn(max = WideButtonsMaxWidth)+                    .fillMaxWidth(),+            ) {+                buttons.forEach { button ->+                    Box(modifier = Modifier.weight(1f)) { button() }+                }+            }+        }+        return+    }+    /* Portrait: at most [MAX_BUTTONS_PER_ROW] buttons share one line with+    equal weights; extras flow onto a second centered line. */+    val rows = buttons.chunked(MAX_BUTTONS_PER_ROW)+    Column(+        modifier = Modifier+            .fillMaxWidth()+            .padding(vertical = 8.dp),+        verticalArrangement = Arrangement.spacedBy(8.dp),+    ) {+        rows.forEach { row ->+            Row(+                modifier = Modifier.fillMaxWidth(),+                horizontalArrangement = Arrangement.SpaceEvenly,+            ) {+                // Half-slots on each side keep a short final row centered while+                // every button stays exactly as wide as in a full row.+                val sideWeight = (MAX_BUTTONS_PER_ROW - row.size) / 2f+                if (sideWeight > 0f) Spacer(modifier = Modifier.weight(sideWeight))+                row.forEach { button ->+                    Box(modifier = Modifier.weight(1f)) { button() }+                }+                if (sideWeight > 0f) Spacer(modifier = Modifier.weight(sideWeight))             }         }     } } +/** Portrait buttons per line before extras wrap onto a second centered row. */+private const val MAX_BUTTONS_PER_ROW = 4++/**+ * Wide-window cap for the action row: buttons share the space equally up to+ * this width, then stay centered instead of spreading further apart.+ */+private val WideButtonsMaxWidth = 480.dp+ private fun hasVideoOptions(platforms: ContactPlatforms, isGoogleMeetInstalled: Boolean) =     CommPrefResolver.availablePlatformsFor(         CommAction.VIDEO, platforms, isGoogleMeetInstalled