Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / calendar / AGENTS.md

AGENTS.md9.4 KiBRenderedCodeRaw

AGENTS.md — calendar/ (':calendar')

Scoped supplement. Global rules in root AGENTS.md apply. Stay inside calendar/ + allowed shared modules. Do not root-scan.

Install: ./install calendar (dev by default).

  • Gradle: :calendar / dir: calendar/
  • Package roots present: ui, data, domain, platform, intents, sync, widget
  • Entry files: MainActivity.kt (sole launcher; routes watches to ui/WearMainActivity), ui/WearMainActivity.kt
  • Deps: :library:widgets, :library:wearlink, Wear Compose (material + foundation)
  • Metadata: metadata_data/calendar.md (present)
  • Rust: no / screenshotTest: yes

Overview

Purpose: Fully offline Material You calendar — works with on-device calendars, no account; acts as the system calendar so dates/events from other apps open here. Key features:

  • Month/pager/agenda views, event CRUD with recurrence (RRule), timezones, per-calendar colors
  • .ics import (files shared from anywhere) + export; holiday calendars via generated data (scripts/calendar) — the holiday screen toggles each country: single-language countries enable/disable directly, multi-language countries open the language picker when toggled on and simply disable when toggled off
  • Exact-alarm reminders rescheduled after reboot (ReminderScheduler + BootReceiver)
  • Self-refreshing Glance widgets (agenda + month); assistant read/add via intents/

Architecture / data-flow: ui/ screens + ui/dialogs/ editors → platform/CalendarViewModel (+ CalendarUiContract) → data/ models (Calendar/Event/Instance/ReminderMirror); reminders flow ViewModel → platform/ReminderScheduler → platform/ReminderReceiver → notification, re-armed on boot. Entry points + reading order: MainActivity.kt → ui/CalendarScreen.kt → platform/CalendarViewModel.kt → data/Event.kt + data/Instance.kt → domain/RRule.kt → platform/ReminderScheduler.kt.

One APK, two form factors (phone + watch)

This module is the single Calendar APK for phones and watches: same applicationId = "com.vayunmathur.calendar" and signing on both, as the WearLink handshake requires. The manifest declares no android.hardware.type.watch feature (required=true would block phones; required=false is disallowed for this feature), plus touchscreen not-required and com.google.android.wearable.standalone=false; distribution is sideload/F-Droid, not Play's watch channel, so the APK installs on phones and watches alike. platform/FormFactor.kt reads PackageManager.FEATURE_WATCH at runtime: MainActivity (the sole launcher entry) forwards watches to ui/WearMainActivity before any phone state loads; phones get the month/agenda UI. The phone platform/BootReceiver and platform/ReminderReceiver each gate on FormFactor and return immediately on a watch.

Wear sync (Watch conduit client)

