diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsViewModel.kt index 4d25bae..fb745ec 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/calendars/CalendarsViewModel.kt @@ -75,18 +75,24 @@ class CalendarsViewModel @Inject constructor( ) /** - * Managed special-dates calendars whose deletion would not stick. While its - * type is enabled, the sync recreates a missing mirror on the next pass - * (`SpecialDatesSyncEngine.reconcileCalendars`), so the delete would appear - * to work and then undo itself. Turning special dates off empties this set, - * and deleting a leftover mirror is a real delete from then on. + * Managed special-dates calendars whose deletion would not stick. While the + * feature is on, the sync owns every mirror: it recreates a missing one for + * an enabled type on the next pass and deletes the leftover of a disabled + * one (`SpecialDatesSyncEngine.reconcileCalendars`), so either way the + * delete would appear to work and then undo itself. Turning special dates + * off empties this set, and deleting a leftover mirror is a real delete from + * then on. + * + * Read off each calendar's own durable marker ([CalendarSource.isManaged], + * the `CAL_SYNC2` one the editor lock already trusts) rather than the stored + * ids, which are only rewritten on the next sync pass — a preferences loss + * would otherwise unlock a live mirror until then. */ val deleteLockedCalendarIds: StateFlow> = combine( + calendars, settingsPrefs.specialDatesEnabled, - settingsPrefs.specialDatesTypes, - settingsPrefs.specialDatesCalendars, - ) { enabled, types, byType -> - if (!enabled) emptySet() else types.mapNotNull { byType[it] }.toSet() + ) { sources, enabled -> + if (!enabled) emptySet() else sources.filter { it.isManaged }.map { it.id }.toSet() } .flowOn(io) .stateIn(