fix(#147, #325): review round 4 - standalone occurrences imported first in any file order, copy sheet independent of the list state
This commit is contained in:
1 parent
10208a332e
commit
041f8ec2f7
5 files changed
+40
-23
No files matched your search
+4
-2
@@ -298,7 +298,9 @@ class CalendarRepositoryImpl @Inject constructor(
|
||||
// Occurrences whose standalone copy didn't land, by series UID: the series
|
||||
// keeps them instead of excluding them for good.
|
||||
val unexcluded = mutableMapOf<String, MutableList<Instant>>()
|
||||
for ((index, event) in events.withIndex()) {
|
||||
// Standalone occurrences ahead of the series they were cut from, however the file is ordered.
|
||||
val ordered = events.sortedBy { it.overrideOf == null }
|
||||
for ((index, event) in ordered.withIndex()) {
|
||||
if (index > 0) onProgress(index)
|
||||
// A known UID means the event is already in this calendar — skip,
|
||||
// keeping a restore idempotent (no overwrite this pass).
|
||||
@@ -317,7 +319,7 @@ class CalendarRepositoryImpl @Inject constructor(
|
||||
Log.w(TAG, "Import stopped: the calendar is no longer writable", e)
|
||||
// A known UID would have been skipped whatever happened, so it is
|
||||
// no part of what a retry still has to import.
|
||||
val remaining = events.drop(index)
|
||||
val remaining = ordered.drop(index)
|
||||
val duplicates = remaining.count { it.isAlreadyIn(existing) }
|
||||
skipped += duplicates
|
||||
notAttempted = remaining.size - duplicates
|
||||
|
||||
@@ -184,6 +184,24 @@ fun BackupScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// Not gated on Ready: a running copy keeps its progress and Cancel whatever the list does.
|
||||
if (showCopy) {
|
||||
val calendars by copyViewModel.calendars.collectAsStateWithLifecycle()
|
||||
val selection by copyViewModel.selection.collectAsStateWithLifecycle()
|
||||
CopyEventsSheet(
|
||||
calendars = calendars,
|
||||
selection = selection,
|
||||
run = copyRun,
|
||||
onSelectSource = copyViewModel::setSource,
|
||||
onSelectTarget = copyViewModel::setTarget,
|
||||
onStart = copyViewModel::start,
|
||||
onCancel = copyViewModel::cancel,
|
||||
onDismiss = {
|
||||
showCopy = false
|
||||
copyViewModel.clearFinished()
|
||||
},
|
||||
)
|
||||
}
|
||||
// Gated on Ready rather than resetting the flag when the state leaves it:
|
||||
// flipping it here would be a write during composition.
|
||||
(state as? BackupUiState.Ready)?.let { ready ->
|
||||
@@ -194,23 +212,6 @@ fun BackupScreen(
|
||||
onDismiss = { showExportPicker = false },
|
||||
)
|
||||
}
|
||||
if (showCopy) {
|
||||
val calendars by copyViewModel.calendars.collectAsStateWithLifecycle()
|
||||
val selection by copyViewModel.selection.collectAsStateWithLifecycle()
|
||||
CopyEventsSheet(
|
||||
calendars = calendars,
|
||||
selection = selection,
|
||||
run = copyRun,
|
||||
onSelectSource = copyViewModel::setSource,
|
||||
onSelectTarget = copyViewModel::setTarget,
|
||||
onStart = copyViewModel::start,
|
||||
onCancel = copyViewModel::cancel,
|
||||
onDismiss = {
|
||||
showCopy = false
|
||||
copyViewModel.clearFinished()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (showBackupCalendars) {
|
||||
AutoBackupCalendarPicker(
|
||||
calendars = ready.exportable,
|
||||
@@ -301,11 +302,11 @@ private fun BackupContent(
|
||||
GroupedHint(restoreSummary, style = MaterialTheme.typography.bodySmall)
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.calendars_restore_action),
|
||||
position = Position.Alone,
|
||||
position = if (copyRun != CopyRunState.Idle) Position.Top else Position.Alone,
|
||||
leading = { LeadingAvatar(Icons.Default.FileUpload) },
|
||||
onClick = onRestoreClick,
|
||||
)
|
||||
if (copyRun != CopyRunState.Idle) CopyEventsRow(copyRun, Position.Alone, onCopy)
|
||||
if (copyRun != CopyRunState.Idle) CopyEventsRow(copyRun, Position.Bottom, onCopy)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ class CalendarsViewModel @Inject constructor(
|
||||
uri = uri,
|
||||
content = IcsWriter().writeCalendar(events, Clock.System.now(), name),
|
||||
)
|
||||
events.count { it.overrideOf == null }
|
||||
events.size
|
||||
}
|
||||
BackupResult.Success(count)
|
||||
} catch (e: CancellationException) {
|
||||
|
||||
+12
@@ -1066,6 +1066,18 @@ class CalendarRepositoryImplTest {
|
||||
assertThat(fake.importedEvents.single().first.exDates).containsExactly("20260119T090000Z")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a standalone occurrence listed after its series still goes first`(
|
||||
@TempDir tempDir: Path,
|
||||
) = runTest {
|
||||
val fake = FakeCalendarDataSource()
|
||||
val repo = testRepository(fake, tempDir, Dispatchers.Unconfined)
|
||||
|
||||
repo.importEvents(3L, listOf(parsedEvent("s"), parsedEvent("1-s").copy(overrideOf = "s")))
|
||||
|
||||
assertThat(fake.importedEvents.map { it.first.uid }).containsExactly("1-s", "s").inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a backup writes an RDATE-only series as the one-off a file can hold`(
|
||||
@TempDir tempDir: Path,
|
||||
|
||||
@@ -510,7 +510,9 @@ series there has the override itself — so restoring into the calendar a backup
|
||||
came from adds nothing twice, while a restore into an empty one gets both. The
|
||||
standalone event also names its occurrence (`X-CALENDULA-OVERRIDE-AT`); if it
|
||||
fails to insert, the series is inserted without that exclusion, so the
|
||||
occurrence stays at its original time rather than vanishing for good.
|
||||
occurrence stays at its original time rather than vanishing for good. The
|
||||
import inserts every such event ahead of the series, whatever order the file
|
||||
lists them in.
|
||||
Exceptions whose series isn't among the rows are left out, a cancelled
|
||||
series' moved occurrences stay cancelled, and sync ids link only within their
|
||||
own calendar. A file can't carry `RDATE`, so a backup treats a series that
|
||||
|
||||
Reference in new issue
Block a user