calendar: show reminders, custom times, fix event delete (#823 #824 #825)
- Commit
86431d76d5255ce2cd7841ef73dd341df11dfb33- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-17 20:08 UTC (1 month ago)
- Parents
8a646d5
Diff
calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt b/calendar/src/main/java/com/vayunmathur/calendar/data/Event.ktindex c569847cb6..07ba6c170f 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/data/Event.kt@@ -48,6 +48,20 @@ data class Event( /** RRULE and RDATE are independent ways to repeat, and either one makes this a series. */ val isRecurring: Boolean get() = rrule != null || rdate.isNotEmpty() + /** Copy with [date] removed from the extra repeat dates. */+ fun withoutRdate(date: LocalDate): Event = copy(rdate = rdate - date)++ /**+ * RFC 5545 RDATE column value for this event's extra dates, or null when empty so the+ * column is cleared. Timed occurrences use the UTC datetime form: a date alone would be+ * read back as midnight, putting the occurrence at the wrong time of day.+ */+ fun rdateColumnValue(): String? =+ rdate.takeIf { it.isNotEmpty() }?.joinToString(",") { date ->+ if (allDay) date.toIcalBasic()+ else date.toIcalUtcDateTime(startDateTimeDisplay.time, TimeZone.of(timezone))+ }+ val startDateTimeDisplay: LocalDateTime get() = Instant.fromEpochMilliseconds(start).toLocalDateTime(TimeZone.of(timezone)) @@ -81,13 +95,7 @@ data class Event( put(CalendarContract.Events.RRULE, null as String?) } // Always written, including as null, so clearing the repeat also clears the dates.- put(- CalendarContract.Events.RDATE,- rdate.takeIf { it.isNotEmpty() }?.joinToString(",") { date ->- if (allDay) date.toIcalBasic()- else date.toIcalUtcDateTime(startDateTimeDisplay.time, tzObj)- },- )+ put(CalendarContract.Events.RDATE, rdateColumnValue()) put(CalendarContract.Events.ALL_DAY, if (allDay) 1 else 0) put(CalendarContract.Events.EVENT_TIMEZONE, tz) if (exdate.isNotEmpty()) {
calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarGlanceWidget.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarGlanceWidget.kt b/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarGlanceWidget.ktindex 61f9a6e7a9..7ed9391f14 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarGlanceWidget.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarGlanceWidget.kt@@ -53,7 +53,7 @@ import androidx.glance.LocalContext import kotlin.time.Clock /** Positioned events for the agenda widget, keyed by day. */-internal data class CalendarWidgetData(+data class CalendarWidgetData( val positionedEvents: Map<LocalDate, List<Instance>>, )
calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarMonthGlanceWidget.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarMonthGlanceWidget.kt b/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarMonthGlanceWidget.ktindex 3d0ee8c187..6aeda6bb78 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarMonthGlanceWidget.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/glance/CalendarMonthGlanceWidget.kt@@ -59,7 +59,7 @@ import kotlinx.datetime.toLocalDateTime import kotlin.time.Clock /** Month-grid data for the month widget, real or sample. */-internal data class MonthWidgetData(+data class MonthWidgetData( val monthLabel: String, val weeks: List<List<LocalDate>>, val eventsByDay: Map<LocalDate, List<Instance>>,
calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventReminders.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventReminders.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventReminders.ktindex 48c62a7ee2..1c76dd8a45 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventReminders.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventReminders.kt@@ -2,19 +2,29 @@ package com.vayunmathur.calendar.ui import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.input.KeyboardType+import androidx.compose.ui.unit.dp import com.vayunmathur.calendar.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.DropdownMenu import com.vayunmathur.library.ui.DropdownMenuItem import com.vayunmathur.library.ui.IconSchedule+import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Text+import androidx.compose.foundation.text.KeyboardOptions import com.vayunmathur.library.ui.R as UiR @Composable@@ -32,26 +42,105 @@ internal fun EditEventReminders( ) } var addReminderExpanded by remember { mutableStateOf(false) }+ var showCustomDialog by remember { mutableStateOf(false) } val available = REMINDER_PRESETS.filter { it !in reminders }- if (available.isNotEmpty()) {- Item(- { IconSchedule() },- {- Box {- Text(stringResource(R.string.add_reminder), Modifier.clickable { addReminderExpanded = true })- DropdownMenu(addReminderExpanded, { addReminderExpanded = false }) {- available.forEach { m ->+ // The Custom option means the add row always has something to offer, even when+ // every preset is already selected.+ Item(+ { IconSchedule() },+ {+ Box {+ Text(stringResource(R.string.add_reminder), Modifier.clickable { addReminderExpanded = true })+ DropdownMenu(addReminderExpanded, { addReminderExpanded = false }) {+ available.forEach { m ->+ DropdownMenuItem(+ text = { Text(reminderLabel(context, m)) },+ onClick = {+ addReminderExpanded = false+ onReminders((reminders + m).sorted())+ },+ )+ }+ DropdownMenuItem(+ text = { Text(stringResource(R.string.reminder_custom)) },+ onClick = {+ addReminderExpanded = false+ showCustomDialog = true+ },+ )+ }+ }+ },+ )+ if (showCustomDialog) {+ CustomReminderDialog(+ onDismiss = { showCustomDialog = false },+ onConfirm = { minutes ->+ showCustomDialog = false+ if (minutes !in reminders) onReminders((reminders + minutes).sorted())+ },+ )+ }+}++@Composable+private fun CustomReminderDialog(+ onDismiss: () -> Unit,+ onConfirm: (Int) -> Unit,+) {+ var amountStr by remember { mutableStateOf("") }+ var unitIndex by remember { mutableIntStateOf(1) }+ val units = listOf(+ stringResource(R.string.reminder_unit_minutes),+ stringResource(R.string.reminder_unit_hours),+ stringResource(R.string.reminder_unit_days),+ stringResource(R.string.reminder_unit_weeks),+ )+ val minutes = amountStr.toLongOrNull()+ ?.let { customReminderMinutes(it, REMINDER_UNIT_MULTIPLIERS[unitIndex]) }+ var unitExpanded by remember { mutableStateOf(false) }+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text(stringResource(R.string.reminder_custom_title)) },+ text = {+ Column {+ OutlinedTextField(+ value = amountStr,+ onValueChange = { amountStr = it.filter(Char::isDigit).take(9) },+ label = { Text(stringResource(R.string.reminder_custom_amount)) },+ singleLine = true,+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),+ )+ Box(Modifier.fillMaxWidth().padding(top = 8.dp)) {+ OutlinedTextField(+ value = units[unitIndex],+ onValueChange = {},+ readOnly = true,+ singleLine = true,+ modifier = Modifier.fillMaxWidth().clickable { unitExpanded = true },+ label = { Text(stringResource(R.string.reminder_custom_unit)) },+ )+ DropdownMenu(unitExpanded, { unitExpanded = false }) {+ units.forEachIndexed { i, label -> DropdownMenuItem(- text = { Text(reminderLabel(context, m)) },+ text = { Text(label) }, onClick = {- addReminderExpanded = false- onReminders((reminders + m).sorted())+ unitIndex = i+ unitExpanded = false }, ) } } }- },- )- }+ }+ },+ confirmButton = {+ Button(onClick = { minutes?.let(onConfirm) }, enabled = minutes != null) {+ Text(stringResource(UiR.string.add))+ }+ },+ dismissButton = {+ Button(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+ },+ ) }
calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventRow.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventRow.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventRow.ktindex aceb9448a7..d185f7aa01 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventRow.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/EditEventRow.kt@@ -35,6 +35,20 @@ internal fun Item(icon: @Composable () -> Unit = {}, left: @Composable () -> Uni /** Common reminder offsets, in minutes before the event start. */ val REMINDER_PRESETS = listOf(0, 5, 10, 15, 30, 60, 120, 1440) +/** Minute multipliers for the custom-reminder unit picker, in dropdown order. */+val REMINDER_UNIT_MULTIPLIERS = listOf(1, 60, 24 * 60, 7 * 24 * 60)++/**+ * Minutes-before for a custom reminder of [amount] [unitMinutes]-minute units, or null when the+ * amount is not positive or the total does not fit an Int.+ */+fun customReminderMinutes(amount: Long, unitMinutes: Int): Int? {+ if (amount < 1 || unitMinutes < 1) return null+ // Divide before multiplying: amount * unitMinutes can overflow Long for huge amounts.+ if (amount > Int.MAX_VALUE / unitMinutes) return null+ return (amount * unitMinutes).toInt()+}+ fun reminderLabel(context: Context, minutes: Int): String = when { minutes <= 0 -> context.getString(R.string.reminder_at_time_of_event) minutes % 1440 == 0 -> context.resources.getQuantityString(R.plurals.reminder_days_before, minutes / 1440, minutes / 1440)
calendar/src/main/java/com/vayunmathur/calendar/ui/EventScreen.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/EventScreen.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/EventScreen.ktindex 282f59035a..4d1a61cfe6 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/ui/EventScreen.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/EventScreen.kt@@ -42,6 +42,7 @@ import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconDescription import com.vayunmathur.library.ui.IconEdit import com.vayunmathur.library.ui.IconGlobe+import com.vayunmathur.library.ui.IconSchedule import com.vayunmathur.library.ui.rememberMessenger import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.sharedText@@ -189,6 +190,13 @@ fun EventScreen(state: EventUiState, actions: EventActions) { }, leadingContent = { IconDescription() })+ if (event.reminders.isNotEmpty()) ListItem({+ Text(event.reminders.sorted().joinToString(", ") { reminderLabel(context, it) })+ }, leadingContent = {+ IconSchedule()+ }, supportingContent = {+ Text(stringResource(R.string.reminders))+ }) if(event.location.isNotBlank()) ListItem( { Text(event.location, modifier = Modifier.sharedText("calendar-event-location-${event.id}")) }, Modifier.clickable {
calendar/src/main/java/com/vayunmathur/calendar/ui/IcsParser.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/IcsParser.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/IcsParser.ktindex ac5978bd72..b17bb85e54 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/ui/IcsParser.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/IcsParser.kt@@ -2,8 +2,12 @@ package com.vayunmathur.calendar.ui import com.vayunmathur.library.log.Log import com.vayunmathur.calendar.data.Event+import com.vayunmathur.calendar.util.AllDayFormat import com.vayunmathur.calendar.util.RRule+import kotlinx.datetime.DatePeriod+import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone+import kotlinx.datetime.minus import kotlinx.datetime.toLocalDateTime import java.io.BufferedInputStream import java.io.InputStream@@ -132,6 +136,10 @@ private fun handlePropertyLine( current["DTEND"] = value current["DTEND_PROP"] = left }+ "RECURRENCE-ID" -> {+ current["RECURRENCE-ID"] = value+ current["RECURRENCE-ID_PROP"] = left+ } "RDATE" -> rdateProps.add(left to value) "EXDATE" -> exdateProps.add(left to value) else -> current[propName] = value@@ -179,10 +187,15 @@ private fun buildEventFromProps( val rdate = parseIcsDates(rdateProps, zone).filter { it != startDate } val exdate = parseIcsDates(exdateProps, zone) + val recurrenceId = recurrenceIdDate(current, zone) val evt = Event(id, -1, title, description, location, null, startMillis, endMillis, timezone, startAllDay, rrule, exdate = exdate, rdate = rdate, reminders = alarmReminders.distinct().sorted())- events.add(evt)+ if (recurrenceId == null) {+ events.add(evt)+ } else {+ applyRecurrenceOverride(events, evt, recurrenceId, current)+ } added = true } } catch (expected: Exception) {@@ -190,3 +203,83 @@ private fun buildEventFromProps( } return added }++/** The day a RECURRENCE-ID names, or null when this VEVENT is not an override. */+internal fun recurrenceIdDate(current: Map<String, String>, zone: TimeZone): LocalDate? {+ val raw = current["RECURRENCE-ID"] ?: return null+ // Pair RECURRENCE-ID with its own property line (TZID=...), not DTSTART's.+ val propLeft = current["RECURRENCE-ID_PROP"] ?: ""+ return recurrenceIdDateFrom(raw, propLeft, zone)+}++/** Splits one RECURRENCE-ID value into its occurrence day, resolved in [zone]. */+internal fun recurrenceIdDateFrom(raw: String, propLeft: String, zone: TimeZone): LocalDate? {+ val value = raw.trim().substringAfterLast(':')+ if (value.length == 8 && value.all { it.isDigit() }) {+ return runCatching { AllDayFormat.parse(value) }.getOrNull()+ }+ val (millis, _, _) = parseICSTime(propLeft, value)+ return millis?.let { Instant.fromEpochMilliseconds(it).toLocalDateTime(zone).date }+}++/**+ * Folds a RECURRENCE-ID override VEVENT into the series parsed from the same UID.+ *+ * Exporters express a changed or deleted occurrence as a second VEVENT carrying the same UID+ * plus RECURRENCE-ID naming the overridden date. Without this the override arrives as its own+ * event, and its ghost occurrence stays in the series forever (#825).+ *+ * - plain RECURRENCE-ID: cut the date out of the series (RRULE -> EXDATE, RDATE -> dropped)+ * and, when the override carries its own DTSTART, re-insert it standalone;+ * - RANGE=THISANDFUTURE: truncate the series before the date (RRULE gets an UNTIL, later+ * RDATEs are dropped) and start the override as the new series there.+ *+ * The series is found by UID hash, matching the ids assigned in [buildEventFromProps].+ */+internal fun applyRecurrenceOverride(+ events: MutableList<Event>,+ override: Event,+ recurrenceId: LocalDate,+ current: Map<String, String>,+) {+ val seriesIndex = events.indexOfFirst { it.id == override.id && it.isRecurring }+ if (seriesIndex < 0) {+ // No series seen for this UID (or the override came first): keep the occurrence+ // standalone rather than dropping the user's data.+ events.add(override.copy(rrule = null, rdate = emptyList(), exdate = emptyList()))+ return+ }+ val series = events[seriesIndex]+ val thisAndFuture = current["RECURRENCE-ID_PROP"]?.uppercase()?.contains("RANGE=THISANDFUTURE") == true+ // Only STATUS:CANCELLED marks a deleted occurrence. DTSTART alone cannot: an override whose+ // DTSTART matches the recurrence id may be a deletion marker, but it may also carry updated+ // metadata (a renamed occurrence at the same time). Treating a match as deleted would+ // silently drop the latter, so a match without CANCELLED is kept as a standalone event.+ val isDeletion = current["STATUS"]?.equals("CANCELLED", ignoreCase = true) == true+ if (thisAndFuture) {+ val truncated = series.copy(+ rrule = series.rrule?.let { rule ->+ rule.withEnd(RRule.EndCondition.Until(recurrenceId.minus(DatePeriod(days = 1))))+ },+ rdate = series.rdate.filter { it < recurrenceId },+ exdate = series.exdate.filter { it < recurrenceId },+ )+ events[seriesIndex] = truncated+ if (!isDeletion) {+ events.add(override.copy(exdate = emptyList()))+ }+ return+ }+ // Cut the date out of the series. An RDATE-listed date is dropped from the list (an+ // EXDATE would be meaningless there — EXDATE only suppresses RRULE-generated instances);+ // an RRULE occurrence is suppressed via EXDATE.+ val cut = if (series.rdate.contains(recurrenceId)) {+ series.copy(rdate = series.rdate.filter { it != recurrenceId })+ } else {+ series.copy(exdate = (series.exdate + recurrenceId).distinct().sorted())+ }+ events[seriesIndex] = cut+ if (!isDeletion) {+ events.add(override.copy(rrule = null, rdate = emptyList(), exdate = emptyList()))+ }+}
calendar/src/main/java/com/vayunmathur/calendar/util/CalendarViewModel.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/util/CalendarViewModel.kt b/calendar/src/main/java/com/vayunmathur/calendar/util/CalendarViewModel.ktindex cf68c87e5e..b274a2a890 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/util/CalendarViewModel.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/util/CalendarViewModel.kt@@ -360,17 +360,66 @@ class CalendarViewModel(application: Application) : } } + /**+ * Deletes the whole series for [eventId] from the provider.+ *+ * Imported and recurring events reported undeletable (#825): marking DELETED only asked+ * a sync adapter to delete later, which for a local calendar never comes. A real+ * `delete()` removes the row now; the DELETED-flag update stays as the fallback when+ * the provider refuses it.+ */ override fun deleteEventSeries(eventId: Long) {- upsertEvent(eventId, ContentValues().apply {- put(CalendarContract.Events.DELETED, 1)- })+ val app = getApplication<Application>()+ viewModelScope.launch(Dispatchers.IO) {+ val deleted = try {+ app.contentResolver.delete(+ CalendarContract.Events.CONTENT_URI,+ "${CalendarContract.Events._ID} = ?",+ arrayOf(eventId.toString()),+ )+ } catch (expected: Exception) {+ Log.error("CalendarViewModel", "Error deleting event", expected)+ 0+ }+ if (deleted > 0) {+ _events.value = Event.getAllEvents(app)+ ReminderScheduler.reconcileAll(app, _events.value)+ updateWidgets()+ } else {+ // The provider refused the delete (e.g. a read-only calendar it would not+ // remove): flag it instead so the row at least hides from our queries.+ upsertEvent(eventId, ContentValues().apply {+ put(CalendarContract.Events.DELETED, 1)+ })+ withContext(Dispatchers.Main) {+ AppMessages.show(app.getString(R.string.event_delete_failed))+ }+ }+ } } + /**+ * Removes one occurrence starting at [instanceBeginTime] from the series for [eventId].+ *+ * RRULE occurrences are excluded via EXDATE; RDATE occurrences live in the event's own+ * date list instead, so those are stripped there. A non-series event has no occurrence+ * to cut out, so deleting its "instance" deletes the event.+ */ override fun deleteEventInstance(eventId: Long, instanceBeginTime: Long) { val event = _events.value.find { it.id == eventId } ?: return+ if (!event.isRecurring) {+ deleteEventSeries(eventId)+ return+ } val zone = TimeZone.of(event.timezone) val instanceDate = Instant.fromEpochMilliseconds(instanceBeginTime) .toLocalDateTime(zone).date+ if (event.rdate.contains(instanceDate)) {+ upsertEvent(eventId, ContentValues().apply {+ put(CalendarContract.Events.RDATE, event.withoutRdate(instanceDate).rdateColumnValue())+ })+ return+ } // Timed occurrences need the datetime form; a date-only EXDATE is ignored // by the provider for timed events and the delete silently no-ops. val exdateStr = (event.exdate + instanceDate).distinct().joinToString(",") { date ->
calendar/src/main/res/values/strings.xml
diff --git a/calendar/src/main/res/values/strings.xml b/calendar/src/main/res/values/strings.xmlindex 1c45e98366..1abfd67351 100644--- a/calendar/src/main/res/values/strings.xml+++ b/calendar/src/main/res/values/strings.xml@@ -208,6 +208,8 @@ <string name="delete_this_event">Delete this event</string> <!-- Option to delete all occurrences of recurring event --> <string name="delete_all_events">Delete all events</string>+ <!-- Shown when the provider refused to delete an event. Sentence -->+ <string name="event_delete_failed">Couldn\'t delete the event</string> <!-- Edit event: save-scope chooser for recurring events, mirrors the delete options --> <!-- Option to apply edits to only this occurrence of a recurring event -->@@ -273,6 +275,8 @@ <string name="reminder_at_time_of_event">At time of event</string> <!-- Title of the dialog for setting a calendar's default reminders (Settings > calendar reminders action) --> <string name="default_reminders">Default reminders</string>+ <!-- Event details: section header above the reminder list. Noun, plural -->+ <string name="reminders">Reminders</string> <!-- Description at the top of the default-reminders dialog. %1$s = calendar display name --> <string name="default_reminders_description">Reminders added automatically to new events in <xliff:g id="calendar_name" example="Work">%1$s</xliff:g>.</string> <!-- Toggle in the default-reminders dialog: also apply the chosen reminders to events already in the calendar -->@@ -298,6 +302,22 @@ <!-- %1$d = minute count plural --> <item quantity="other"><xliff:g id="count" example="15">%1$d</xliff:g> minutes before</item> </plurals>+ <!-- Reminder picker: opens the dialog for a non-preset time. Adjective -->+ <string name="reminder_custom">Custom</string>+ <!-- Custom reminder dialog: title. Noun phrase -->+ <string name="reminder_custom_title">Custom reminder</string>+ <!-- Custom reminder dialog: label for the numeric amount field. Noun -->+ <string name="reminder_custom_amount">Amount</string>+ <!-- Custom reminder dialog: label for the time-unit dropdown. Noun -->+ <string name="reminder_custom_unit">Unit</string>+ <!-- Custom reminder dialog: time-unit options. Nouns, plural -->+ <string name="reminder_unit_minutes">Minutes</string>+ <!-- Custom reminder dialog: hours unit option -->+ <string name="reminder_unit_hours">Hours</string>+ <!-- Custom reminder dialog: days unit option -->+ <string name="reminder_unit_days">Days</string>+ <!-- Custom reminder dialog: weeks unit option -->+ <string name="reminder_unit_weeks">Weeks</string> <!-- Recurrence summary descriptions (RRule.describe): human-readable repeat rule --> <!-- Recurrence summary: event repeats daily -->
calendar/src/test/java/com/vayunmathur/calendar/data/EventRdateTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/data/EventRdateTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/data/EventRdateTest.ktnew file mode 100644index 0000000000..f601262c35--- /dev/null+++ b/calendar/src/test/java/com/vayunmathur/calendar/data/EventRdateTest.kt@@ -0,0 +1,49 @@+package com.vayunmathur.calendar.data++import kotlinx.datetime.LocalDate+import kotlinx.datetime.LocalDateTime+import kotlinx.datetime.LocalTime+import kotlinx.datetime.TimeZone+import kotlinx.datetime.toInstant+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull++class EventRdateTest {++ private fun event(rdate: List<LocalDate>, allDay: Boolean = false) = Event(+ id = 1,+ calendarID = 1,+ title = "Test",+ description = "",+ location = "",+ color = null,+ start = LocalDateTime(LocalDate(2025, 7, 4), LocalTime(9, 0))+ .toInstant(TimeZone.of("America/New_York")).toEpochMilliseconds(),+ end = LocalDateTime(LocalDate(2025, 7, 4), LocalTime(10, 0))+ .toInstant(TimeZone.of("America/New_York")).toEpochMilliseconds(),+ timezone = "America/New_York",+ allDay = allDay,+ rrule = null,+ rdate = rdate,+ )++ @Test+ fun withoutRdateDropsOnlyThatDate() {+ val cut = event(listOf(LocalDate(2025, 7, 8), LocalDate(2025, 7, 12)))+ .withoutRdate(LocalDate(2025, 7, 8))+ assertEquals(listOf(LocalDate(2025, 7, 12)), cut.rdate)+ }++ @Test+ fun timedRdateColumnUsesUtcDateTimes() {+ // 9 AM New York in July is 13:00 UTC.+ val value = event(listOf(LocalDate(2025, 7, 8))).rdateColumnValue()+ assertEquals("20250708T130000Z", value)+ }++ @Test+ fun emptyRdateColumnIsNullSoTheColumnClears() {+ assertNull(event(emptyList()).rdateColumnValue())+ }+}
calendar/src/test/java/com/vayunmathur/calendar/ui/CustomReminderTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/ui/CustomReminderTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/ui/CustomReminderTest.ktnew file mode 100644index 0000000000..5382eef764--- /dev/null+++ b/calendar/src/test/java/com/vayunmathur/calendar/ui/CustomReminderTest.kt@@ -0,0 +1,28 @@+package com.vayunmathur.calendar.ui++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull++class CustomReminderTest {++ @Test+ fun eachUnitMultipliesToMinutes() {+ assertEquals(45, customReminderMinutes(45, REMINDER_UNIT_MULTIPLIERS[0]))+ assertEquals(120, customReminderMinutes(2, REMINDER_UNIT_MULTIPLIERS[1]))+ assertEquals(4320, customReminderMinutes(3, REMINDER_UNIT_MULTIPLIERS[2]))+ assertEquals(10080, customReminderMinutes(1, REMINDER_UNIT_MULTIPLIERS[3]))+ }++ @Test+ fun zeroOrNegativeAmountIsRejected() {+ assertNull(customReminderMinutes(0, 1))+ assertNull(customReminderMinutes(-3, 60))+ }++ @Test+ fun overflowIsRejected() {+ assertNull(customReminderMinutes(Long.MAX_VALUE, 7 * 24 * 60))+ assertNull(customReminderMinutes(Int.MAX_VALUE.toLong() + 1, 1))+ }+}
calendar/src/test/java/com/vayunmathur/calendar/ui/IcsImportTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/ui/IcsImportTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/ui/IcsImportTest.ktindex 1855f087d1..6c0d922c79 100644--- a/calendar/src/test/java/com/vayunmathur/calendar/ui/IcsImportTest.kt+++ b/calendar/src/test/java/com/vayunmathur/calendar/ui/IcsImportTest.kt@@ -1,5 +1,6 @@ package com.vayunmathur.calendar.ui +import com.vayunmathur.calendar.util.RRule import kotlinx.datetime.LocalDate import kotlin.test.Test import kotlin.test.assertEquals@@ -104,4 +105,134 @@ class IcsImportTest { assertTrue(events[0].exdate.isEmpty()) assertTrue(!events[0].isRecurring) }++ private fun parseAll(vararg blocks: List<String>) = parseICSFile(+ (+ listOf("BEGIN:VCALENDAR", "VERSION:2.0") ++ blocks.flatMap { listOf("BEGIN:VEVENT") + it + listOf("END:VEVENT") } ++ listOf("END:VCALENDAR")+ ).joinToString("\r\n").byteInputStream()+ )++ @Test+ fun aDeletedOccurrenceArrivesAsAnExdate() {+ val events = parseAll(+ listOf(+ "UID:series-1",+ "SUMMARY:Standup",+ "DTSTART:20250707T090000Z",+ "DTEND:20250707T093000Z",+ "RRULE:FREQ=DAILY;INTERVAL=1",+ ),+ listOf(+ "UID:series-1",+ "SUMMARY:Standup",+ "DTSTART:20250708T090000Z",+ "DTEND:20250708T093000Z",+ "RECURRENCE-ID:20250708T090000Z",+ "STATUS:CANCELLED",+ ),+ )+ assertEquals(1, events.size)+ assertEquals(listOf(LocalDate(2025, 7, 8)), events[0].exdate)+ }++ @Test+ fun aChangedOccurrenceIsCutOutAndReinserted() {+ val events = parseAll(+ listOf(+ "UID:series-2",+ "SUMMARY:Standup",+ "DTSTART:20250707T090000Z",+ "DTEND:20250707T093000Z",+ "RRULE:FREQ=DAILY;INTERVAL=1",+ ),+ listOf(+ "UID:series-2",+ "SUMMARY:Standup moved",+ "DTSTART:20250708T100000Z",+ "DTEND:20250708T103000Z",+ "RECURRENCE-ID:20250708T090000Z",+ ),+ )+ assertEquals(2, events.size)+ val series = events.first { it.isRecurring }+ val moved = events.first { !it.isRecurring }+ assertEquals(listOf(LocalDate(2025, 7, 8)), series.exdate)+ assertEquals("Standup moved", moved.title)+ }++ @Test+ fun aDeletedRdateIsDroppedFromTheDateList() {+ val events = parseAll(+ listOf(+ "UID:series-3",+ "SUMMARY:Custom repeats",+ "DTSTART;VALUE=DATE:20250704",+ "DTEND;VALUE=DATE:20250705",+ "RDATE;VALUE=DATE:20250708,20250712",+ ),+ listOf(+ "UID:series-3",+ "SUMMARY:Custom repeats",+ "DTSTART;VALUE=DATE:20250708",+ "RECURRENCE-ID;VALUE=DATE:20250708",+ "STATUS:CANCELLED",+ ),+ )+ assertEquals(1, events.size)+ assertEquals(listOf(LocalDate(2025, 7, 12)), events[0].rdate)+ assertTrue(events[0].exdate.isEmpty())+ }++ @Test+ fun anOverrideWithoutCancelStatusIsKeptStandalone() {+ // No STATUS:CANCELLED: the override is kept as its own event (it may carry updated+ // metadata), while the date is still cut from the series so it does not show twice.+ val events = parseAll(+ listOf(+ "UID:series-3b",+ "SUMMARY:Custom repeats",+ "DTSTART;VALUE=DATE:20250704",+ "DTEND;VALUE=DATE:20250705",+ "RDATE;VALUE=DATE:20250708,20250712",+ ),+ listOf(+ "UID:series-3b",+ "SUMMARY:Custom repeats renamed",+ "DTSTART;VALUE=DATE:20250708",+ "RECURRENCE-ID;VALUE=DATE:20250708",+ ),+ )+ assertEquals(2, events.size)+ val series = events.first { it.isRecurring }+ assertEquals(listOf(LocalDate(2025, 7, 12)), series.rdate)+ assertEquals("Custom repeats renamed", events.first { !it.isRecurring }.title)+ }++ @Test+ fun thisAndFutureTruncatesTheSeries() {+ val events = parseAll(+ listOf(+ "UID:series-4",+ "SUMMARY:Standup",+ "DTSTART:20250707T090000Z",+ "DTEND:20250707T093000Z",+ "RRULE:FREQ=DAILY;INTERVAL=1",+ ),+ listOf(+ "UID:series-4",+ "SUMMARY:Standup moved",+ "DTSTART:20250710T100000Z",+ "DTEND:20250710T103000Z",+ "RECURRENCE-ID;RANGE=THISANDFUTURE:20250710T090000Z",+ ),+ )+ assertEquals(2, events.size)+ val truncated = events.first { it.isRecurring }+ val tail = events.first { !it.isRecurring }+ val end = truncated.rrule?.endCondition as? RRule.EndCondition.Until+ assertEquals(LocalDate(2025, 7, 9), end?.date)+ assertEquals("Standup moved", tail.title)+ } }