Skip to content
Closed
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
41 changes: 41 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,47 @@ Configuration in `.editorconfig`:
- **Entry functions:** `{feature}Entries`
- **Use cases:** `{Action}{Domain}UseCase` (e.g., `GetHomeDataUseCase`)

### Imports

**Import the type, never the namespace.** An import may shorten a qualified reference only when the
short name still says what it is to someone reading that line cold, without scrolling to the import
list. Sealed subclasses, enum entries and other types pass that test. A member reached through a
receiver that carries the meaning does not.

Always allowed (this is the house style, ~1200 such imports exist):

```kotlin
import com.hedvig.android.feature.home.home.ui.HomeUiState.Success // `is Success ->` reads fine
import com.hedvig.android.design.system.hedvig.TooltipDefaults.BeakDirection.TopEnd
import kotlin.time.Duration.Companion.seconds // enables the `5.seconds` idiom
```

Never allowed, because the receiver is the meaning:

```kotlin
import hedvig.resources.Res.string // ❌ `stringResource(string.FOO)` → use `Res.string.FOO`
import hedvig.resources.Res.drawable // ❌ `painterResource(drawable.x)` → use `Res.drawable.x`
import kotlin.time.Clock.System // ❌ `System.now()` → use `Clock.System.now()`
import ...hedvig.TooltipDefaults.defaultStyle // ❌ `defaultStyle` alone names nothing
```

`Res` and `Clock` are the two that come up most: 193 files import `hedvig.resources.Res` plainly and
that is the standard. `System.now()` additionally reads as `java.lang.System` to anyone skimming.

**Separately: never make an import-only change to a line you are not otherwise editing.** Converting
existing `HomeEvent.RefreshData` call sites to a bare `RefreshData` (or the reverse) is a whole-file
rewrite disguised as a diff. It buries the real change under churn and makes review and `git blame`
worse for no behavioural gain.

**Why:** both halves of this rule protect the reader. The first protects whoever reads the line
later, the second protects whoever reviews the PR now. PR #3100 was one screen refactor carrying 29
gratuitous new imports and ~60 rewritten call sites, and the formatting noise overshadowed the
actual work.

**How to apply:** if you are touching a line for a real reason, use the correct form. If you are not
touching it, leave its qualification exactly as it is. Import cleanups that are genuinely wanted go
in their own commit.

### Comments