Protocol: shared wire types live in :library:wearlink at com.vayunmathur.library.wearlink.calendar.WearCalendarProtocol; the golden-JSON tests in this module pin the shared code's wire format.

  • Snapshot + watch-state sync: conduit data items (/calendar/snapshot phone -> watch, /calendar/watch-state watch -> phone)
  • Sync request: conduit message (/calendar/request-sync), watch -> phone only
  • Transport: Watch conduit client — phone side sync/WearCalendarSync.kt and watch side sync/WearLinkBridge.kt both use WearLinkClientNode (Messenger to the Watch app's watch_conduit service, appId calendar); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports NotInstalled/Unavailable and the sync stays idle; snapshots republish on conduit Connected and on calendar changes. FormFactor picks the side at runtime, so only one of the two nodes runs on a given device.

Watch experience:

  • ui/WearMainActivity routes ui/WearRoute over the agenda (ui/WearAgendaScreen) and read-only event detail (ui/WearEventScreen), rendered from data/WearCalendarStore (wear-calendar-snapshot.json); sectioning is domain/wearAgenda. The watch has no event editing or RSVP; its one write is sync/requestWearSync asking the phone for a fresh snapshot.
  • Watch listing screenshots are the group = "wear" previews in src/screenshotTest/.../ui/WearMetadataPreviews.kt, collected by :calendar:metadata into metadata_data/photos/calendar/wear/; phone shots use the phone bucket.

Gotchas:

  • util/ is NOT a closed package root — don't add more files there
  • Holiday data is generated by scripts/calendar, not hand-written — regenerate, don't edit
  • Reminder alarms must be re-registered on boot; test the BootReceiver path, not just in-app scheduling
  • Phone and watch share one APK and one signing identity: never split the watch experience back into a separate module or applicationId, or the WearLink handshake breaks

Key files

Root — entry (no Route.kt)

  • com/vayunmathur/calendar/MainActivity.kt

data/ — calendar/event/instance models

  • com/vayunmathur/calendar/data/Calendar.kt
  • com/vayunmathur/calendar/data/Event.kt
  • com/vayunmathur/calendar/data/Instance.kt
  • com/vayunmathur/calendar/data/ReminderMirror.kt

util/ — ViewModel, recurrence, reminders, ICS

  • com/vayunmathur/calendar/util/CalendarViewModel.kt
  • com/vayunmathur/calendar/util/CalendarUiContract.kt
  • com/vayunmathur/calendar/util/RRule.kt — recurrence expansion
  • com/vayunmathur/calendar/util/RecurrenceParams.kt
  • com/vayunmathur/calendar/util/ReminderScheduler.kt
  • com/vayunmathur/calendar/util/ReminderReceiver.kt
  • com/vayunmathur/calendar/util/BootReceiver.kt
  • com/vayunmathur/calendar/platform/HolidayCalendarManager.kt — holiday calendar add/remove in the system provider; HolidayToggleAction decision (on disables, single-language off enables directly, multi-language off opens the picker) and picker pre-selection (live calendar language, then session-remembered language)
  • com/vayunmathur/calendar/data/HolidayData.kt — bundled holiday assets; languagesByCountry resolves every country's languages in one pass
  • com/vayunmathur/calendar/util/IcsExport.kt
  • com/vayunmathur/calendar/util/DateFormats.kt

ui/ + ui/dialogs/ — views and editors

  • com/vayunmathur/calendar/ui/CalendarScreen.kt
  • com/vayunmathur/calendar/ui/CalendarMonthView.kt
  • com/vayunmathur/calendar/ui/CalendarPagerView.kt
  • com/vayunmathur/calendar/ui/AgendaView.kt
  • com/vayunmathur/calendar/ui/WeekHeaderRow.kt
  • com/vayunmathur/calendar/ui/HourScale.kt
  • com/vayunmathur/calendar/ui/EventPositioner.kt
  • com/vayunmathur/calendar/ui/CalendarSelector.kt
  • com/vayunmathur/calendar/ui/CalendarViewHelpers.kt
  • com/vayunmathur/calendar/ui/EditEventScreen.kt
  • com/vayunmathur/calendar/ui/EditEventRow.kt
  • com/vayunmathur/calendar/ui/EditEventDateTime.kt
  • com/vayunmathur/calendar/ui/EditEventReminders.kt
  • com/vayunmathur/calendar/ui/EventScreen.kt
  • com/vayunmathur/calendar/ui/HolidayCalendarsScreen.kt
  • com/vayunmathur/calendar/ui/IcsImport.kt
  • com/vayunmathur/calendar/ui/ImportIcsScreen.kt
  • com/vayunmathur/calendar/ui/SettingsScreen.kt
  • com/vayunmathur/calendar/ui/SummaryEventItem.kt
  • com/vayunmathur/calendar/ui/SummaryGrid.kt
  • com/vayunmathur/calendar/ui/dialogs/RecurrenceDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/RecurrenceRuleBuild.kt
  • com/vayunmathur/calendar/ui/dialogs/RecurrenceDates.kt
  • com/vayunmathur/calendar/ui/dialogs/RecurrenceDialogComponents.kt
  • com/vayunmathur/calendar/ui/dialogs/CalendarPickerDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/CalendarSetDateDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/SettingsAddCalendarDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/SettingsChangeColorDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/SettingsDefaultRemindersDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/SettingsDeleteCalendarDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/SettingsRenameCalendarDialog.kt
  • com/vayunmathur/calendar/ui/dialogs/TimezonePickerDialog.kt

sync/ — wear companion sync (both sides, one APK)

  • com/vayunmathur/calendar/sync/WearCalendarSync.kt — phone conduit client node; snapshot publish, watch-state receive, request-sync handling
  • com/vayunmathur/calendar/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the store, watch-state publish
  • com/vayunmathur/calendar/sync/WearSyncRequest.kt — requestWearSync helper (watch asks phone for a fresh snapshot)

Watch experience (ui/ + data/ + domain/ + platform/)

  • com/vayunmathur/calendar/ui/WearMainActivity.kt — watch entry (agenda + event detail from the synced store)
  • com/vayunmathur/calendar/ui/WearRoute.kt, WearAgendaScreen.kt, WearEventScreen.kt
  • com/vayunmathur/calendar/data/WearCalendarStore.kt — persisted watch snapshot (wear-calendar-snapshot.json)
  • com/vayunmathur/calendar/domain/WearAgenda.kt — today/upcoming sectioning for the watch agenda
  • com/vayunmathur/calendar/platform/FormFactor.kt — watch detection (FEATURE_WATCH)

glance/ + intents/ — widgets and assistant IPC

  • com/vayunmathur/calendar/glance/CalendarGlanceWidget.kt
  • com/vayunmathur/calendar/glance/CalendarGlanceWidgetReceiver.kt
  • com/vayunmathur/calendar/glance/CalendarMonthGlanceWidget.kt
  • com/vayunmathur/calendar/glance/CalendarMonthGlanceWidgetReceiver.kt
  • com/vayunmathur/calendar/intents/GetIntent.kt
  • com/vayunmathur/calendar/intents/InsertIntent.kt

Verify (this module only)

./gradlew :calendar:compileDevKotlin
./gradlew :calendar:lint
./gradlew :calendar:checkMetadata