CalendarStyleMap.kt
CalendarStyleMap is a user-scoped registry that associates each calendar (by its database ID) with a CalendarStyle object defining its colors. It provides convenience accessors for the two built-in birthday calendars and automatically initializes their styles with hardcoded defaults (#06790e green for favorites birthdays, #ffffff white for all birthdays) when first accessed if not already configured.
styles: MutableMap<Long, CalendarStyle> (private)Internal map storing the CalendarStyle per calendar ID. Not exposed directly; accessed through get(), add(), and contains().
birthdaysFavoritesStyle: CalendarStyleReturns the style for the "favorite birthdays" calendar (BIRTHDAYS_FAVS_CAL_ID). Uses !! because the get() method guarantees non-null for this ID (auto-creates if absent).
birthdaysAllStyle: CalendarStyleReturns the style for the "all birthdays" calendar (BIRTHDAYS_ALL_CAL_ID). Similarly non-null-guaranteed.
contains(calendarId: Long): BooleanChecks whether a style exists for the given calendar ID.
add(calendarId: Long, style: CalendarStyle)Adds or replaces a style for a given calendar ID.
get(calendarId: Long?): CalendarStyle?Retrieves the style for a calendar ID. Returns null if the ID itself is null. Special-cases the two built-in birthday calendar IDs (BIRTHDAYS_FAVS_CAL_ID and BIRTHDAYS_ALL_CAL_ID): if no style has been explicitly added for them, lazily creates and caches a default style ("#06790e" for favorites, "#ffffff" for all). This lazy initialization ensures the birthday calendars always have a visible style without requiring explicit configuration.
The lazy initialization pattern for birthday calendars avoids requiring an explicit configuration step. Instead of needing an installer or migration script to pre-seed birthday styles, the first call to get() with either birthday ID transparently creates the default style. This also means that if a user's stored preferences are missing these entries (e.g., after an upgrade), they are regenerated on-the-fly. The MutableMap is kept private to prevent direct mutation from outside the class, ensuring the lazy defaults are always triggered through get() rather than via map access.