Code comments and KDoc must describe the **current** code and stand on their own. A comment fails to earn its place in two ways: it tells the wrong kind of story, or it repeats what is already there. Before writing one, apply the test: *would this make sense to someone reading the file cold, with no knowledge of the PR, the conversation, or what was decided against?* If not, it does not belong in the source. Do not reference:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.ClickableListDefaults.iconSize
import com.hedvig.android.design.system.hedvig.icon.ChevronRight
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.design.system.hedvig.tokens.ColorSchemeKeyTokens
Expand Down Expand Up @@ -96,7 +95,7 @@ private fun ClickableListItem(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
) {
Icon(HedvigIcons.ChevronRight, "", Modifier.size(iconSize))
Icon(HedvigIcons.ChevronRight, "", Modifier.size(ClickableListDefaults.iconSize))
}
},
spaceBetween = 4.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.hedvig.android.design.system.hedvig.DialogDefaults.ButtonSize.SMALL
import com.hedvig.android.design.system.hedvig.DialogDefaults.DialogStyle
import com.hedvig.android.design.system.hedvig.DialogDefaults.DialogStyle.Buttons
import com.hedvig.android.design.system.hedvig.DialogDefaults.DialogStyle.NoButtons
import com.hedvig.android.design.system.hedvig.DialogDefaults.defaultButtonSize
import com.hedvig.android.design.system.hedvig.EmptyStateDefaults.EmptyStateButtonStyle
import com.hedvig.android.design.system.hedvig.EmptyStateDefaults.EmptyStateIconStyle.ERROR
import com.hedvig.android.design.system.hedvig.tokens.DialogTokens
Expand Down Expand Up @@ -86,7 +85,7 @@ fun HedvigAlertDialog(
modifier: Modifier = Modifier,
confirmButtonLabel: String = stringResource(Res.string.GENERAL_YES),
dismissButtonLabel: String = stringResource(Res.string.GENERAL_NO),
buttonSize: DialogDefaults.ButtonSize = defaultButtonSize,
buttonSize: DialogDefaults.ButtonSize = DialogDefaults.defaultButtonSize,
) {
HedvigAlertDialog(
title = AnnotatedString(title),
Expand All @@ -109,7 +108,7 @@ fun HedvigAlertDialog(
modifier: Modifier = Modifier,
confirmButtonLabel: String = stringResource(Res.string.GENERAL_YES),
dismissButtonLabel: String = stringResource(Res.string.GENERAL_NO),
buttonSize: DialogDefaults.ButtonSize = defaultButtonSize,
buttonSize: DialogDefaults.ButtonSize = DialogDefaults.defaultButtonSize,
) {
HedvigDialog(
style = Buttons(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.hedvig.android.compose.ui.LayoutWithoutPlacement
import com.hedvig.android.design.system.hedvig.BigCardDefaults.inputTextStyle
import com.hedvig.android.design.system.hedvig.BigCardDefaults.labelTextStyle
import com.hedvig.android.design.system.hedvig.BigCardDefaults.padding
import com.hedvig.android.design.system.hedvig.tokens.ColorSchemeKeyTokens
import com.hedvig.android.design.system.hedvig.tokens.TypographyKeyTokens

Expand Down Expand Up @@ -57,7 +54,7 @@ fun HedvigBigCard(
inputText: String?,
modifier: Modifier = Modifier,
enabled: Boolean = true,
textStyle: TextStyle = inputTextStyle,
textStyle: TextStyle = BigCardDefaults.inputTextStyle,
) {
Surface(
shape = HedvigTheme.shapes.cornerLarge,
Expand All @@ -72,14 +69,14 @@ fun HedvigBigCard(
LayoutWithoutPlacement(
sizeAdjustingContent = {
// Always take up the space that the two texts would take
Column(Modifier.padding(padding)) {
HedvigText(text = labelText, style = labelTextStyle)
Column(Modifier.padding(BigCardDefaults.padding)) {
HedvigText(text = labelText, style = BigCardDefaults.labelTextStyle)
HedvigText(text = "H", style = textStyle)
}
},
) {
if (inputText == null) {
Box(Modifier.padding(padding)) {
Box(Modifier.padding(BigCardDefaults.padding)) {
HedvigText(
text = labelText,
style = textStyle,
Expand All @@ -88,10 +85,10 @@ fun HedvigBigCard(
)
}
} else {
Column(Modifier.padding(padding)) {
Column(Modifier.padding(BigCardDefaults.padding)) {
HedvigText(
text = labelText,
style = labelTextStyle,
style = BigCardDefaults.labelTextStyle,
color = bigCardColors.labelTextColor(enabled),
)
HedvigText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ import com.hedvig.android.design.system.hedvig.NotificationDefaults.Notification
import com.hedvig.android.design.system.hedvig.NotificationDefaults.NotificationPriority.Info
import com.hedvig.android.design.system.hedvig.NotificationDefaults.NotificationPriority.InfoInline
import com.hedvig.android.design.system.hedvig.NotificationDefaults.NotificationPriority.NeutralToast
import com.hedvig.android.design.system.hedvig.NotificationDefaults.defaultStyle
import com.hedvig.android.design.system.hedvig.NotificationDefaults.paddingNoIcon
import com.hedvig.android.design.system.hedvig.NotificationDefaults.paddingWithIcon
import com.hedvig.android.design.system.hedvig.NotificationDefaults.textStyle
import com.hedvig.android.design.system.hedvig.icon.Campaign
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.design.system.hedvig.icon.InfoFilled
Expand Down Expand Up @@ -82,7 +78,7 @@ fun HedvigNotificationCard(
priority: NotificationPriority,
modifier: Modifier = Modifier,
withIcon: Boolean = NotificationDefaults.withIconDefault,
style: InfoCardStyle = defaultStyle,
style: InfoCardStyle = NotificationDefaults.defaultStyle,
buttonLoading: Boolean = false,
minLines: Int = 1,
) {
Expand All @@ -104,10 +100,10 @@ fun HedvigNotificationCard(
priority: NotificationPriority,
modifier: Modifier = Modifier,
withIcon: Boolean = NotificationDefaults.withIconDefault,
style: InfoCardStyle = defaultStyle,
style: InfoCardStyle = NotificationDefaults.defaultStyle,
buttonLoading: Boolean = false,
) {
val padding = if (withIcon) paddingWithIcon else paddingNoIcon
val padding = if (withIcon) NotificationDefaults.paddingWithIcon else NotificationDefaults.paddingNoIcon
val description = when (priority) {
Attention, NotificationPriority.AttentionRound, Error, Info -> stringResource(Res.string.TALKBACK_NOTIFICATION_CARD)
Campaign, InfoInline, NeutralToast, FancyInfo -> ""
Expand All @@ -125,7 +121,7 @@ fun HedvigNotificationCard(
border = if (priority !is FancyInfo) priority.colors.borderColor else null,
) {
val buttonDarkTheme = if (priority is InfoInline) isSystemInDarkTheme() else false
ProvideTextStyle(textStyle) {
ProvideTextStyle(NotificationDefaults.textStyle) {
Row(Modifier.padding(padding)) {
if (withIcon) {
LayoutWithoutPlacement(
Expand Down Expand Up @@ -156,7 +152,7 @@ fun HedvigNotificationCard(
buttonSize = Small,
modifier = Modifier.weight(1f),
) {
HedvigText(style.leftButtonText, style = textStyle)
HedvigText(style.leftButtonText, style = NotificationDefaults.textStyle)
}
Spacer(Modifier.width(4.dp))
HedvigButton(
Expand All @@ -166,7 +162,7 @@ fun HedvigNotificationCard(
buttonSize = Small,
modifier = Modifier.weight(1f),
) {
HedvigText(style.rightButtonText, style = textStyle)
HedvigText(style.rightButtonText, style = NotificationDefaults.textStyle)
}
}
}
Expand All @@ -184,11 +180,11 @@ fun HedvigNotificationCard(
) {
LayoutWithoutPlacement(
sizeAdjustingContent = {
HedvigText(style.buttonText, style = textStyle)
HedvigText(style.buttonText, style = NotificationDefaults.textStyle)
},
) {
if (!buttonLoading) {
HedvigText(style.buttonText, style = textStyle)
HedvigText(style.buttonText, style = NotificationDefaults.textStyle)
} else {
Box(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ import com.hedvig.android.design.system.hedvig.TooltipDefaults.TooltipStyle.Camp
import com.hedvig.android.design.system.hedvig.TooltipDefaults.TooltipStyle.Campaign.Brightness.BLEAK
import com.hedvig.android.design.system.hedvig.TooltipDefaults.TooltipStyle.Campaign.Brightness.BRIGHT
import com.hedvig.android.design.system.hedvig.TooltipDefaults.TooltipStyle.Inbox
import com.hedvig.android.design.system.hedvig.TooltipDefaults.arrowHeightDp
import com.hedvig.android.design.system.hedvig.TooltipDefaults.arrowSpaceFromEdgeWhenOffCenteredDp
import com.hedvig.android.design.system.hedvig.TooltipDefaults.arrowWidthDp
import com.hedvig.android.design.system.hedvig.TooltipDefaults.defaultStyle
import com.hedvig.android.design.system.hedvig.tokens.TooltipTokens
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.delay
Expand All @@ -63,7 +59,7 @@ fun HedvigTooltip(
showTooltip: Boolean,
tooltipShown: () -> Unit,
modifier: Modifier = Modifier,
tooltipStyle: TooltipStyle = defaultStyle,
tooltipStyle: TooltipStyle = TooltipDefaults.defaultStyle,
beakDirection: BeakDirection = BottomCenter,
maxWidth: Dp = TooltipDefaults.defaultMaxWidth,
) {
Expand Down Expand Up @@ -150,9 +146,11 @@ private fun InnerChatTooltip(
private fun Shape.withBeak(beakDirection: BeakDirection): Shape {
return object : Shape {
override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
val arrowSpaceFromEdgeWhenOffCentered: Float = with(density) { arrowSpaceFromEdgeWhenOffCenteredDp.toPx() }
val arrowWidth = with(density) { arrowWidthDp.toPx() }
val arrowHeight = with(density) { arrowHeightDp.toPx() }
val arrowSpaceFromEdgeWhenOffCentered: Float = with(density) {
TooltipDefaults.arrowSpaceFromEdgeWhenOffCenteredDp.toPx()
}
val arrowWidth = with(density) { TooltipDefaults.arrowWidthDp.toPx() }
val arrowHeight = with(density) { TooltipDefaults.arrowHeightDp.toPx() }
val squircleSize: Size = when (beakDirection) {
BottomCenter, BottomStart, BottomEnd, TopCenter, TopStart, TopEnd -> {
size.copy(height = size.height - arrowHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.dropUnlessResumed
import com.hedvig.android.design.system.hedvig.TopAppBarDefaults.windowInsets
import com.hedvig.android.design.system.hedvig.icon.ArrowLeft
import com.hedvig.android.design.system.hedvig.icon.Close
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
Expand Down Expand Up @@ -183,7 +182,7 @@ fun TopAppBarLayoutForActions(
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.windowInsetsPadding(windowInsets)
.windowInsetsPadding(TopAppBarDefaults.windowInsets)
.height(TopAppBarTokens.ContainerHeight)
.fillMaxWidth()
.padding(contentPadding),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import com.hedvig.android.design.system.hedvig.HedvigText
import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.HorizontalDivider
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDefaults.counterPadding
import com.hedvig.android.design.system.hedvig.fromToken
import com.hedvig.android.design.system.hedvig.internal.Decoration
import com.hedvig.android.design.system.hedvig.tokens.ColorSchemeKeyTokens.BackgroundBlack
Expand Down Expand Up @@ -241,7 +240,7 @@ private fun FreeTextOverlayContent(
color = freeTextColors.labelColor,
modifier = Modifier
.fillMaxWidth()
.padding(counterPadding)
.padding(FreeTextDefaults.counterPadding)
.wrapContentWidth(Alignment.End)
.semantics {
contentDescription = characterLimitDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.Height.Unlimited
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.Style
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.Style.Labeled
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.contentPadding
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.defaultHeight
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.defaultStyle
import com.hedvig.android.design.system.hedvig.freetext.FreeTextDisplayDefaults.supportingTextPadding
import com.hedvig.android.design.system.hedvig.fromToken
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.design.system.hedvig.icon.WarningFilled
Expand Down Expand Up @@ -64,8 +60,8 @@ fun FreeTextDisplay(
freeTextPlaceholder: String,
modifier: Modifier = Modifier,
maxLength: Int = FreeTextDisplayDefaults.maxLength,
height: Height = defaultHeight,
style: Style = defaultStyle,
height: Height = FreeTextDisplayDefaults.defaultHeight,
style: Style = FreeTextDisplayDefaults.defaultStyle,
hasError: Boolean = false,
supportingText: String? = null,
showCount: Boolean = true,
Expand All @@ -87,7 +83,7 @@ fun FreeTextDisplay(
color = freeTextColors.displayContainerColor,
) {
Column(
Modifier.padding(contentPadding),
Modifier.padding(FreeTextDisplayDefaults.contentPadding),
) {
if (style is Labeled && freeTextValue != null) {
Row(Modifier.fillMaxWidth()) {
Expand Down Expand Up @@ -147,7 +143,7 @@ fun FreeTextDisplay(
text = supportingText,
color = displayColors.supportingTextColor,
style = FreeTextDisplayDefaults.countLabelStyle.value,
modifier = Modifier.padding(supportingTextPadding),
modifier = Modifier.padding(FreeTextDisplayDefaults.supportingTextPadding),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import hedvig.resources.claim_status_detail_closed
import hedvig.resources.claim_status_detail_submitted
import java.util.Locale
import kotlin.time.Clock
import kotlin.time.Clock.System
import kotlin.time.Duration
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -77,7 +76,7 @@ private fun SubmittedAndClosedColumn(topText: String, bottomText: String, modifi
}

@Composable
private fun currentTimeAsState(updateInterval: Duration = 1.seconds, clock: Clock = System): State<Instant> {
private fun currentTimeAsState(updateInterval: Duration = 1.seconds, clock: Clock = Clock.System): State<Instant> {
return produceState(initialValue = clock.now()) {
while (isActive) {
delay(updateInterval)
Expand Down Expand Up @@ -123,8 +122,8 @@ private fun PreviewSubmittedAndClosedInformation() {
HedvigTheme {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary) {
SubmittedAndClosedColumns(
submittedAt = System.now().minus(10.days),
closedAt = System.now().minus(30.seconds),
submittedAt = Clock.System.now().minus(10.days),
closedAt = Clock.System.now().minus(30.seconds),
locale = Locale.ENGLISH,
)
}
Expand Down
Loading
Loading