Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / calendar / AGENTS.md
| 1 | # AGENTS.md — calendar/ (':calendar') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `calendar/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: ./install calendar (dev by default)._ |
| 6 | - Gradle: :calendar / dir: calendar/ |
| 7 | - Package roots present: ui, data, domain, platform, intents, sync, widget |
| 8 | - Entry files: MainActivity.kt (sole launcher; routes watches to ui/WearMainActivity), ui/WearMainActivity.kt |
| 9 | - Deps: :library:widgets, :library:wearlink, Wear Compose (material + foundation) |
| 10 | - Metadata: metadata_data/calendar.md (present) |
| 11 | - Rust: no / screenshotTest: yes |
| 12 | |
| 13 | ## Overview |
| 14 | **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. |
| 15 | **Key features:** |
| 16 | - Month/pager/agenda views, event CRUD with recurrence (`RRule`), timezones, per-calendar colors |
| 17 | - `.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 |
| 18 | - Exact-alarm reminders rescheduled after reboot (`ReminderScheduler` + `BootReceiver`) |
| 19 | - Self-refreshing Glance widgets (agenda + month); assistant read/add via `intents/` |
| 20 | **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. |
| 21 | **Entry points + reading order:** `MainActivity.kt` → `ui/CalendarScreen.kt` → `platform/CalendarViewModel.kt` → `data/Event.kt` + `data/Instance.kt` → `domain/RRule.kt` → `platform/ReminderScheduler.kt`. |
| 22 | |
| 23 | ## One APK, two form factors (phone + watch) |
| 24 | This module is the single Calendar APK for phones and watches: same |
| 25 | `applicationId = "com.vayunmathur.calendar"` and signing on both, as the |
| 26 | WearLink handshake requires. The manifest declares no |
| 27 | `android.hardware.type.watch` feature (required=true would block |
| 28 | phones; required=false is disallowed for this feature), plus |
| 29 | touchscreen not-required and |
| 30 | `com.google.android.wearable.standalone=false`; distribution is |
| 31 | sideload/F-Droid, not Play's watch channel, so the APK installs on |
| 32 | phones and watches alike. `platform/FormFactor.kt` |
| 33 | reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the |
| 34 | sole launcher entry) forwards watches to `ui/WearMainActivity` before |
| 35 | any phone state loads; phones get the month/agenda UI. The phone |
| 36 | `platform/BootReceiver` and `platform/ReminderReceiver` each gate on |
| 37 | `FormFactor` and return immediately on a watch. |
| 38 | |
| 39 | ## Wear sync (Watch conduit client) |
| 40 | **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. |
| 41 | - Snapshot + watch-state sync: conduit data items (`/calendar/snapshot` phone -> watch, `/calendar/watch-state` watch -> phone) |
| 42 | - Sync request and event delete: conduit messages (`/calendar/request-sync`, `/calendar/op` with a delete-event op the phone applies to the provider), watch -> phone only |
| 43 | - **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. |
| 44 | - **Push triggers:** the publish also runs on the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearCalendarSync.syncNow()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration. |
| 45 | - **Open on phone:** the watch request (`/<appId>/open-on-phone` conduit message; camera: `OPEN_ON_PHONE` op) is handled live by the sync message listener when this app is registered, and otherwise the phone conduit host broadcasts `OpenOnPhoneContract.ACTION` (package-addressed, `CONDUIT` signature permission) to `sync/OpenOnPhoneReceiver`, which launches the main activity as a new task — no phone process needs to be running first. |
| 46 | **Watch experience:** |
| 47 | - `ui/WearMainActivity` routes `ui/WearRoute` over the agenda (`ui/WearAgendaScreen`) and event detail (`ui/WearEventScreen`: read-only fields plus a Delete event button after Open on phone, applied by the phone over the conduit), rendered from `data/WearCalendarStore` (`wear-calendar-snapshot.json`); sectioning is `domain/wearAgenda`. The watch has no event editing or RSVP and no manual sync action; snapshots arrive automatically over the conduit. |
| 48 | - 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. |
| 49 | **Gotchas:** |
| 50 | - `util/` is NOT a closed package root — don't add more files there |
| 51 | - Holiday data is generated by `scripts/calendar`, not hand-written — regenerate, don't edit |
| 52 | - Reminder alarms must be re-registered on boot; test the `BootReceiver` path, not just in-app scheduling |
| 53 | - 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 |
| 54 | |
| 55 | ## Key files |
| 56 | ### Root — entry (no Route.kt) |
| 57 | - com/vayunmathur/calendar/MainActivity.kt |
| 58 | ### data/ — calendar/event/instance models |
| 59 | - com/vayunmathur/calendar/data/Calendar.kt |
| 60 | - com/vayunmathur/calendar/data/Event.kt |
| 61 | - com/vayunmathur/calendar/data/Instance.kt |
| 62 | - com/vayunmathur/calendar/data/ReminderMirror.kt |
| 63 | ### util/ — ViewModel, recurrence, reminders, ICS |
| 64 | - com/vayunmathur/calendar/util/CalendarViewModel.kt |
| 65 | - com/vayunmathur/calendar/util/CalendarUiContract.kt |
| 66 | - com/vayunmathur/calendar/util/RRule.kt — recurrence expansion |
| 67 | - com/vayunmathur/calendar/util/RecurrenceParams.kt |
| 68 | - com/vayunmathur/calendar/util/ReminderScheduler.kt |
| 69 | - com/vayunmathur/calendar/util/ReminderReceiver.kt |
| 70 | - com/vayunmathur/calendar/util/BootReceiver.kt |
| 71 | - 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) |
| 72 | - com/vayunmathur/calendar/data/HolidayData.kt — bundled holiday assets; `languagesByCountry` resolves every country's languages in one pass |
| 73 | - com/vayunmathur/calendar/util/IcsExport.kt |
| 74 | - com/vayunmathur/calendar/util/DateFormats.kt |
| 75 | ### ui/ + ui/dialogs/ — views and editors |
| 76 | - com/vayunmathur/calendar/ui/CalendarScreen.kt |
| 77 | - com/vayunmathur/calendar/ui/CalendarMonthView.kt |
| 78 | - com/vayunmathur/calendar/ui/CalendarPagerView.kt |
| 79 | - com/vayunmathur/calendar/ui/AgendaView.kt |
| 80 | - com/vayunmathur/calendar/ui/WeekHeaderRow.kt |
| 81 | - com/vayunmathur/calendar/ui/HourScale.kt |
| 82 | - com/vayunmathur/calendar/ui/EventPositioner.kt |
| 83 | - com/vayunmathur/calendar/ui/CalendarSelector.kt |
| 84 | - com/vayunmathur/calendar/ui/CalendarViewHelpers.kt |
| 85 | - com/vayunmathur/calendar/ui/EditEventScreen.kt |
| 86 | - com/vayunmathur/calendar/ui/EditEventRow.kt |
| 87 | - com/vayunmathur/calendar/ui/EditEventDateTime.kt |
| 88 | - com/vayunmathur/calendar/ui/EditEventReminders.kt |
| 89 | - com/vayunmathur/calendar/ui/EventScreen.kt |
| 90 | - com/vayunmathur/calendar/ui/HolidayCalendarsScreen.kt |
| 91 | - com/vayunmathur/calendar/ui/IcsImport.kt |
| 92 | - com/vayunmathur/calendar/ui/ImportIcsScreen.kt |
| 93 | - com/vayunmathur/calendar/ui/SettingsScreen.kt |
| 94 | - com/vayunmathur/calendar/ui/SummaryEventItem.kt |
| 95 | - com/vayunmathur/calendar/ui/SummaryGrid.kt |
| 96 | - com/vayunmathur/calendar/ui/dialogs/RecurrenceDialog.kt |
| 97 | - com/vayunmathur/calendar/ui/dialogs/RecurrenceRuleBuild.kt |
| 98 | - com/vayunmathur/calendar/ui/dialogs/RecurrenceDates.kt |
| 99 | - com/vayunmathur/calendar/ui/dialogs/RecurrenceDialogComponents.kt |
| 100 | - com/vayunmathur/calendar/ui/dialogs/CalendarPickerDialog.kt |
| 101 | - com/vayunmathur/calendar/ui/dialogs/CalendarSetDateDialog.kt |
| 102 | - com/vayunmathur/calendar/ui/dialogs/SettingsAddCalendarDialog.kt |
| 103 | - com/vayunmathur/calendar/ui/dialogs/SettingsChangeColorDialog.kt |
| 104 | - com/vayunmathur/calendar/ui/dialogs/SettingsDefaultRemindersDialog.kt |
| 105 | - com/vayunmathur/calendar/ui/dialogs/SettingsDeleteCalendarDialog.kt |
| 106 | - com/vayunmathur/calendar/ui/dialogs/SettingsRenameCalendarDialog.kt |
| 107 | - com/vayunmathur/calendar/ui/dialogs/TimezonePickerDialog.kt |
| 108 | ### sync/ — wear companion sync (both sides, one APK) |
| 109 | - com/vayunmathur/calendar/sync/WearCalendarSync.kt — phone conduit client node; snapshot publish, watch-state receive, request-sync handling |
| 110 | - com/vayunmathur/calendar/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the store, watch-state publish |
| 111 | ### Watch experience (ui/ + data/ + domain/ + platform/) |
| 112 | - com/vayunmathur/calendar/ui/WearMainActivity.kt — watch entry (agenda + event detail from the synced store) |
| 113 | - com/vayunmathur/calendar/ui/WearRoute.kt, WearAgendaScreen.kt, WearEventScreen.kt |
| 114 | - com/vayunmathur/calendar/data/WearCalendarStore.kt — persisted watch snapshot (`wear-calendar-snapshot.json`) |
| 115 | - com/vayunmathur/calendar/domain/WearAgenda.kt — today/upcoming sectioning for the watch agenda |
| 116 | - com/vayunmathur/calendar/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`) |
| 117 | ### glance/ + intents/ — widgets and assistant IPC |
| 118 | - com/vayunmathur/calendar/glance/CalendarGlanceWidget.kt |
| 119 | - com/vayunmathur/calendar/glance/CalendarGlanceWidgetReceiver.kt |
| 120 | - com/vayunmathur/calendar/glance/CalendarMonthGlanceWidget.kt |
| 121 | - com/vayunmathur/calendar/glance/CalendarMonthGlanceWidgetReceiver.kt |
| 122 | - com/vayunmathur/calendar/intents/GetIntent.kt |
| 123 | - com/vayunmathur/calendar/intents/InsertIntent.kt |
| 124 | |
| 125 | ## Verify (this module only) |
| 126 | ``` |
| 127 | ./gradlew :calendar:compileDevKotlin |
| 128 | ./gradlew :calendar:lint |
| 129 | ./gradlew :calendar:checkMetadata |
| 130 | ``` |
| 131 | - Wear Tile: `service/CalendarTileService` (a `MaTileService` in `:library:weartiles`) renders the next upcoming event from `WearCalendarStore`; the store requests a tile update on every new snapshot, plus 15-minute freshness. Tap opens `WearMainActivity`. |