fix(edit): apply default reminder to ACTION_INSERT events (#49)

External ACTION_INSERT launches (e.g. Google Maps' "add to calendar",
the Todo Agenda widget) share the single-event .ics prefill channel:
CalendarHost routes requestedInsertForm as importForm, so EventEditScreen
calls openImported(), which froze reminders as touched to respect a file's
own VALARMs. But an insert intent carries no reminders, so the empty freeze
just suppressed the configured settings default — the event opened (and
saved) with no reminder.

Make the freeze follow the source, not the path: a form that carries its
own reminders (an .ics with VALARMs) still freezes them; a form with none
(every insert intent, and an .ics without VALARMs) falls back to the
settings default via applyDefaultReminder(), exactly like openNew(). An
intent that did carry reminders still wins.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-12 11:46:51 +02:00
parent bda002684c
commit 4f263d00fe

View File

@@ -241,18 +241,31 @@ class EventEditViewModel @Inject constructor(
}
/**
* Seed a fresh event from a parsed `.ics` file (the single-event "open into
* the create form" path). [form] already carries the file's fields; its
* [EventForm.calendarId] is null so the calendar still resolves to the
* last-used/first-writable one, and reminders are frozen as touched so the
* settings default never overwrites what the file specified. No-op when a
* form is already open, so the prefill survives configuration changes.
* Seed a fresh event from a prefilled [form] — a parsed single-event `.ics`
* file or an external `ACTION_INSERT` intent (another app/widget creating an
* event, e.g. Google Maps' "add to calendar"; #30, #49). [EventForm.calendarId]
* is null so the calendar still resolves to the last-used/first-writable one.
*
* Reminders follow the source rather than the path: a form that carries its
* own (an `.ics` with VALARMs) freezes them as touched, so the settings
* default never overwrites what it specified; a form with none — every
* insert intent, and an `.ics` without VALARMs — falls back to the settings
* default exactly like [openNew], instead of the empty freeze suppressing it.
* No-op when a form is already open, so the prefill survives configuration
* changes.
*/
fun openImported(form: EventForm) {
if (_form.value != null || _editTarget.value != null) return
_remindersTouched.value = true
_revealed.value = form.populatedFields()
_form.value = form
if (form.reminders.isNotEmpty()) {
// Source specified its own reminders — freeze so the default can't
// clobber them (and a later calendar/all-day switch won't re-apply).
_remindersTouched.value = true
} else {
// Nothing carried: inherit the settings default like a new event.
applyDefaultReminder()
}
}
/**