Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,11 @@ serving, AI-estimate source); changing a number marks it `userEdited`, as a barc
connected) is its own green, REM is cyan, connecting is amber. The readiness ring keeps the
brand colour on purpose: it is the headline score.
- **One card radius: 8dp.** Tiles and vital cards used to be 20/30dp.
- **Every button is a `PulseButton`** (`ui/components/PulseButton.kt`, v2.11.57): one composable
with a style (Filled, Tonal, Outlined, Text) that holds the design system's button rules — 52dp
minimum height and the 97% press scale. Never call Material's `Button`, `FilledTonalButton`,
`OutlinedButton` or `TextButton` directly, and don't give a button a fixed `.height()`: it is a
minimum so a long pt-BR label grows the button. `PulseButtonTest` fails on a direct call.
- **One filled accent per screen**: the Actions button. A screen's own primary action is a tonal
button (Activity's Record).
- **Landscape keeps the header** (compact, one row): it is the only route to Settings and the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pulseloop.coach.schema

import com.pulseloop.ui.theme.dither
import com.pulseloop.ui.components.PulseButtonStyle
import com.pulseloop.ui.components.PulseButton
import com.pulseloop.ui.theme.PulseColors
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
Expand Down Expand Up @@ -51,13 +53,13 @@ fun CoachActionCardView(
Text(action.summary, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurface)

Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedButton(
PulseButton(PulseButtonStyle.Outlined,
onClick = onCancel,
modifier = Modifier.weight(1f),
) {
Text("Cancel")
}
Button(
PulseButton(
onClick = onConfirm,
modifier = Modifier.weight(1f),
colors = ButtonDefaults.buttonColors(containerColor = tone),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
Expand Down Expand Up @@ -48,7 +47,7 @@ fun PrimaryButton(
enabled: Boolean = true,
onClick: () -> Unit,
) {
Button(
PulseButton(
onClick = onClick,
enabled = enabled,
modifier = modifier.fillMaxWidth().heightIn(min = 52.dp),
Expand Down Expand Up @@ -76,7 +75,7 @@ fun SecondaryButton(
enabled: Boolean = true,
onClick: () -> Unit,
) {
Button(
PulseButton(
onClick = onClick,
enabled = enabled,
modifier = modifier
Expand Down
101 changes: 101 additions & 0 deletions app/src/main/java/com/pulseloop/ui/components/PulseButton.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.pulseloop.ui.components

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.heightIn
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp
import com.pulseloop.ui.theme.pressScale

/** The four kinds of button the app uses. Which one a screen gets is a hierarchy decision. */
enum class PulseButtonStyle {
/** The one filled accent action per screen. */
Filled,
/** A screen's own primary action when the accent is taken (Activity's Record). */
Tonal,
/** A secondary action. */
Outlined,
/** A dialog action, or a quiet action beside a stronger one. */
Text,
}

object PulseButtonDefaults {
/**
* Every button is at least 52dp tall (Gabriel Design System, DESIGN.md "Buttons"; the
* `button` size token, 52px). Material3's own 40dp only reached 48dp as a touch target.
* A min, not a fixed height, so a two-line pt-BR label or large font scale grows the button
* instead of clipping it.
*/
val MinHeight = 52.dp
}

/**
* The app's only button. Every `Button` / `FilledTonalButton` / `OutlinedButton` / `TextButton`
* goes through it, so the system's button rules hold in one place: 52dp minimum height and the
* 97% press scale (`pressScale`, which follows "Remove animations"). `PulseButtonTest` fails on a
* Material button called anywhere else.
*
* [style] comes first so a call reads `PulseButton(PulseButtonStyle.Outlined, onClick = …)`, and
* positional arguments after it keep the Material order (onClick, modifier). [colors], [border]
* and [shape] default to that style's Material defaults.
*/
@Composable
fun PulseButton(
style: PulseButtonStyle = PulseButtonStyle.Filled,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape? = null,
colors: ButtonColors? = null,
border: BorderStroke? = null,
contentPadding: PaddingValues? = null,
content: @Composable RowScope.() -> Unit,
) {
val interaction = remember { MutableInteractionSource() }
val m = modifier.heightIn(min = PulseButtonDefaults.MinHeight).pressScale(interaction)
when (style) {
PulseButtonStyle.Filled -> Button(
onClick = onClick, modifier = m, enabled = enabled,
shape = shape ?: ButtonDefaults.shape,
colors = colors ?: ButtonDefaults.buttonColors(),
border = border,
contentPadding = contentPadding ?: ButtonDefaults.ContentPadding,
interactionSource = interaction, content = content,
)
PulseButtonStyle.Tonal -> FilledTonalButton(
onClick = onClick, modifier = m, enabled = enabled,
shape = shape ?: ButtonDefaults.filledTonalShape,
colors = colors ?: ButtonDefaults.filledTonalButtonColors(),
border = border,
contentPadding = contentPadding ?: ButtonDefaults.ContentPadding,
interactionSource = interaction, content = content,
)
PulseButtonStyle.Outlined -> OutlinedButton(
onClick = onClick, modifier = m, enabled = enabled,
shape = shape ?: ButtonDefaults.outlinedShape,
colors = colors ?: ButtonDefaults.outlinedButtonColors(),
border = border ?: ButtonDefaults.outlinedButtonBorder,
contentPadding = contentPadding ?: ButtonDefaults.ContentPadding,
interactionSource = interaction, content = content,
)
PulseButtonStyle.Text -> TextButton(
onClick = onClick, modifier = m, enabled = enabled,
shape = shape ?: ButtonDefaults.textShape,
colors = colors ?: ButtonDefaults.textButtonColors(),
border = border,
contentPadding = contentPadding ?: ButtonDefaults.TextButtonContentPadding,
interactionSource = interaction, content = content,
)
}
}
7 changes: 4 additions & 3 deletions app/src/main/java/com/pulseloop/ui/dashboard/DashboardEdit.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pulseloop.ui.dashboard

import com.pulseloop.ui.i18n.trf
import com.pulseloop.ui.components.PulseButtonStyle
import com.pulseloop.ui.components.PulseButton

import com.pulseloop.ui.i18n.tr

Expand All @@ -25,7 +27,6 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -224,7 +225,7 @@ fun HiddenMetricsTray(hidden: List<DashboardCard>, onRestore: (DashboardCard) ->
* for iOS's long-press). Show it only when not already editing. */
@Composable
fun CustomizeCardsButton(onClick: () -> Unit) {
TextButton(onClick = onClick) {
PulseButton(PulseButtonStyle.Text, onClick = onClick) {
Text(tr("Customize"), style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
}
Expand All @@ -244,7 +245,7 @@ fun ReorderDoneBar(onDone: () -> Unit) {
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(start = 8.dp),
)
TextButton(onClick = onDone) { Text(tr("Done")) }
PulseButton(PulseButtonStyle.Text, onClick = onDone) { Text(tr("Done")) }
}
}
}
11 changes: 6 additions & 5 deletions app/src/main/java/com/pulseloop/ui/onboarding/Editors.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pulseloop.ui.onboarding

import com.pulseloop.ui.i18n.trf
import com.pulseloop.ui.components.PulseButtonStyle
import com.pulseloop.ui.components.PulseButton

import com.pulseloop.ui.i18n.tr

Expand Down Expand Up @@ -31,7 +33,6 @@ import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -352,7 +353,7 @@ private fun NumberPickerSheet(
Modifier.fillMaxWidth().padding(horizontal = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
TextButton(onClick = {
PulseButton(PulseButtonStyle.Text, onClick = {
onSave(null)
onDismiss()
}) { Text(tr("Clear"), color = PulseColors.textSecondary) }
Expand All @@ -364,7 +365,7 @@ private fun NumberPickerSheet(
color = PulseColors.textPrimary,
)
Spacer(Modifier.weight(1f))
TextButton(onClick = {
PulseButton(PulseButtonStyle.Text, onClick = {
onSave(selection)
onDismiss()
}) { Text(tr("Done"), color = PulseColors.accent, fontWeight = FontWeight.SemiBold) }
Expand Down Expand Up @@ -426,7 +427,7 @@ private fun DecimalValueSheet(
Modifier.fillMaxWidth().padding(horizontal = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
TextButton(onClick = {
PulseButton(PulseButtonStyle.Text, onClick = {
onSave(null)
onDismiss()
}) { Text(tr("Clear"), color = PulseColors.textSecondary) }
Expand All @@ -438,7 +439,7 @@ private fun DecimalValueSheet(
color = PulseColors.textPrimary,
)
Spacer(Modifier.weight(1f))
TextButton(
PulseButton(PulseButtonStyle.Text,
enabled = parsedValue != null,
onClick = {
onSave(parsedValue)
Expand Down
27 changes: 13 additions & 14 deletions app/src/main/java/com/pulseloop/ui/screens/AccuracyCheckUi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pulseloop.ui.screens

import com.pulseloop.ui.i18n.trf
import com.pulseloop.ui.components.PulseButtonStyle
import com.pulseloop.ui.components.PulseButton

import com.pulseloop.ui.i18n.tr

Expand All @@ -13,7 +15,6 @@ import androidx.compose.foundation.clickable
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.FilterChip
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.TextButton
import androidx.compose.runtime.collectAsState
import com.pulseloop.data.PulseLoopDatabase
import com.pulseloop.data.entity.AccuracyCheckEntity
Expand All @@ -31,9 +32,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -166,12 +165,12 @@ fun AccuracyCheckSettingsScreen(onBack: () -> Unit) {
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
if (readable.size < ReferenceMetric.entries.size) {
Button(onClick = { launcher.launch(AccuracyCheckPermissions.request) }, enabled = !scanning) {
PulseButton(onClick = { launcher.launch(AccuracyCheckPermissions.request) }, enabled = !scanning) {
Text(if (readable.isEmpty()) tr("Allow access") else tr("Allow more"))
}
}
if (readable.isNotEmpty()) {
OutlinedButton(onClick = { scan() }, enabled = !scanning) { Text(trf("Scan last {0} days", ReferenceSourceScanner.LOOKBACK_DAYS)) }
PulseButton(PulseButtonStyle.Outlined, onClick = { scan() }, enabled = !scanning) { Text(trf("Scan last {0} days", ReferenceSourceScanner.LOOKBACK_DAYS)) }
}
if (scanning) CircularProgressIndicator(Modifier.size(20.dp).align(Alignment.CenterVertically), strokeWidth = 2.dp)
}
Expand Down Expand Up @@ -204,7 +203,7 @@ fun AccuracyCheckSettingsScreen(onBack: () -> Unit) {
}
}
}
OutlinedButton(onClick = {
PulseButton(PulseButtonStyle.Outlined, onClick = {
val text = ReferenceSurveyText.render(r.sources, ReferenceSourceScanner.LOOKBACK_DAYS, { ReferenceAppLabels.label(context, it) }, r.unreadable)
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
.setPrimaryClip(ClipData.newPlainText(tr("Accuracy check sources"), text))
Expand Down Expand Up @@ -298,20 +297,20 @@ private fun RunningCard(check: AccuracyCheckEntity, scope: kotlinx.coroutines.Co
Text(trf("Accuracy check · day {0} of {1}", day, total), fontSize = 16.sp, fontWeight = FontWeight.Bold, color = PulseColors.textPrimary)
Text(trf("{0} vs {1}, until {2}.", check.deviceLabel, check.referenceLabel, AccuracyUiText.date(check.plannedEndAt)), fontSize = 14.sp, color = PulseColors.textSecondary)
Text(trf("Wear both as usual. Health Connect export paused for: {0}.", AccuracyUiText.units(units)), fontSize = 12.sp, color = PulseColors.warning)
OutlinedButton(onClick = { confirmEnd = true }) { Text(tr("End now")) }
PulseButton(PulseButtonStyle.Outlined, onClick = { confirmEnd = true }) { Text(tr("End now")) }
}
if (confirmEnd) {
AlertDialog(
onDismissRequest = { confirmEnd = false },
title = { Text(tr("End the check now?")) },
text = { Text(tr("The report covers the days so far. You'll then choose what happens to the paused Health Connect export.")) },
confirmButton = {
TextButton(onClick = {
PulseButton(PulseButtonStyle.Text, onClick = {
confirmEnd = false
scope.launch { AccuracyCheckController.end(context, AccuracyCheckEntity.END_EARLY) }
}) { Text(tr("End now")) }
},
dismissButton = { TextButton(onClick = { confirmEnd = false }) { Text(tr("Keep going")) } },
dismissButton = { PulseButton(PulseButtonStyle.Text, onClick = { confirmEnd = false }) { Text(tr("Keep going")) } },
)
}
}
Expand All @@ -327,11 +326,11 @@ private fun ResumeCard(check: AccuracyCheckEntity, scope: kotlinx.coroutines.Cor
trf("During the check, {0} wrote the same types to Health Connect. Exporting the ring's copy of those days now would count them twice.", check.referenceLabel),
fontSize = 12.sp, color = PulseColors.textMuted,
)
Button(onClick = {
PulseButton(onClick = {
busy = true
scope.launch { AccuracyCheckController.resolve(context, AccuracyCheckEntity.RESUME_SKIP); busy = false }
}, enabled = !busy, modifier = Modifier.fillMaxWidth()) { Text(tr("Skip these days (recommended)")) }
OutlinedButton(onClick = {
PulseButton(PulseButtonStyle.Outlined, onClick = {
busy = true
scope.launch { AccuracyCheckController.resolve(context, AccuracyCheckEntity.RESUME_EXPORT); busy = false }
}, enabled = !busy, modifier = Modifier.fillMaxWidth()) { Text(tr("Export them too")) }
Expand Down Expand Up @@ -384,8 +383,8 @@ private fun StartDialog(
Text(tr("Wear both devices as you normally would, including at night."), fontSize = 12.sp)
}
},
confirmButton = { TextButton(onClick = { onStart(label.trim(), days) }) { Text(tr("Start")) } },
dismissButton = { TextButton(onClick = onDismiss) { Text(tr("Cancel")) } },
confirmButton = { PulseButton(PulseButtonStyle.Text, onClick = { onStart(label.trim(), days) }) { Text(tr("Start")) } },
dismissButton = { PulseButton(PulseButtonStyle.Text, onClick = onDismiss) { Text(tr("Cancel")) } },
)
}

Expand All @@ -412,7 +411,7 @@ private fun SourceCard(context: Context, s: ReferenceSourceSurvey, onUse: (() ->
)
}
s.metrics.forEach { MetricRow(it) }
if (onUse != null) Button(onClick = onUse, modifier = Modifier.fillMaxWidth()) { Text(tr("Compare my ring with this")) }
if (onUse != null) PulseButton(onClick = onUse, modifier = Modifier.fillMaxWidth()) { Text(tr("Compare my ring with this")) }
}
}

Expand Down
Loading
Loading