fix(#240): guard double picker launch, flag skipped accounts in the receipt, translatable grant summary
This commit is contained in:
1 parent
67052352ac
commit
e88ad7f533
6 files changed
+27
-23
No files matched your search
+1
-1
@@ -206,7 +206,7 @@ class CalendarRepositoryImpl @Inject constructor(
|
||||
val sent = targets.reachable.count { requestSync(it, userInitiated = true) }
|
||||
when {
|
||||
sent == 0 -> SyncRequestResult.Failed
|
||||
sent < targets.reachable.size -> SyncRequestResult.PartlyFailed
|
||||
sent < targets.reachable.size || targets.needsAccess.isNotEmpty() -> SyncRequestResult.PartlyFailed
|
||||
else -> SyncRequestResult.Requested
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,18 +461,21 @@ fun CalendarHost(
|
||||
val syncResult by sync.result.collectAsStateWithLifecycle()
|
||||
val selectionFailureMessage = eventActionFailureMessage(selectionFailure)
|
||||
val syncMessage = syncResult?.let { stringResource(it.messageRes()) }
|
||||
// The system account picker grants access to one account per pick; whatever
|
||||
// the outcome, access is re-read rather than trusted from the result.
|
||||
// Access can also be granted or revoked in system settings: re-read on every
|
||||
// resume, which covers the picker returning too.
|
||||
val accessPicker = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
|
||||
// Access is re-read on resume (covering the picker's return), never trusted from the result.
|
||||
var accessPickerOpen by remember { mutableStateOf(false) }
|
||||
val accessPicker = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
accessPickerOpen = false
|
||||
}
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { sync.refreshAccess() }
|
||||
val accessPickerDescription = stringResource(R.string.sync_access_picker_description)
|
||||
val launchAccessPicker: (Set<SyncAccount>) -> Unit = { accounts ->
|
||||
try {
|
||||
accessPicker.launch(accountAccessIntent(accounts, accessPickerDescription))
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.w("CalendarHost", "No account picker", e)
|
||||
if (!accessPickerOpen) {
|
||||
try {
|
||||
accessPicker.launch(accountAccessIntent(accounts, accessPickerDescription))
|
||||
accessPickerOpen = true
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.w("CalendarHost", "No account picker", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
val onEditEvent: (EventInstance) -> Unit = { event -> editKey = event.occurrenceKey() }
|
||||
@@ -572,6 +575,9 @@ fun CalendarHost(
|
||||
val stayingPut = remember { StayingPut() }
|
||||
val chromeHost = remember { ChromeHost() }
|
||||
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
||||
LaunchedEffect(drawerState.targetValue) {
|
||||
if (drawerState.targetValue == DrawerValue.Open) sync.refreshAccess()
|
||||
}
|
||||
val density = LocalDensity.current
|
||||
val topBarBottom = TopAppBarDefaults.windowInsets.getTop(density) +
|
||||
with(density) { TopAppBarDefaults.TopAppBarExpandedHeight.toPx() }
|
||||
@@ -622,17 +628,15 @@ fun CalendarHost(
|
||||
onOpenSettings()
|
||||
switchScope.launch { drawerState.close() }
|
||||
},
|
||||
sync = remember(syncTargets, syncInFlight) {
|
||||
sync = remember(syncTargets, syncInFlight, accessPickerDescription) {
|
||||
DrawerSync(
|
||||
canSync = syncTargets.reachable.isNotEmpty(),
|
||||
inFlight = syncInFlight,
|
||||
needsAccess = syncTargets.needsAccess.map { it.name }.distinct(),
|
||||
needsAccess = syncTargets.needsAccess.isNotEmpty(),
|
||||
onSync = {
|
||||
sync.requestSync()
|
||||
switchScope.launch { drawerState.close() }
|
||||
},
|
||||
// The drawer stays open: one pick grants one account,
|
||||
// and the row is right there for the next.
|
||||
onGrantAccess = { launchAccessPicker(syncTargets.needsAccess) },
|
||||
)
|
||||
},
|
||||
|
||||
@@ -150,27 +150,27 @@ fun CalendarDrawer(
|
||||
|
||||
/**
|
||||
* The drawer's sync rows: "Sync now" when [canSync] ([inFlight] shows progress
|
||||
* and ignores taps), and a grant row naming the [needsAccess] accounts.
|
||||
* and ignores taps), and a grant row while some account [needsAccess].
|
||||
*/
|
||||
data class DrawerSync(
|
||||
val canSync: Boolean,
|
||||
val inFlight: Boolean,
|
||||
val needsAccess: List<String>,
|
||||
val needsAccess: Boolean,
|
||||
val onSync: () -> Unit,
|
||||
val onGrantAccess: () -> Unit,
|
||||
) {
|
||||
val hasRows: Boolean get() = canSync || needsAccess.isNotEmpty()
|
||||
val hasRows: Boolean get() = canSync || needsAccess
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SyncRows(sync: DrawerSync) {
|
||||
if (sync.canSync) {
|
||||
SyncNowRow(sync, if (sync.needsAccess.isEmpty()) Position.Bottom else Position.Middle)
|
||||
SyncNowRow(sync, if (sync.needsAccess) Position.Middle else Position.Bottom)
|
||||
}
|
||||
if (sync.needsAccess.isNotEmpty()) {
|
||||
if (sync.needsAccess) {
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.drawer_sync_access),
|
||||
summary = stringResource(R.string.drawer_sync_access_summary, sync.needsAccess.joinToString()),
|
||||
summary = stringResource(R.string.drawer_sync_access_summary),
|
||||
position = Position.Bottom,
|
||||
minHeight = 56.dp,
|
||||
leading = { DrawerLeadingIcon(Icons.Filled.ManageAccounts) },
|
||||
|
||||
@@ -397,7 +397,7 @@
|
||||
<string name="drawer_jump_to_date">Jump to date</string>
|
||||
<string name="drawer_sync_now">Sync now</string>
|
||||
<string name="drawer_sync_access">Allow sync requests</string>
|
||||
<string name="drawer_sync_access_summary">Calendula can\'t ask %1$s to sync yet</string>
|
||||
<string name="drawer_sync_access_summary">Pick each account Calendula may ask to sync</string>
|
||||
<string name="sync_access_picker_description">Choose an account Calendula may ask to sync your calendars</string>
|
||||
<string name="sync_requested">Sync requested</string>
|
||||
<string name="sync_request_failed">Couldn\'t request a sync</string>
|
||||
|
||||
@@ -233,7 +233,7 @@ class SyncNudgeTest {
|
||||
assertThat(repo.syncTargets.first()).isEqualTo(SyncTargets(setOf(dav), setOf(google)))
|
||||
|
||||
sync.requests.clear()
|
||||
assertThat(repo.requestSync()).isEqualTo(SyncRequestResult.Requested)
|
||||
assertThat(repo.requestSync()).isEqualTo(SyncRequestResult.PartlyFailed)
|
||||
assertThat(sync.requests).containsExactly(Request(dav, true))
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ the package list (recurring writes, save conflicts, reminder delivery).
|
||||
drawer offers "Allow sync requests" instead, which opens the system account
|
||||
picker (`AccountManager.newChooseAccountIntent`) — the picked account
|
||||
becomes visible to the app. Access is re-read on every request and on
|
||||
every resume, so a revoke simply puts the account back behind the
|
||||
every resume and drawer open, so a revoke simply puts the account back behind the
|
||||
grant row. 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
|
||||
|
||||
Reference in new issue
Block a user