From 32213d46f80f5010dd2986de7e5a3cbc79fd188b Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 30 Nov 2026 21:58:36 +0100 Subject: [PATCH] Take the preset palette from floret-kit (#198) --- .../data/calendar/CalendarColorPalette.kt | 56 +++++++------------ .../calendula/ui/calendars/CalendarsScreen.kt | 2 +- .../calendula/ui/common/ColorSwatchRow.kt | 2 +- .../data/calendar/CalendarColorPaletteTest.kt | 14 ----- floret-kit | 2 +- 5 files changed, 23 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPalette.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPalette.kt index 3a7ae164..0752257d 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPalette.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPalette.kt @@ -1,49 +1,33 @@ package de.jeanlucmakiola.calendula.data.calendar +import de.jeanlucmakiola.floret.components.PresetColors + /** * The colours offered when creating or editing a calendar; ARGB ints for a raw - * `CALENDAR_COLOR` / `EVENT_COLOR`. - * - * Hues rather than final fills: every surface that draws a calendar colour runs - * it through the app's own tone pass first, which pins lightness to one of two - * poles. So the set is spread by hue first, and the naturally light colours - * (amber, cyan, pink) sit on the light pole, which keeps them apart in lightness - * too, for colour-vision deficiencies as much as anything (#198). Distinctness - * is checked painted, in both themes and raw, by `CalendarColorPaletteTest`. - * - * Stored colours are never rewritten to match: a calendar or event coloured - * from an earlier palette simply shows as a custom colour ([presetOf]). + * `CALENDAR_COLOR` / `EVENT_COLOR`. The values are floret-kit's [PresetColors], + * shared with Agendula; distinctness after this app's tone pass is checked by + * `CalendarColorPaletteTest`. * * The named entries exist for callers that need one specific hue (the managed * special-dates calendars), so they can't drift from the swatches on offer. */ object CalendarColorPalette { - val Mauve = 0xFF614F54.toInt() - val Red = 0xFFEC4851.toInt() - val Orange = 0xFFE28139.toInt() - val Amber = 0xFFF3CD66.toInt() - val Olive = 0xFF666722.toInt() - val Green = 0xFF00852E.toInt() - val Teal = 0xFF009391.toInt() - val Cyan = 0xFF58C3F5.toInt() - val Blue = 0xFF2676C4.toInt() - val Indigo = 0xFF625CC5.toInt() - val Purple = 0xFF9352A5.toInt() - val Pink = 0xFFFD9EBF.toInt() + val Mauve = PresetColors.Mauve + val Red = PresetColors.Red + val Orange = PresetColors.Orange + val Amber = PresetColors.Amber + val Olive = PresetColors.Olive + val Green = PresetColors.Green + val Teal = PresetColors.Teal + val Cyan = PresetColors.Cyan + val Blue = PresetColors.Blue + val Indigo = PresetColors.Indigo + val Purple = PresetColors.Purple + val Pink = PresetColors.Pink /** The full palette, in swatch-grid order. */ - val all: List = listOf( - Mauve, Red, Orange, Amber, Olive, Green, - Teal, Cyan, Blue, Indigo, Purple, Pink, - ) + val all: List = PresetColors.all - /** - * The preset [argb] is, or null when it is a custom colour. Alpha is - * ignored: providers differ in whether they store it. - */ - fun presetOf(argb: Int?): Int? = argb?.let { all.firstOrNull { preset -> sameColor(preset, it) } } + /** The preset [argb] is, or null when it is a custom colour (never rewritten to match). */ + fun presetOf(argb: Int?): Int? = PresetColors.presetOf(argb) } - -/** Whether [a] and [b] are the same RGB colour, whatever their alpha. */ -fun sameColor(a: Int?, b: Int?): Boolean = - a != null && b != null && (a and 0xFFFFFF) == (b and 0xFFFFFF) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsScreen.kt index af94a450..f3eee80b 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsScreen.kt @@ -73,7 +73,7 @@ import de.jeanlucmakiola.calendula.domain.isNotSynced import de.jeanlucmakiola.calendula.domain.orderedForManager import de.jeanlucmakiola.calendula.domain.stateLabels import de.jeanlucmakiola.calendula.data.calendar.CalendarColorPalette -import de.jeanlucmakiola.calendula.data.calendar.sameColor +import de.jeanlucmakiola.floret.components.sameColor import de.jeanlucmakiola.calendula.ui.common.CustomColorPicker import de.jeanlucmakiola.calendula.ui.common.CustomColorRow import de.jeanlucmakiola.calendula.ui.common.RecentColorsRow diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ColorSwatchRow.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ColorSwatchRow.kt index d5c31470..3d2a31b4 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ColorSwatchRow.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ColorSwatchRow.kt @@ -22,7 +22,7 @@ import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp import androidx.compose.foundation.selection.selectable -import de.jeanlucmakiola.calendula.data.calendar.sameColor +import de.jeanlucmakiola.floret.components.sameColor import de.jeanlucmakiola.floret.components.formatHexColor /** diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPaletteTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPaletteTest.kt index b98c10a7..7917b106 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPaletteTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/CalendarColorPaletteTest.kt @@ -11,13 +11,6 @@ class CalendarColorPaletteTest { private val palette = CalendarColorPalette.all - @Test - fun `presets are twelve distinct opaque colours`() { - assertThat(palette).hasSize(12) - assertThat(palette.toSet()).hasSize(12) - palette.forEach { assertThat(it ushr 24).isEqualTo(0xFF) } - } - @Test fun `painted swatches stay apart in both themes`() { assertMinDistance("light fill", MIN_FILL_DISTANCE) { eventTone(it, dark = false, harmonise = true).container } @@ -61,13 +54,6 @@ class CalendarColorPaletteTest { assertThat(CalendarColorPalette.presetOf(null)).isNull() } - @Test - fun `sameColor compares rgb only`() { - assertThat(sameColor(0xFF112233.toInt(), 0x00112233)).isTrue() - assertThat(sameColor(0xFF112233.toInt(), 0xFF112234.toInt())).isFalse() - assertThat(sameColor(null, 0xFF112233.toInt())).isFalse() - } - private fun assertMinDistance(label: String, min: Float, paint: (Int) -> Int) { val painted = palette.map(paint).map(::oklchOf) for (i in painted.indices) for (j in i + 1 until painted.size) { diff --git a/floret-kit b/floret-kit index 17e469b3..dea52a9e 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 17e469b3100d627858c875e9415e438219dfe0dd +Subproject commit dea52a9eb62cc2d9872b5cb2cf70df9900f97204