fix(#515, #325): review round 2 - multi-line and unreadable EXDATE handled, imports all or nothing per event, running copy survives list failures
This commit is contained in:
1 parent
028d8d0e1e
commit
05887d2ed0
7 files changed
+55
-32
No files matched your search
@@ -913,18 +913,25 @@ class AndroidCalendarDataSource @Inject constructor(
|
||||
} else {
|
||||
null
|
||||
}
|
||||
event.semanticReminderMinutes().forEach { minutes ->
|
||||
val providerMinutes = if (reminderDate != null) {
|
||||
toProviderAllDayMinutes(
|
||||
semanticMinutes = minutes,
|
||||
startDate = reminderDate,
|
||||
zone = zone,
|
||||
timeOfDayMinutes = allDayReminderTimeMinutes,
|
||||
)
|
||||
} else {
|
||||
minutes
|
||||
// All or nothing: a row whose reminders failed would count as not added
|
||||
// and still be there.
|
||||
try {
|
||||
event.semanticReminderMinutes().forEach { minutes ->
|
||||
val providerMinutes = if (reminderDate != null) {
|
||||
toProviderAllDayMinutes(
|
||||
semanticMinutes = minutes,
|
||||
startDate = reminderDate,
|
||||
zone = zone,
|
||||
timeOfDayMinutes = allDayReminderTimeMinutes,
|
||||
)
|
||||
} else {
|
||||
minutes
|
||||
}
|
||||
insertReminderRow(eventId, providerMinutes)
|
||||
}
|
||||
insertReminderRow(eventId, providerMinutes)
|
||||
} catch (t: Throwable) {
|
||||
runCatching { resolver.delete(eventUri(eventId), null, null) }
|
||||
throw t
|
||||
}
|
||||
return eventId
|
||||
}
|
||||
|
||||
@@ -96,15 +96,19 @@ internal fun exportExDates(
|
||||
eventTimezone: String? = null,
|
||||
): List<String> {
|
||||
if (exdate.isNullOrBlank()) return emptyList()
|
||||
val zone = exdateListZone(exdate, eventTimezone)
|
||||
return exdateStamps(exdate)
|
||||
.map { stamp ->
|
||||
// Several properties are stored one per line, each with its own zone prefix.
|
||||
return exdate.lines().filter { it.isNotBlank() }.flatMap { line ->
|
||||
val zone = exdateListZone(line, eventTimezone)
|
||||
exdateStamps(line).map { stamp ->
|
||||
if (isAllDay) {
|
||||
stamp.substringBefore('T')
|
||||
} else {
|
||||
canonicalExdateStamp(stamp, isAllDay = false, listZone = zone) ?: stamp
|
||||
}
|
||||
}
|
||||
}
|
||||
// A bare day on a timed series stays: a restore reads it at the series' time of day.
|
||||
.filter { EXPORTED_STAMP.matches(it) }
|
||||
.distinct()
|
||||
}
|
||||
|
||||
@@ -120,14 +124,14 @@ internal fun exportRecurrenceDates(
|
||||
eventTimezone: String? = null,
|
||||
): List<String> {
|
||||
if (rdate.isNullOrBlank()) return emptyList()
|
||||
// Several RDATE properties are stored one per line, each with its own zone prefix.
|
||||
return rdate.lines().filter { it.isNotBlank() }.flatMap { line ->
|
||||
// The zone prefix may hold a '/' of its own (Europe/Berlin), so only the stamps lose their period end.
|
||||
// The zone prefix may hold a '/' of its own (Europe/Berlin), so only the stamps lose their period end.
|
||||
val starts = rdate.lines().joinToString("\n") { line ->
|
||||
val stamps = line.withoutExdateParameters()
|
||||
val starts = line.dropLast(stamps.length) + stamps.split(',').joinToString(",") { it.substringBefore('/') }
|
||||
exportExDates(starts, isAllDay, eventTimezone)
|
||||
}.filter { RECURRENCE_DATE.matches(it) }.distinct()
|
||||
line.dropLast(stamps.length) + stamps.split(',').joinToString(",") { it.substringBefore('/') }
|
||||
}
|
||||
return exportExDates(starts, isAllDay, eventTimezone)
|
||||
}
|
||||
|
||||
private val RECURRENCE_DATE = Regex("""\d{8}(T\d{6}Z)?""")
|
||||
/** What a file and a provider both read back: a day, or a UTC stamp. */
|
||||
private val EXPORTED_STAMP = Regex("""\d{8}(T\d{6}Z)?""")
|
||||
|
||||
@@ -52,8 +52,9 @@ data class CalendarRows(
|
||||
* occurrence, so it is the same on every run. Overrides whose series isn't
|
||||
* among the rows are left out; the provider doesn't show them either.
|
||||
*
|
||||
* Standalone occurrences come first, so an import cut short leaves at worst an
|
||||
* occurrence missing its series, never a series missing an occurrence.
|
||||
* Standalone occurrences come first; `importEvents` enforces that order for
|
||||
* any file, so an import cut short leaves at worst an occurrence missing its
|
||||
* series, never a series missing an occurrence.
|
||||
*
|
||||
* [exdateStamp] formats an occurrence as an `EXDATE` entry in the provider's
|
||||
* shape, the same one Calendula's own exclusions use. A cancelled series'
|
||||
|
||||
@@ -398,13 +398,7 @@ private fun CopyEventsRow(copyRun: CopyRunState, position: Position, onClick: ()
|
||||
title = stringResource(R.string.calendars_copy_action),
|
||||
summary = when (copyRun) {
|
||||
is CopyRunState.Running -> copyProgressText(copyRun)
|
||||
is CopyRunState.Done -> stringResource(
|
||||
when {
|
||||
copyRun.stopped -> R.string.calendars_copy_stopped_title
|
||||
copyRun.summary.failed > 0 -> R.string.calendars_copy_partial
|
||||
else -> R.string.calendars_copy_done
|
||||
},
|
||||
)
|
||||
is CopyRunState.Done -> stringResource(copyRun.titleRes)
|
||||
CopyRunState.Cancelled -> stringResource(R.string.calendars_copy_cancelled)
|
||||
CopyRunState.Failed -> stringResource(R.string.calendars_copy_failed)
|
||||
CopyRunState.Idle -> stringResource(R.string.calendars_copy_summary)
|
||||
|
||||
@@ -74,7 +74,8 @@ fun CopyEventsSheet(
|
||||
},
|
||||
) {
|
||||
GroupedHint(stringResource(R.string.calendars_copy_hint), style = MaterialTheme.typography.bodySmall)
|
||||
when (calendars) {
|
||||
// A copy under way keeps its progress and Cancel whatever the list does.
|
||||
if (run == CopyRunState.Idle) when (calendars) {
|
||||
CopyCalendars.Loading -> {
|
||||
Box(Modifier.fillMaxWidth().padding(32.dp), contentAlignment = Alignment.Center) {
|
||||
CircularProgressIndicator()
|
||||
@@ -207,7 +208,7 @@ fun copyProgressText(run: CopyRunState.Running): String {
|
||||
private fun CopySummary(run: CopyRunState.Done) {
|
||||
val summary = run.summary
|
||||
Text(
|
||||
stringResource(if (run.stopped) R.string.calendars_copy_stopped_title else R.string.calendars_copy_done),
|
||||
stringResource(run.titleRes),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package de.jeanlucmakiola.calendula.ui.calendars
|
||||
|
||||
import android.util.Log
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import de.jeanlucmakiola.calendula.R
|
||||
import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository
|
||||
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
||||
import de.jeanlucmakiola.calendula.domain.ics.IcsImportSummary
|
||||
@@ -134,6 +136,14 @@ sealed interface CopyRunState {
|
||||
data class Done(val summary: IcsImportSummary) : CopyRunState {
|
||||
/** The target stopped taking events part way, so some were never tried. */
|
||||
val stopped: Boolean get() = summary.notAttempted > 0
|
||||
|
||||
/** How the run ended, the same words on the row and in the sheet. */
|
||||
@get:StringRes
|
||||
val titleRes: Int get() = when {
|
||||
stopped -> R.string.calendars_copy_stopped_title
|
||||
summary.failed > 0 -> R.string.calendars_copy_partial
|
||||
else -> R.string.calendars_copy_done
|
||||
}
|
||||
}
|
||||
data object Cancelled : CopyRunState
|
||||
data object Failed : CopyRunState
|
||||
|
||||
@@ -312,4 +312,10 @@ class IcsExportMapperTest {
|
||||
assertThat(exportRecurrenceDates("Europe/Berlin;20260110T100000\nAmerica/New_York;20260112T090000", isAllDay = false))
|
||||
.containsExactly("20260110T090000Z", "20260112T140000Z").inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an EXDATE stored over several lines keeps every line, unreadable stamps go`() {
|
||||
assertThat(exportExDates("Europe/Berlin;20260110T100000\nEurope/Berlin;20260117T100000,junk", isAllDay = false))
|
||||
.containsExactly("20260110T090000Z", "20260117T090000Z").inOrder()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user