diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b272d8e9..17ee1eb7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -56,6 +56,10 @@
+
+
+
+
.withAdapter(): Set {
+ val candidates = filter { it.isSyncable }
+ if (candidates.isEmpty()) return emptySet()
+ val adapterTypes = try {
+ syncRequester.adapterAccountTypes()
+ } catch (e: Exception) {
+ Log.w(TAG, "Sync adapters unreadable", e)
+ return emptySet()
+ }
+ return candidates.filterTo(linkedSetOf()) { it.type in adapterTypes }
}
private fun requestSync(account: SyncAccount, userInitiated: Boolean): Boolean = try {
@@ -140,11 +146,16 @@ class CalendarRepositoryImpl @Inject constructor(
false
}
- private fun eventCalendar(eventId: Long, original: EventForm? = null): suspend () -> Collection =
- { listOf(original?.calendarId ?: dataSource.eventCalendarId(eventId)) }
+ /** The event's own calendar (from [original] when given, else read), plus [others]. */
+ private fun eventCalendar(
+ eventId: Long,
+ original: EventForm? = null,
+ vararg others: Long?,
+ ): suspend () -> Collection =
+ { listOf(original?.calendarId ?: dataSource.eventCalendarId(eventId), *others) }
private fun syncTargets(calendars: List): Set =
- calendars.syncAccounts().filterTo(linkedSetOf(), ::canSync)
+ calendars.syncAccounts().withAdapter()
override val canRequestSync: Flow
get() = calendars().map { syncTargets(it).isNotEmpty() }.distinctUntilChanged().flowOn(io)
@@ -158,10 +169,12 @@ class CalendarRepositoryImpl @Inject constructor(
Log.w(TAG, "Sync request skipped: calendars unreadable", e)
return@withContext SyncRequestResult.Failed
}
- when {
- accounts.isEmpty() -> SyncRequestResult.NothingToSync
- accounts.count { requestSync(it, userInitiated = true) } > 0 -> SyncRequestResult.Requested
- else -> SyncRequestResult.Failed
+ if (accounts.isEmpty()) return@withContext SyncRequestResult.NothingToSync
+ val sent = accounts.count { requestSync(it, userInitiated = true) }
+ when (sent) {
+ accounts.size -> SyncRequestResult.Requested
+ 0 -> SyncRequestResult.Failed
+ else -> SyncRequestResult.PartlyFailed
}
}
@@ -383,7 +396,7 @@ class CalendarRepositoryImpl @Inject constructor(
eventId: Long,
original: EventForm,
updated: EventForm,
- ) = write({ listOf(original.calendarId ?: dataSource.eventCalendarId(eventId), updated.calendarId) }) {
+ ) = write(eventCalendar(eventId, original, updated.calendarId)) {
dataSource.updateEvent(eventId, original, updated, allDayReminderTimeMinutes())
}
@@ -396,7 +409,7 @@ class CalendarRepositoryImpl @Inject constructor(
targetCalendarId: Long,
original: EventForm,
updated: EventForm,
- ): Long = write({ listOf(original.calendarId ?: dataSource.eventCalendarId(eventId), targetCalendarId) }) {
+ ): Long = write(eventCalendar(eventId, original, targetCalendarId)) {
dataSource.moveEvent(
eventId, targetCalendarId, original, updated, allDayReminderTimeMinutes(),
)
diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/SyncRequester.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/SyncRequester.kt
index e8654686..ddcd20df 100644
--- a/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/SyncRequester.kt
+++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/SyncRequester.kt
@@ -20,8 +20,8 @@ data class SyncAccount(val name: String, val type: String) {
* itself stays the adapter's job; this only schedules it.
*/
interface SyncRequester {
- /** Whether a calendar sync adapter is installed for [accountType]; without one a request does nothing. */
- fun hasAdapter(accountType: String): Boolean
+ /** Account types with a calendar sync adapter installed; for any other a request does nothing. */
+ fun adapterAccountTypes(): Set
/**
* Schedule a sync of [account]; may throw if the system refuses. [userInitiated]
@@ -32,10 +32,11 @@ interface SyncRequester {
@Singleton
class AndroidSyncRequester @Inject constructor() : SyncRequester {
- override fun hasAdapter(accountType: String): Boolean =
- ContentResolver.getSyncAdapterTypes().any {
- it.authority == CalendarContract.AUTHORITY && it.accountType == accountType
- }
+ // Lists only adapters in packages visible to the app — hence the SyncAdapter entry.
+ override fun adapterAccountTypes(): Set =
+ ContentResolver.getSyncAdapterTypes()
+ .filter { it.authority == CalendarContract.AUTHORITY }
+ .mapTo(mutableSetOf()) { it.accountType }
override fun requestSync(account: SyncAccount, userInitiated: Boolean) {
val extras = Bundle().apply {
@@ -57,4 +58,4 @@ fun List.syncAccounts(): Set =
.filterTo(linkedSetOf()) { it.isSyncable }
/** Outcome of a user-triggered sync request (#240). */
-enum class SyncRequestResult { Requested, NothingToSync, Failed }
+enum class SyncRequestResult { Requested, PartlyFailed, NothingToSync, Failed }
diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/CalendarHost.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/CalendarHost.kt
index d8922ff9..a84f8c68 100644
--- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/CalendarHost.kt
+++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/CalendarHost.kt
@@ -701,8 +701,8 @@ fun CalendarHost(
EventMoveHost(
reschedule,
modifier = Modifier.fillMaxSize(),
- actionFailure = selectionFailureMessage ?: syncMessage,
- onActionFailureShown = {
+ notice = selectionFailureMessage ?: syncMessage,
+ onNoticeShown = {
if (selectionFailureMessage != null) eventActions.consumeFailure() else sync.consumeResult()
},
)
diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/CalendarDrawer.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/CalendarDrawer.kt
index b6f655bf..602bf99a 100644
--- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/CalendarDrawer.kt
+++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/CalendarDrawer.kt
@@ -41,6 +41,8 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.unit.dp
import de.jeanlucmakiola.calendula.R
import de.jeanlucmakiola.calendula.ui.filter.CalendarFilterList
@@ -150,9 +152,16 @@ data class DrawerSync(val inFlight: Boolean, val onSync: () -> Unit)
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
private fun SyncNowRow(sync: DrawerSync) {
+ val inFlightText = stringResource(R.string.sync_requested)
GroupedRow(
title = stringResource(R.string.drawer_sync_now),
position = Position.Bottom,
+ modifier = if (sync.inFlight) {
+ Modifier.semantics { stateDescription = inFlightText }
+ } else {
+ Modifier
+ },
+ dimmed = sync.inFlight,
minHeight = 56.dp,
leading = { DrawerLeadingIcon(Icons.Filled.Sync) },
trailing = if (sync.inFlight) {
diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventMoveHost.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventMoveHost.kt
index 542222aa..2a0b539e 100644
--- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventMoveHost.kt
+++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventMoveHost.kt
@@ -51,8 +51,8 @@ private val FAB_BAND = 88.dp
fun EventMoveHost(
viewModel: RescheduleViewModel,
modifier: Modifier = Modifier,
- actionFailure: String? = null,
- onActionFailureShown: () -> Unit = {},
+ notice: String? = null,
+ onNoticeShown: () -> Unit = {},
) {
val prompt by viewModel.scopePrompt.collectAsStateWithLifecycle()
val outcome by viewModel.outcome.collectAsStateWithLifecycle()
@@ -81,7 +81,7 @@ fun EventMoveHost(
}
// A failed selection action (#141) shares the chip rather than stacking on it.
val message = when (outcome) {
- null -> actionFailure
+ null -> notice
is MoveOutcome.Moved -> if (resizedLabel != null) {
stringResource(R.string.event_resize_done, resizedLabel)
} else {
@@ -116,10 +116,10 @@ fun EventMoveHost(
viewModel.consumeOutcome()
}
// A failure waits for the chip to be free, then has its own turn.
- LaunchedEffect(actionFailure, outcome == null) {
- if (actionFailure == null || outcome != null) return@LaunchedEffect
+ LaunchedEffect(notice, outcome == null) {
+ if (notice == null || outcome != null) return@LaunchedEffect
delay(CHIP_MILLIS)
- onActionFailureShown()
+ onNoticeShown()
}
BoxWithConstraints(modifier = modifier.fillMaxSize()) {
@@ -138,7 +138,7 @@ fun EventMoveHost(
// write anyway, so offering it would be a button that does nothing.
val undo = content.undo?.takeIf { !writeInFlight }
SnackChip(
- visible = outcome != null || actionFailure != null,
+ visible = outcome != null || notice != null,
message = content.message,
maxWidth = chipMaxWidth,
actionLabel = stringResource(R.string.event_move_undo).takeIf { undo != null },
diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/SyncViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/SyncViewModel.kt
index 70e05048..b80a822a 100644
--- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/SyncViewModel.kt
+++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/SyncViewModel.kt
@@ -46,6 +46,8 @@ class SyncViewModel @Inject constructor(
fun requestSync() {
if (_inFlight.value) return
_inFlight.value = true
+ // A repeat receipt must land as a new one, restarting the chip.
+ _result.value = null
viewModelScope.launch {
try {
// Listening before asking, so a sync that lands at once still counts.
@@ -54,7 +56,7 @@ class SyncViewModel @Inject constructor(
}
val outcome = repository.requestSync()
_result.value = outcome
- if (outcome == SyncRequestResult.Requested) settled.await() else settled.cancel()
+ if (outcome == SyncRequestResult.Requested || outcome == SyncRequestResult.PartlyFailed) settled.await() else settled.cancel()
} finally {
_inFlight.value = false
}
@@ -74,6 +76,7 @@ class SyncViewModel @Inject constructor(
@StringRes
fun SyncRequestResult.messageRes(): Int = when (this) {
SyncRequestResult.Requested -> R.string.sync_requested
+ SyncRequestResult.PartlyFailed -> R.string.sync_request_partly_failed
SyncRequestResult.NothingToSync -> R.string.sync_nothing_to_sync
SyncRequestResult.Failed -> R.string.sync_request_failed
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 20c67931..8d9d800b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -398,6 +398,7 @@
Sync now
Sync requested
Couldn\'t request a sync
+ Sync requested, but not for every account
No synced calendars to sync
diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/TestRepositories.kt b/app/src/test/java/de/jeanlucmakiola/calendula/TestRepositories.kt
index b3396f89..44eb1ae0 100644
--- a/app/src/test/java/de/jeanlucmakiola/calendula/TestRepositories.kt
+++ b/app/src/test/java/de/jeanlucmakiola/calendula/TestRepositories.kt
@@ -49,22 +49,24 @@ fun testRepository(
): CalendarRepositoryImpl = CalendarRepositoryImpl(source, prefs, settings, io, syncRequester)
/**
- * Records every sync request; [accepts] false models the system refusing one,
- * [adapterTypes] the installed calendar sync adapters (null: every type has one).
+ * Records every sync request; [accepts] false models the system refusing all,
+ * [refusedTypes] refusing those account types, [adapterTypes] the installed
+ * calendar sync adapters (null: a fixed set covering the test accounts).
*/
class RecordingSyncRequester(
var accepts: Boolean = true,
var adapterTypes: Set? = null,
+ var refusedTypes: Set = emptySet(),
) : SyncRequester {
data class Request(val account: SyncAccount, val userInitiated: Boolean)
val requests = mutableListOf()
- override fun hasAdapter(accountType: String): Boolean =
- adapterTypes?.contains(accountType) ?: true
+ override fun adapterAccountTypes(): Set =
+ adapterTypes ?: setOf("bitfire.at.davdroid", "com.google", "LOCAL")
override fun requestSync(account: SyncAccount, userInitiated: Boolean) {
- if (!accepts) throw SecurityException("refused")
+ if (!accepts || account.type in refusedTypes) throw SecurityException("refused")
requests += Request(account, userInitiated)
}
}
diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/SyncNudgeTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/SyncNudgeTest.kt
index 025609f5..8a347768 100644
--- a/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/SyncNudgeTest.kt
+++ b/app/src/test/java/de/jeanlucmakiola/calendula/data/calendar/SyncNudgeTest.kt
@@ -211,4 +211,13 @@ class SyncNudgeTest {
sync.adapterTypes = setOf(dav.type)
assertThat(repo.canRequestSync.first()).isTrue()
}
+
+ @Test
+ fun `manual sync refused for some accounts says so`(@TempDir dir: Path) = runTest {
+ val sync = RecordingSyncRequester(refusedTypes = setOf(google.type))
+ val repo = testRepository(fake(), dir, Dispatchers.Unconfined, syncRequester = sync)
+
+ assertThat(repo.requestSync()).isEqualTo(SyncRequestResult.PartlyFailed)
+ assertThat(sync.requests).containsExactly(Request(dav, true))
+ }
}
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 9a2d8327..426ca7da 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -14,8 +14,11 @@ the package list (recurring writes, save conflicts, reminder delivery).
expedited nudge for the account after each of its own writes to a synced
calendar (#303, once per write, so a multi-row save or an import asks once
per account, and never `MANUAL`, which would override master-sync-off), and
- a manual request from the drawer's "Sync now" (#240). Both go through
- `SyncRequester`; whether and when the adapter syncs stays its call.
+ a manual request from the drawer's "Sync now" (#240), which like the
+ system's own "Sync now" also runs for accounts whose auto-sync is off. Both
+ go through `SyncRequester` and only ask account types with a calendar sync
+ adapter (visible to the app via a `` entry); whether and when the
+ adapter syncs stays its call.
2. **Observer-driven UI.** A `ContentObserver` on the provider triggers
re-queries; every screen recomposes from fresh provider state. After a
write, nothing is patched by hand — the views refresh from the provider.