Compare commits
19 Commits
v2.16.0
...
113381a3e6
| Author | SHA1 | Date | |
|---|---|---|---|
| 113381a3e6 | |||
| d037492cf6 | |||
|
|
db7094c54e | ||
| c70412c782 | |||
| 8e2109d073 | |||
| 7c94425e41 | |||
| ac0c43f930 | |||
| 314236ac0c | |||
| c6e83fc071 | |||
| bf6415c023 | |||
| 7aef01d95e | |||
| ce4d6bc4d1 | |||
| 4ad805e747 | |||
| bb6e3ad336 | |||
| edbeadfa30 | |||
| ef48717e2c | |||
| 41593a0e9d | |||
| 4c1bfc052e | |||
| bba536394f |
@@ -72,9 +72,14 @@ jobs:
|
|||||||
distribution: 'zulu'
|
distribution: 'zulu'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
|
|
||||||
|
# Fully qualified on purpose. Codeberg resolves bare `uses:` refs against
|
||||||
|
# data.forgejo.org, Forgejo's own action mirror — actions/checkout,
|
||||||
|
# setup-java and cache all exist there, but android-actions/setup-android
|
||||||
|
# does not, and the job dies with "repository not found". Gitea's instance
|
||||||
|
# defaults to GitHub, which is why this never surfaced before the split.
|
||||||
- name: Setup Android SDK
|
- name: Setup Android SDK
|
||||||
if: steps.scope.outputs.code == 'true'
|
if: steps.scope.outputs.code == 'true'
|
||||||
uses: android-actions/setup-android@v3
|
uses: https://github.com/android-actions/setup-android@v3
|
||||||
with:
|
with:
|
||||||
# Default ("tools platform-tools") drags in the Android Emulator
|
# Default ("tools platform-tools") drags in the Android Emulator
|
||||||
# (~300 MB) which the build never uses.
|
# (~300 MB) which the build never uses.
|
||||||
@@ -27,6 +27,14 @@ jobs:
|
|||||||
# whether this push actually cuts a new release (no tag for it yet). Keeps the
|
# whether this push actually cuts a new release (no tag for it yet). Keeps the
|
||||||
# heavy job from running on every merge to main.
|
# heavy job from running on every merge to main.
|
||||||
detect:
|
detect:
|
||||||
|
# Gitea only. The workflow directory split already keeps this file invisible
|
||||||
|
# to Codeberg — Forgejo's lookup is first-match-wins, and .forgejo/workflows
|
||||||
|
# exists — but that only holds while .forgejo/ is non-empty. Move the last
|
||||||
|
# file out of it and Codeberg would fall back to .gitea/workflows and start
|
||||||
|
# running the release pipeline on the contributor-facing runner, with no
|
||||||
|
# secrets. repository_owner differs between the two forges regardless of
|
||||||
|
# URL, proxy or instance rename, so this closes it permanently.
|
||||||
|
if: github.repository_owner == 'makiolaj'
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
outputs:
|
outputs:
|
||||||
is_release: ${{ steps.v.outputs.is_release }}
|
is_release: ${{ steps.v.outputs.is_release }}
|
||||||
@@ -41,8 +49,16 @@ jobs:
|
|||||||
- name: Resolve version and whether it is a new release
|
- name: Resolve version and whether it is a new release
|
||||||
id: v
|
id: v
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
# Tags are read from Codeberg, which is canonical — deliberately NOT
|
||||||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
# from the Gitea API this workflow runs on. The Codeberg -> Gitea sync
|
||||||
|
# is a push mirror, i.e. `git push --mirror`, which deletes refs the
|
||||||
|
# source does not have. A tag minted here on Gitea is therefore wiped
|
||||||
|
# by the next sync (Codeberg does not have it yet) and only reappears
|
||||||
|
# once the tag push at the end of this workflow propagates back.
|
||||||
|
# Asking Gitea inside that window would report "no tag" for a release
|
||||||
|
# that already shipped, and cut it a second time.
|
||||||
|
# Public repo, so this read needs no token.
|
||||||
|
TAG_API: https://codeberg.org/api/v1/repos/jlmakiola/calendula
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
VERSION=$(grep -oP 'versionName\s*=\s*"\K[^"]+' app/build.gradle.kts)
|
VERSION=$(grep -oP 'versionName\s*=\s*"\K[^"]+' app/build.gradle.kts)
|
||||||
@@ -60,15 +76,28 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
# A tag for this version already existing means the release shipped on
|
# A tag for this version already existing means the release shipped on
|
||||||
# an earlier push; do nothing. Absent => this merge cuts the release.
|
# an earlier push; do nothing. Absent => this merge cuts the release.
|
||||||
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
|
#
|
||||||
-H "Authorization: token $TOKEN" "$API/git/refs/tags/v$VERSION")
|
# Anything other than a clean 200/404 is treated as fatal rather than
|
||||||
if [ "$STATUS" = "200" ]; then
|
# as "no tag". A Codeberg outage or a network blip would otherwise
|
||||||
echo "Tag v$VERSION already exists — nothing to release."
|
# read as absent and re-cut a release that has already shipped —
|
||||||
|
# republishing to F-Droid and Play. Failing here is recoverable; a
|
||||||
|
# duplicate release is not.
|
||||||
|
STATUS=$(curl -s -o /dev/null -w '%{http_code}' "$TAG_API/git/refs/tags/v$VERSION" || echo 000)
|
||||||
|
case "$STATUS" in
|
||||||
|
200)
|
||||||
|
echo "Tag v$VERSION already exists on Codeberg — nothing to release."
|
||||||
echo "is_release=false" >> "$GITHUB_OUTPUT"
|
echo "is_release=false" >> "$GITHUB_OUTPUT"
|
||||||
else
|
;;
|
||||||
echo "No tag for v$VERSION yet — cutting the release."
|
404)
|
||||||
|
echo "No tag for v$VERSION on Codeberg yet — cutting the release."
|
||||||
echo "is_release=true" >> "$GITHUB_OUTPUT"
|
echo "is_release=true" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
;;
|
||||||
|
*)
|
||||||
|
echo "Codeberg tag lookup for v$VERSION returned HTTP $STATUS." >&2
|
||||||
|
echo "Refusing to guess: treating this as 'no tag' could re-cut a shipped release." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Releases: build + sign + publish, then mint the tag and Gitea release.
|
# Releases: build + sign + publish, then mint the tag and Gitea release.
|
||||||
# Also runs on manual dispatch, where it skips the build and just re-signs and
|
# Also runs on manual dispatch, where it skips the build and just re-signs and
|
||||||
@@ -412,20 +441,31 @@ jobs:
|
|||||||
"prerelease": False,
|
"prerelease": False,
|
||||||
}))
|
}))
|
||||||
PY
|
PY
|
||||||
# Upsert (re-run safe). POST also creates the tag at target_commitish
|
# Create (or update) the release. Codeberg 500s on a POST/GET against a
|
||||||
# if the push mirror hasn't synced it yet.
|
# tag it has only just received — the release request outruns the
|
||||||
ID=$(curl -s -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG" | jq -r '.id // empty')
|
# indexing of the ref we pushed a moment ago — so a single attempt kept
|
||||||
if [ -n "$ID" ]; then
|
# failing and skipping the mirror even though the very same call
|
||||||
|
# succeeds seconds later. Retry with backoff, and PATCH in place if a
|
||||||
|
# release already exists (re-run safe). A 5xx body still exits curl 0,
|
||||||
|
# so the loop, not `set -e`, controls the flow.
|
||||||
|
ID=""
|
||||||
|
for attempt in 1 2 3 4 5 6; do
|
||||||
|
EXIST=$(curl -s -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG" | jq -r '.id // empty' 2>/dev/null || true)
|
||||||
|
if [ -n "$EXIST" ]; then
|
||||||
curl -s -o /dev/null -w "release PATCH HTTP %{http_code}\n" -X PATCH \
|
curl -s -o /dev/null -w "release PATCH HTTP %{http_code}\n" -X PATCH \
|
||||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||||
-d @cb-payload.json "$API/releases/$ID"
|
-d @cb-payload.json "$API/releases/$EXIST"
|
||||||
else
|
ID="$EXIST"; break
|
||||||
curl -s -o cb-response.json -w "release POST HTTP %{http_code}\n" -X POST \
|
|
||||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
|
||||||
-d @cb-payload.json "$API/releases"
|
|
||||||
ID=$(jq -r '.id // empty' cb-response.json 2>/dev/null || true)
|
|
||||||
fi
|
fi
|
||||||
if [ -z "$ID" ]; then echo "Could not resolve Codeberg release id." >&2; exit 1; fi
|
CODE=$(curl -s -o cb-response.json -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||||
|
-d @cb-payload.json "$API/releases")
|
||||||
|
echo "release POST attempt $attempt HTTP $CODE"
|
||||||
|
ID=$(jq -r '.id // empty' cb-response.json 2>/dev/null || true)
|
||||||
|
[ -n "$ID" ] && break
|
||||||
|
sleep $((attempt * 10))
|
||||||
|
done
|
||||||
|
if [ -z "$ID" ]; then echo "Could not resolve Codeberg release id after retries." >&2; exit 1; fi
|
||||||
|
|
||||||
# Attach APK + checksum, replacing any prior asset of the same name.
|
# Attach APK + checksum, replacing any prior asset of the same name.
|
||||||
for A in "$ASSET_APK" "$ASSET_SUM"; do
|
for A in "$ASSET_APK" "$ASSET_SUM"; do
|
||||||
|
|||||||
@@ -29,14 +29,30 @@ jobs:
|
|||||||
- name: Run Renovate
|
- name: Run Renovate
|
||||||
run: renovate
|
run: renovate
|
||||||
env:
|
env:
|
||||||
# Self-hosted Gitea, not github.com.
|
# Renovate targets Codeberg (canonical) while still RUNNING on the
|
||||||
RENOVATE_PLATFORM: gitea
|
# Gitea runner. Moving the job to Codeberg would put a repo-write
|
||||||
RENOVATE_ENDPOINT: https://gitea.jeanlucmakiola.de/api/v1
|
# token on the contributor-facing runner, which is exactly what the
|
||||||
# Bot-account token (Gitea secret). Needs repo read/write + PR scope.
|
# .forgejo/ vs .gitea/ split exists to prevent — so the token stays
|
||||||
|
# where the other secrets live and only the API calls cross over.
|
||||||
|
#
|
||||||
|
# Platform is `forgejo`, not `gitea`: Codeberg runs Forgejo, and the
|
||||||
|
# pinned image ships a distinct forgejo platform module.
|
||||||
|
RENOVATE_PLATFORM: forgejo
|
||||||
|
RENOVATE_ENDPOINT: https://codeberg.org/api/v1
|
||||||
|
# Codeberg bot-account token (Gitea secret). Needs repo read/write +
|
||||||
|
# PR scope on jlmakiola/calendula.
|
||||||
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||||
# Scope to this repo only — no org-wide autodiscovery.
|
# Scope to this repo only — no org-wide autodiscovery.
|
||||||
RENOVATE_AUTODISCOVER: 'false'
|
RENOVATE_AUTODISCOVER: 'false'
|
||||||
RENOVATE_REPOSITORIES: '["makiolaj/calendula"]'
|
RENOVATE_REPOSITORIES: '["jlmakiola/calendula"]'
|
||||||
# Commits/PRs authored as the bot, not a real maintainer.
|
# Commits/PRs authored as the bot, not a real maintainer. This address
|
||||||
|
# must be a verified email on the Codeberg bot account, otherwise the
|
||||||
|
# commits show up unattributed there.
|
||||||
RENOVATE_GIT_AUTHOR: 'Renovate Bot <renovate@jeanlucmakiola.de>'
|
RENOVATE_GIT_AUTHOR: 'Renovate Bot <renovate@jeanlucmakiola.de>'
|
||||||
|
# Read-only github.com PAT (no scopes needed). Unaffected by the forge
|
||||||
|
# move — nearly every dependency is *released* on GitHub, and without
|
||||||
|
# this,
|
||||||
|
# changelog/release-note lookups hit the 60/h anonymous rate limit
|
||||||
|
# and PRs arrive with an empty "Release Notes" section.
|
||||||
|
RENOVATE_GITHUB_COM_TOKEN: ${{ secrets.GITHUB_COM_TOKEN }}
|
||||||
LOG_LEVEL: info
|
LOG_LEVEL: info
|
||||||
|
|||||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "floret-kit"]
|
[submodule "floret-kit"]
|
||||||
path = floret-kit
|
path = floret-kit
|
||||||
url = https://gitea.jeanlucmakiola.de/makiolaj/floret-kit.git
|
url = https://codeberg.org/jlmakiola/floret-kit.git
|
||||||
|
|||||||
58
CHANGELOG.md
58
CHANGELOG.md
@@ -7,6 +7,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Settings → Calendars now says what is different about a calendar instead of
|
||||||
|
leaving you to guess. Ones you can only view — a subscribed calendar, a
|
||||||
|
calendar shared with you read-only — are marked **Read-only** ([#76]).
|
||||||
|
- Calendars your device isn't syncing are marked **Not synced**, moved to the
|
||||||
|
bottom of their account and left without a switch. None of their events are on
|
||||||
|
the device, so the switch they used to have could not have shown you anything
|
||||||
|
— the calendar simply looked broken. They are no longer offered when you pick
|
||||||
|
a calendar for a new or an imported event either: an event saved there would
|
||||||
|
never reach the account. Whether an account syncs a calendar stays that
|
||||||
|
account's own app's decision ([#78]).
|
||||||
|
- The birthday and anniversary calendars Calendula fills from your contacts are
|
||||||
|
marked **Filled from your contacts**, which is why they can't be picked for a
|
||||||
|
new event: anything you put there would be removed again on the next sync.
|
||||||
|
Deleting one is held back while special dates are switched on — Calendula
|
||||||
|
would simply create it again — and the calendar's editor says so; turn the
|
||||||
|
feature off under Settings → Special dates and the delete works as usual
|
||||||
|
([#76]).
|
||||||
|
- The calendar picker in the event form and in the .ics import screen now ends
|
||||||
|
with a **"Missing a calendar?"** row that opens Settings → Calendars, where
|
||||||
|
those marks then explain why a calendar isn't offered ([#76]).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Calendula's source code now lives on **Codeberg**, where its issues already
|
||||||
|
were. The **Source code** and **License** links in Settings → About point
|
||||||
|
there, so reporting a bug and reading the code no longer land on two different
|
||||||
|
sites. Nothing about the app itself changes, and the F-Droid repository is
|
||||||
|
unaffected.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Search results now show an all-day event's real date. West of UTC — anywhere in
|
||||||
|
the Americas, say — a search hit was dated one day early, disagreeing with the
|
||||||
|
day the month, week and agenda views file the same event under ([#82]).
|
||||||
|
- Reminders now arrive for every calendar you have switched on. A calendar that
|
||||||
|
was hidden at system level — switched off in another calendar app, or never
|
||||||
|
switched on after being added — still showed its events and listed their
|
||||||
|
reminders in Calendula, but never notified: Android only schedules reminder
|
||||||
|
alarms for calendars marked visible, and Calendula kept its own separate
|
||||||
|
on/off list that had no say in it. There is now one switch: **Settings →
|
||||||
|
Calendars** turns a calendar on or off for the whole device, so what you see
|
||||||
|
and what reminds you can no longer disagree ([#75]).
|
||||||
|
|
||||||
|
Calendars you had switched off in Calendula are switched off here too on first
|
||||||
|
launch. Calendars that were already off — hidden in another calendar app, or
|
||||||
|
never switched on after being added — stay off, and Calendula says so once
|
||||||
|
rather than quietly switching them on for every app on your device; you can
|
||||||
|
turn any of them back on in Settings → Calendars.
|
||||||
|
|
||||||
|
If you gave Calendula read-only access to your calendars, the switch still
|
||||||
|
works: your choice is kept in the app until it can be written.
|
||||||
|
|
||||||
|
The drawer's filter is unchanged and still app-only: hiding a calendar there
|
||||||
|
tidies your view without silencing its reminders.
|
||||||
|
|
||||||
## [2.16.0] — 2026-07-24
|
## [2.16.0] — 2026-07-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -1112,3 +1166,7 @@ automatically, with zero telemetry and no internet permission.
|
|||||||
[#42]: https://codeberg.org/jlmakiola/calendula/issues/42
|
[#42]: https://codeberg.org/jlmakiola/calendula/issues/42
|
||||||
[#44]: https://codeberg.org/jlmakiola/calendula/issues/44
|
[#44]: https://codeberg.org/jlmakiola/calendula/issues/44
|
||||||
[#70]: https://codeberg.org/jlmakiola/calendula/issues/70
|
[#70]: https://codeberg.org/jlmakiola/calendula/issues/70
|
||||||
|
[#75]: https://codeberg.org/jlmakiola/calendula/issues/75
|
||||||
|
[#76]: https://codeberg.org/jlmakiola/calendula/issues/76
|
||||||
|
[#78]: https://codeberg.org/jlmakiola/calendula/issues/78
|
||||||
|
[#82]: https://codeberg.org/jlmakiola/calendula/issues/82
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
Reads, writes, and reminds — on top of the system calendar, with zero network access.</p>
|
Reads, writes, and reminds — on top of the system calendar, with zero network access.</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a href="https://gitea.jeanlucmakiola.de/makiolaj/calendula/actions"><img src="https://gitea.jeanlucmakiola.de/makiolaj/calendula/actions/workflows/ci.yaml/badge.svg?branch=main" alt="CI"></a>
|
<a href="https://codeberg.org/jlmakiola/calendula/actions"><img src="https://codeberg.org/jlmakiola/calendula/actions/workflows/ci.yaml/badge.svg?branch=main" alt="CI"></a>
|
||||||
<img src="https://img.shields.io/badge/Android-10%2B-3DDC84?logo=android&logoColor=white" alt="Android 10+">
|
<img src="https://img.shields.io/badge/Android-10%2B-3DDC84?logo=android&logoColor=white" alt="Android 10+">
|
||||||
<img src="https://img.shields.io/badge/Kotlin-Compose-7F52FF?logo=kotlin&logoColor=white" alt="Kotlin + Compose">
|
<img src="https://img.shields.io/badge/Kotlin-Compose-7F52FF?logo=kotlin&logoColor=white" alt="Kotlin + Compose">
|
||||||
<img src="https://img.shields.io/badge/Material%203-Expressive-4285F4" alt="Material 3 Expressive">
|
<img src="https://img.shields.io/badge/Material%203-Expressive-4285F4" alt="Material 3 Expressive">
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.app.Application
|
|||||||
import dagger.hilt.android.EntryPointAccessors
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import de.jeanlucmakiola.calendula.data.backup.BackupScheduler
|
import de.jeanlucmakiola.calendula.data.backup.BackupScheduler
|
||||||
|
import de.jeanlucmakiola.calendula.data.calendar.CalendarVisibilityReconciler
|
||||||
import de.jeanlucmakiola.calendula.data.backup.BackupWorker
|
import de.jeanlucmakiola.calendula.data.backup.BackupWorker
|
||||||
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
|
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
|
||||||
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesSyncWorker
|
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesSyncWorker
|
||||||
@@ -39,6 +40,24 @@ class CalendulaApp : Application() {
|
|||||||
)
|
)
|
||||||
reconcileAutoBackup()
|
reconcileAutoBackup()
|
||||||
reconcileSpecialDates()
|
reconcileSpecialDates()
|
||||||
|
reconcileCalendarVisibility()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush any calendar switch-off the app hasn't been allowed to write into
|
||||||
|
* the system's `Calendars.VISIBLE` yet — including the retired app-local
|
||||||
|
* "disabled calendars" set the upgrade inherits (#75). A no-op on a fresh
|
||||||
|
* install and in the steady state; a launch without the calendar permission
|
||||||
|
* leaves the set pending, and `RootScreen` runs it again once the app comes
|
||||||
|
* up holding it — whichever way it was granted.
|
||||||
|
*/
|
||||||
|
private fun reconcileCalendarVisibility() {
|
||||||
|
val deps = EntryPointAccessors.fromApplication(
|
||||||
|
this, CalendarVisibilityReconciler.Deps::class.java,
|
||||||
|
)
|
||||||
|
CoroutineScope(SupervisorJob() + Dispatchers.Default).launch {
|
||||||
|
deps.calendarVisibilityReconciler().run()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -110,6 +110,32 @@ interface CalendarDataSource {
|
|||||||
/** Permanently delete a local calendar the app owns, with all its events. */
|
/** Permanently delete a local calendar the app owns, with all its events. */
|
||||||
fun deleteCalendar(id: Long)
|
fun deleteCalendar(id: Long)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show or hide the calendar device-wide by writing `Calendars.VISIBLE` — the
|
||||||
|
* app's one visibility model (#75). `VISIBLE` also gates the provider's own
|
||||||
|
* reminder scheduling, so switching a calendar off here is what actually
|
||||||
|
* stops its notifications; switching it on is what brings them back.
|
||||||
|
* Writable by a plain app (one of the three columns the platform documents
|
||||||
|
* as such) and device-local — no sync adapter pushes it anywhere.
|
||||||
|
*/
|
||||||
|
fun setCalendarVisible(id: Long, visible: Boolean)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether one calendar is currently switched on at system level, without
|
||||||
|
* reading every row — for the reminder gate, which sees a calendar id and
|
||||||
|
* nothing else. Null when the answer can't be had: no row (the calendar was
|
||||||
|
* deleted) or no read permission.
|
||||||
|
*/
|
||||||
|
fun isCalendarVisible(id: Long): Boolean?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the app holds `WRITE_CALENDAR`, i.e. may write
|
||||||
|
* [setCalendarVisible] at all. Read-only users (READ granted, WRITE denied)
|
||||||
|
* keep their calendar switches app-side instead — see
|
||||||
|
* [de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs.pendingDisabledCalendarIds].
|
||||||
|
*/
|
||||||
|
fun canWriteCalendars(): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a local calendar tagged as the special-dates mirror for [type]
|
* Create a local calendar tagged as the special-dates mirror for [type]
|
||||||
* (a marker in `CAL_SYNC2`); returns its `Calendars._ID`. Otherwise a normal
|
* (a marker in `CAL_SYNC2`); returns its `Calendars._ID`. Otherwise a normal
|
||||||
@@ -373,6 +399,40 @@ class AndroidCalendarDataSource @Inject constructor(
|
|||||||
if (deleted == 0) throw WriteFailedException("delete calendar id=$id")
|
if (deleted == 0) throw WriteFailedException("delete calendar id=$id")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Addressed by appended id on the plain (non-sync-adapter) Calendars URI,
|
||||||
|
* one calendar per call. Both parts are load-bearing:
|
||||||
|
* `CalendarProvider2.updateInTransaction` short-circuits to a raw database
|
||||||
|
* update unless the selection is `_id=…`, skipping the dirty marking *and*
|
||||||
|
* the `checkNextAlarm()` reschedule — i.e. an `_id IN (…)` batch would write
|
||||||
|
* the flag but never re-arm the reminder alarms this write exists to
|
||||||
|
* trigger. The sync-adapter URI is avoided so the write also applies to
|
||||||
|
* synced calendars, which is where the bug bites.
|
||||||
|
*/
|
||||||
|
override fun setCalendarVisible(id: Long, visible: Boolean) {
|
||||||
|
val values = ContentValues().apply {
|
||||||
|
put(CalendarContract.Calendars.VISIBLE, if (visible) 1 else 0)
|
||||||
|
}
|
||||||
|
val rows = resolver.update(
|
||||||
|
ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, id),
|
||||||
|
values, null, null,
|
||||||
|
)
|
||||||
|
if (rows == 0) throw WriteFailedException("set calendar visibility id=$id")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isCalendarVisible(id: Long): Boolean? {
|
||||||
|
if (!hasCalendarPermission()) return null
|
||||||
|
return resolver.query(
|
||||||
|
ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, id),
|
||||||
|
arrayOf(CalendarContract.Calendars.VISIBLE),
|
||||||
|
null, null, null,
|
||||||
|
)?.use { if (it.moveToFirst()) it.getInt(0) != 0 else null }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canWriteCalendars(): Boolean =
|
||||||
|
ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_CALENDAR) ==
|
||||||
|
PackageManager.PERMISSION_GRANTED
|
||||||
|
|
||||||
override fun createManagedCalendar(displayName: String, color: Int, type: SpecialDateType): Long {
|
override fun createManagedCalendar(displayName: String, color: Int, type: SpecialDateType): Long {
|
||||||
val name = displayName.trim().ifEmpty { Fallbacks.UNNAMED_CALENDAR }
|
val name = displayName.trim().ifEmpty { Fallbacks.UNNAMED_CALENDAR }
|
||||||
val values = ContentValues().apply {
|
val values = ContentValues().apply {
|
||||||
|
|||||||
@@ -31,5 +31,10 @@ internal fun ColumnReader.toCalendarSource(): CalendarSource {
|
|||||||
isManaged = isLocal &&
|
isManaged = isLocal &&
|
||||||
getString(CalendarProjection.IDX_MANAGED_MARKER)
|
getString(CalendarProjection.IDX_MANAGED_MARKER)
|
||||||
?.startsWith(CalendarProjection.MANAGED_MARKER_PREFIX) == true,
|
?.startsWith(CalendarProjection.MANAGED_MARKER_PREFIX) == true,
|
||||||
|
// A provider that leaves the column NULL is treated as syncing — the
|
||||||
|
// harmless default, since this flag only ever holds the one-shot
|
||||||
|
// visibility migration back from switching a calendar on.
|
||||||
|
syncsEvents = isNull(CalendarProjection.IDX_SYNC_EVENTS) ||
|
||||||
|
getInt(CalendarProjection.IDX_SYNC_EVENTS) != 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,20 @@ interface CalendarRepository {
|
|||||||
/** Permanently delete a local calendar the app owns, with all its events. */
|
/** Permanently delete a local calendar the app owns, with all its events. */
|
||||||
suspend fun deleteCalendar(id: Long)
|
suspend fun deleteCalendar(id: Long)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show or hide [ids] device-wide (`Calendars.VISIBLE`), which is also what
|
||||||
|
* turns the provider's reminder scheduling for them on or off — see
|
||||||
|
* [CalendarDataSource.setCalendarVisible]. Each calendar is written on its
|
||||||
|
* own, in order; a failure part-way leaves the earlier writes standing (the
|
||||||
|
* observer reports whatever actually landed).
|
||||||
|
*
|
||||||
|
* Without `WRITE_CALENDAR` the choice is kept app-side instead (see
|
||||||
|
* [de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs.pendingDisabledCalendarIds]),
|
||||||
|
* where it filters events and reminders just the same until it can be
|
||||||
|
* written.
|
||||||
|
*/
|
||||||
|
suspend fun setCalendarsVisible(ids: Collection<Long>, visible: Boolean)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every event of the writable local calendars, ready to serialise into a
|
* Every event of the writable local calendars, ready to serialise into a
|
||||||
* whole-calendar `.ics` backup (see [CalendarDataSource.exportableEvents]).
|
* whole-calendar `.ics` backup (see [CalendarDataSource.exportableEvents]).
|
||||||
|
|||||||
@@ -16,11 +16,17 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.drop
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.merge
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
import kotlin.time.Instant
|
import kotlin.time.Instant
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@@ -47,52 +53,140 @@ class CalendarRepositoryImpl @Inject constructor(
|
|||||||
extraBufferCapacity = 1,
|
extraBufferCapacity = 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bumped on every provider notification, so one tick's calendar read can be
|
||||||
|
* shared by everything that needs it (see [calendarsSnapshot]).
|
||||||
|
*/
|
||||||
|
private val generation = AtomicLong(0L)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
dataSource.registerChangeListener { ticks.tryEmit(Unit) }
|
dataSource.registerChangeListener {
|
||||||
|
generation.incrementAndGet()
|
||||||
|
ticks.tryEmit(Unit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-query signal for everything filtered by visibility: the provider's own
|
||||||
|
* notifications, plus every change to the pending switch-off set (an id
|
||||||
|
* leaves it as its `VISIBLE` write lands, which changes what is shown).
|
||||||
|
* [calendarsSnapshot] keeps the two in step.
|
||||||
|
*/
|
||||||
|
private fun visibilityTicks(): Flow<Unit> = merge(
|
||||||
|
ticks.onStart { emit(Unit) },
|
||||||
|
// The current value is already covered by the tick above; only later
|
||||||
|
// changes re-query (the set is deduped, so an unrelated DataStore write
|
||||||
|
// doesn't).
|
||||||
|
prefs.pendingDisabledCalendarIds.drop(1).map {},
|
||||||
|
)
|
||||||
|
|
||||||
|
// A switch-off the app hasn't been allowed to write yet is folded into the
|
||||||
|
// flag itself, so every consumer — the Settings switch, the filter sheet,
|
||||||
|
// the form and import pickers, the widgets — reads one visibility and can't
|
||||||
|
// disagree with what the user just tapped. The reconciler reads the data
|
||||||
|
// source directly, because it needs the provider's own answer.
|
||||||
override fun calendars(): Flow<List<CalendarSource>> =
|
override fun calendars(): Flow<List<CalendarSource>> =
|
||||||
ticks
|
visibilityTicks().reQuery {
|
||||||
.onStart { emit(Unit) }
|
val calendars = calendarsSnapshot()
|
||||||
.reQuery { dataSource.calendars() }
|
val pendingDisabled = prefs.pendingDisabledCalendarIds.first()
|
||||||
|
if (pendingDisabled.isEmpty()) calendars
|
||||||
|
else calendars.map {
|
||||||
|
if (it.id in pendingDisabled) it.copy(isVisibleInSystem = false) else it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Collapse re-emissions that carry an identical list (see
|
||||||
|
// [instances]).
|
||||||
|
.distinctUntilChanged()
|
||||||
.flowOn(io)
|
.flowOn(io)
|
||||||
|
|
||||||
// Instances are filtered by the app-side hidden ∪ disabled calendar sets
|
// Instances are filtered by the system's per-calendar VISIBLE flag ∪ the
|
||||||
// (M3): an event is dropped whenever the user has hidden *or* disabled its
|
// switch-offs still waiting to be written to it ∪ the app-side hidden set:
|
||||||
// calendar. Re-runs when the provider ticks *or* either set changes —
|
// an event is dropped when the user switched its calendar off in Settings →
|
||||||
// toggling a calendar in the filter sheet or the calendar manager updates
|
// Calendars (which also stops the provider scheduling its reminders) *or*
|
||||||
// every view immediately. [calendars] stays unfiltered so those screens can
|
// hid it in the filter sheet. Re-runs when the provider ticks — writing
|
||||||
// list and re-enable hidden/disabled calendars.
|
// VISIBLE notifies, so switching a calendar updates every view — or when
|
||||||
|
// either set changes. [calendars] stays unfiltered so those screens can list
|
||||||
|
// and re-enable invisible calendars.
|
||||||
override fun instances(range: ClosedRange<Instant>): Flow<List<EventInstance>> =
|
override fun instances(range: ClosedRange<Instant>): Flow<List<EventInstance>> =
|
||||||
combine(
|
combine(
|
||||||
ticks
|
visibilityTicks().reQuery {
|
||||||
.onStart { emit(Unit) }
|
// All three reads in one pass, so a list of instances is never
|
||||||
.reQuery {
|
// filtered against a visibility snapshot from another tick.
|
||||||
dataSource.instances(
|
QueriedInstances(
|
||||||
|
instances = dataSource.instances(
|
||||||
beginMillis = range.start.toEpochMillis(),
|
beginMillis = range.start.toEpochMillis(),
|
||||||
endMillis = range.endInclusive.toEpochMillis(),
|
endMillis = range.endInclusive.toEpochMillis(),
|
||||||
|
),
|
||||||
|
switchedOffCalendarIds = invisibleCalendarIds() +
|
||||||
|
prefs.pendingDisabledCalendarIds.first(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
prefs.hiddenCalendarIds,
|
prefs.hiddenCalendarIds,
|
||||||
prefs.disabledCalendarIds,
|
) { queried, hidden ->
|
||||||
) { instances, hidden, disabled ->
|
val excluded = hidden + queried.switchedOffCalendarIds
|
||||||
val excluded = hidden + disabled
|
if (excluded.isEmpty()) queried.instances
|
||||||
if (excluded.isEmpty()) instances
|
else queried.instances.filterNot { it.calendarId in excluded }
|
||||||
else instances.filterNot { it.calendarId in excluded }
|
|
||||||
}
|
}
|
||||||
// hidden and disabled both derive from one DataStore, so toggling
|
// Any DataStore edit re-emits the hidden set even when it is
|
||||||
// either makes both re-emit and combine briefly surfaces the same
|
// unchanged (e.g. writing the last-used calendar), which would
|
||||||
// list twice — collapse the duplicate so views don't re-render for it.
|
// re-surface an identical list — collapse those so views don't
|
||||||
|
// re-render for them.
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.flowOn(io)
|
.flowOn(io)
|
||||||
|
|
||||||
|
/** One instances query plus the visibility it must be filtered against. */
|
||||||
|
private data class QueriedInstances(
|
||||||
|
val instances: List<EventInstance>,
|
||||||
|
val switchedOffCalendarIds: Set<Long>,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Calendars switched off at system level — hidden, and never reminded about. */
|
||||||
|
private suspend fun invisibleCalendarIds(): Set<Long> = calendarsSnapshot()
|
||||||
|
.filterNot { it.isVisibleInSystem }
|
||||||
|
.mapTo(mutableSetOf()) { it.id }
|
||||||
|
|
||||||
|
private val calendarsLock = Mutex()
|
||||||
|
private var cachedGeneration = -1L
|
||||||
|
private var cachedPending: Set<Long>? = null
|
||||||
|
private var cachedCalendars: List<CalendarSource> = emptyList()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The calendar list for the current tick, queried once and shared. Every
|
||||||
|
* open view collects [calendars] *and* filters its instances by visibility,
|
||||||
|
* which used to cost one full `Calendars` query each per tick. Reusing a
|
||||||
|
* single read also keeps them consistent: within a tick, what a screen lists
|
||||||
|
* and what its events are filtered against can't come from two snapshots.
|
||||||
|
*
|
||||||
|
* An empty result is never cached — it is what a read without the calendar
|
||||||
|
* permission returns, and the grant itself doesn't notify the provider.
|
||||||
|
*
|
||||||
|
* The pending switch-off set keys the cache alongside the tick. An id leaves
|
||||||
|
* that set the moment its `VISIBLE` write lands, while the observer that
|
||||||
|
* would invalidate the snapshot is only dispatched through the main looper
|
||||||
|
* afterwards — so a snapshot taken while the id was still pending, read
|
||||||
|
* against the set that no longer holds it, would report the calendar as *on*
|
||||||
|
* again and re-admit exactly the events being hidden.
|
||||||
|
*/
|
||||||
|
private suspend fun calendarsSnapshot(): List<CalendarSource> = calendarsLock.withLock {
|
||||||
|
val current = generation.get()
|
||||||
|
val pending = prefs.pendingDisabledCalendarIds.first()
|
||||||
|
if (current != cachedGeneration || pending != cachedPending || cachedCalendars.isEmpty()) {
|
||||||
|
cachedCalendars = dataSource.calendars()
|
||||||
|
cachedGeneration = current
|
||||||
|
cachedPending = pending
|
||||||
|
}
|
||||||
|
cachedCalendars
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun eventDetail(eventId: Long): EventDetail = withContext(io) {
|
override suspend fun eventDetail(eventId: Long): EventDetail = withContext(io) {
|
||||||
dataSource.eventDetail(eventId) ?: throw NoSuchEventException(eventId)
|
dataSource.eventDetail(eventId) ?: throw NoSuchEventException(eventId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun searchEvents(query: String): List<EventInstance> = withContext(io) {
|
override suspend fun searchEvents(query: String): List<EventInstance> = withContext(io) {
|
||||||
if (query.isBlank()) return@withContext emptyList()
|
if (query.isBlank()) return@withContext emptyList()
|
||||||
val excluded = prefs.hiddenCalendarIds.first() + prefs.disabledCalendarIds.first()
|
val excluded = prefs.hiddenCalendarIds.first() +
|
||||||
|
prefs.pendingDisabledCalendarIds.first() +
|
||||||
|
invisibleCalendarIds()
|
||||||
dataSource.searchEvents(query)
|
dataSource.searchEvents(query)
|
||||||
.let { if (excluded.isEmpty()) it else it.filterNot { e -> e.calendarId in excluded } }
|
.let { if (excluded.isEmpty()) it else it.filterNot { e -> e.calendarId in excluded } }
|
||||||
}
|
}
|
||||||
@@ -118,6 +212,22 @@ class CalendarRepositoryImpl @Inject constructor(
|
|||||||
override suspend fun deleteCalendar(id: Long) =
|
override suspend fun deleteCalendar(id: Long) =
|
||||||
withContext(io) { dataSource.deleteCalendar(id) }
|
withContext(io) { dataSource.deleteCalendar(id) }
|
||||||
|
|
||||||
|
override suspend fun setCalendarsVisible(ids: Collection<Long>, visible: Boolean) =
|
||||||
|
withContext(io) {
|
||||||
|
if (dataSource.canWriteCalendars()) {
|
||||||
|
ids.forEach { dataSource.setCalendarVisible(it, visible) }
|
||||||
|
// Nothing of ours is left waiting for the provider once the
|
||||||
|
// write lands (and switching one back on retires its entry).
|
||||||
|
prefs.removePendingDisabledCalendarIds(ids)
|
||||||
|
} else if (visible) {
|
||||||
|
prefs.removePendingDisabledCalendarIds(ids)
|
||||||
|
} else {
|
||||||
|
// Read-only permission: the switch still works, app-side, and
|
||||||
|
// the reconciler flushes it if WRITE_CALENDAR ever arrives.
|
||||||
|
prefs.addPendingDisabledCalendarIds(ids)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun exportEvents(calendarIds: Set<Long>?) =
|
override suspend fun exportEvents(calendarIds: Set<Long>?) =
|
||||||
withContext(io) { dataSource.exportableEvents(calendarIds) }
|
withContext(io) { dataSource.exportableEvents(calendarIds) }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.data.calendar
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import dagger.hilt.EntryPoint
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import de.jeanlucmakiola.calendula.data.di.IoDispatcher
|
||||||
|
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
||||||
|
import de.jeanlucmakiola.calendula.domain.calendarVisibilityPlan
|
||||||
|
import de.jeanlucmakiola.calendula.domain.hasSystemHiddenCalendars
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps the app's pending "switched off" set (see
|
||||||
|
* [CalendarPrefs.pendingDisabledCalendarIds]) and the system's
|
||||||
|
* `Calendars.VISIBLE` in step — the fold-in of the retired app-local visibility
|
||||||
|
* model (#75), and the standing drain for switch-offs made without
|
||||||
|
* `WRITE_CALENDAR`.
|
||||||
|
*
|
||||||
|
* Runs on every launch, and again whenever the app comes up holding the calendar
|
||||||
|
* permission — a grant made on Android's own app-settings screen never reaches
|
||||||
|
* the permission screen's callback. It is a no-op whenever the pending set is
|
||||||
|
* empty and the notice has been settled, which
|
||||||
|
* is the steady state: each entry is written and dropped individually, so a run
|
||||||
|
* that dies part-way resumes exactly where it stopped and never re-applies a
|
||||||
|
* write the user has since undone by hand.
|
||||||
|
*
|
||||||
|
* The reconciliation only hides (see [calendarVisibilityPlan]). Calendars hidden
|
||||||
|
* at system level stay hidden, and on an *upgraded* install the first run that
|
||||||
|
* sees one arms the one-time notice explaining why Calendula no longer lists
|
||||||
|
* their events. A fresh install never had the old behaviour, so it retires that
|
||||||
|
* notice unshown — every other device ships with something hidden.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
class CalendarVisibilityReconciler @Inject constructor(
|
||||||
|
@ApplicationContext private val context: Context,
|
||||||
|
private val dataSource: CalendarDataSource,
|
||||||
|
private val prefs: CalendarPrefs,
|
||||||
|
@IoDispatcher private val io: CoroutineDispatcher,
|
||||||
|
) {
|
||||||
|
|
||||||
|
suspend fun run() = withContext(io) {
|
||||||
|
// Everything, the DataStore reads included, sits inside the guard: this
|
||||||
|
// runs in a bare application-scope coroutine with no exception handler,
|
||||||
|
// so an IOException from a damaged preferences file would otherwise take
|
||||||
|
// the process down on every launch.
|
||||||
|
try {
|
||||||
|
// A fresh install has no retired model behind it — nothing to
|
||||||
|
// migrate, and nothing to explain. Settled ahead of the permission
|
||||||
|
// gate so an update installed before the first grant can't make a
|
||||||
|
// first run look like an upgrade afterwards.
|
||||||
|
if (!isUpgradeInstall()) settleNoticeOnce(pending = false)
|
||||||
|
if (!hasPermission(Manifest.permission.READ_CALENDAR)) return@withContext
|
||||||
|
val pending = prefs.pendingDisabledCalendarIds.first()
|
||||||
|
val noticeSettled = prefs.visibilityNoticePending.first() != null
|
||||||
|
// The steady state, and every run after the first: nothing left to
|
||||||
|
// drain and nothing left to decide, so don't pay for the query.
|
||||||
|
if (pending.isEmpty() && noticeSettled) return@withContext
|
||||||
|
val calendars = dataSource.calendars()
|
||||||
|
// An empty read means "couldn't read", not "no calendars": the data
|
||||||
|
// source turns a null cursor — a provider momentarily unavailable —
|
||||||
|
// into an empty list. Both decisions below are one-way, so taking
|
||||||
|
// that reading as the truth would drop the whole pending set without
|
||||||
|
// ever writing VISIBLE = 0 (switching the user's calendars back on,
|
||||||
|
// events and reminders with them) and settle the notice as "nothing
|
||||||
|
// to explain". Leave both to the next run.
|
||||||
|
if (calendars.isEmpty()) return@withContext
|
||||||
|
settleNoticeOnce(hasSystemHiddenCalendars(calendars, pending))
|
||||||
|
if (pending.isEmpty() || !hasPermission(Manifest.permission.WRITE_CALENDAR)) {
|
||||||
|
return@withContext
|
||||||
|
}
|
||||||
|
val plan = calendarVisibilityPlan(calendars, pending)
|
||||||
|
// Already off, or gone from the device — nothing to write, so let
|
||||||
|
// those ids leave the pending set with the rest.
|
||||||
|
prefs.removePendingDisabledCalendarIds(plan.settled)
|
||||||
|
// One calendar per write: the provider skips its reminder-alarm
|
||||||
|
// reschedule for anything but a single-id update (see
|
||||||
|
// [CalendarDataSource.setCalendarVisible]). Dropping each id as it
|
||||||
|
// lands keeps a part-applied run resumable.
|
||||||
|
for (id in plan.hide) {
|
||||||
|
dataSource.setCalendarVisible(id, false)
|
||||||
|
prefs.removePendingDisabledCalendarIds(setOf(id))
|
||||||
|
}
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Calendar visibility reconcile failed; will retry", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settle the one-time notice: [pending] arms it, false retires it unshown.
|
||||||
|
* Answered once, by whichever run can answer it first; the answer is stored
|
||||||
|
* either way, so the notice can't resurface later, when the same state would
|
||||||
|
* no longer be news to the user.
|
||||||
|
*/
|
||||||
|
private suspend fun settleNoticeOnce(pending: Boolean) {
|
||||||
|
if (prefs.visibilityNoticePending.first() != null) return
|
||||||
|
prefs.setVisibilityNoticePending(pending)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this install has ever run an earlier version. The notice explains
|
||||||
|
* a change to behaviour the user has already seen, so a first install has
|
||||||
|
* nothing to announce — and hidden calendars are the *norm* on a fresh
|
||||||
|
* device (a second account's, "Holidays in …", a subscribed calendar), which
|
||||||
|
* would otherwise put a changelog dialog in front of a first-run user.
|
||||||
|
*/
|
||||||
|
private fun isUpgradeInstall(): Boolean = try {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val info = context.packageManager.getPackageInfo(context.packageName, 0)
|
||||||
|
info.lastUpdateTime > info.firstInstallTime
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
Log.w(TAG, "Own package info unavailable; treating as a fresh install", e)
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hasPermission(permission: String): Boolean =
|
||||||
|
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
|
||||||
|
|
||||||
|
/** Lets non-injectable entry points (the Application) reach the reconciler. */
|
||||||
|
@EntryPoint
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface Deps {
|
||||||
|
fun calendarVisibilityReconciler(): CalendarVisibilityReconciler
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val TAG = "CalendarVisibility"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ internal object CalendarProjection {
|
|||||||
// uses to recognise its own managed calendars, independent of any
|
// uses to recognise its own managed calendars, independent of any
|
||||||
// stored preference id (which a backup restore / data wipe can lose).
|
// stored preference id (which a backup restore / data wipe can lose).
|
||||||
MANAGED_MARKER_COLUMN,
|
MANAGED_MARKER_COLUMN,
|
||||||
|
CalendarContract.Calendars.SYNC_EVENTS,
|
||||||
)
|
)
|
||||||
|
|
||||||
const val DESCRIPTION_COLUMN: String = CalendarContract.Calendars.CAL_SYNC1
|
const val DESCRIPTION_COLUMN: String = CalendarContract.Calendars.CAL_SYNC1
|
||||||
@@ -36,6 +37,7 @@ internal object CalendarProjection {
|
|||||||
const val IDX_ACCESS_LEVEL = 6
|
const val IDX_ACCESS_LEVEL = 6
|
||||||
const val IDX_DESCRIPTION = 7
|
const val IDX_DESCRIPTION = 7
|
||||||
const val IDX_MANAGED_MARKER = 8
|
const val IDX_MANAGED_MARKER = 8
|
||||||
|
const val IDX_SYNC_EVENTS = 9
|
||||||
}
|
}
|
||||||
|
|
||||||
internal object InstanceProjection {
|
internal object InstanceProjection {
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
package de.jeanlucmakiola.calendula.data.prefs
|
package de.jeanlucmakiola.calendula.data.prefs
|
||||||
|
|
||||||
import androidx.datastore.core.DataStore
|
import androidx.datastore.core.DataStore
|
||||||
|
import androidx.datastore.preferences.core.MutablePreferences
|
||||||
import androidx.datastore.preferences.core.Preferences
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||||
import androidx.datastore.preferences.core.edit
|
import androidx.datastore.preferences.core.edit
|
||||||
import androidx.datastore.preferences.core.longPreferencesKey
|
import androidx.datastore.preferences.core.longPreferencesKey
|
||||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* App-side preference for "calendars the user has hidden in this app",
|
* App-side calendar preferences. [hiddenCalendarIds] is the drawer's filter
|
||||||
* separate from the system's per-calendar VISIBLE flag.
|
* sheet — a purely in-app declutter that deliberately does *not* suppress
|
||||||
|
* reminders. Switching a calendar off entirely is the system's
|
||||||
|
* `Calendars.VISIBLE` flag, written straight to the provider (#75);
|
||||||
|
* [pendingDisabledCalendarIds] only holds those switch-offs the app has not been
|
||||||
|
* allowed to write yet.
|
||||||
*
|
*
|
||||||
* Persisted as a comma-separated string of Long ids; non-numeric tokens are
|
* Persisted as a comma-separated string of Long ids; non-numeric tokens are
|
||||||
* silently dropped (defensive — see CalendarPrefsTest).
|
* silently dropped (defensive — see CalendarPrefsTest).
|
||||||
@@ -22,46 +29,63 @@ class CalendarPrefs @Inject constructor(
|
|||||||
private val store: DataStore<Preferences>,
|
private val store: DataStore<Preferences>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val hiddenCalendarIds: Flow<Set<Long>> = store.data.map { prefs ->
|
// Both id sets are deduped: the store is shared with SettingsPrefs, so every
|
||||||
prefs[HIDDEN_IDS_KEY].orEmpty()
|
// unrelated write (a settings toggle, the last-used calendar) re-emits an
|
||||||
.split(',')
|
// identical set otherwise — and a change to the pending set now costs a
|
||||||
.mapNotNull { it.trim().toLongOrNull() }
|
// fresh provider read in CalendarRepositoryImpl.
|
||||||
.toSet()
|
val hiddenCalendarIds: Flow<Set<Long>> = store.data
|
||||||
}
|
.map { prefs -> prefs[HIDDEN_IDS_KEY].parseIds() }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
suspend fun setHiddenCalendarIds(ids: Set<Long>) {
|
suspend fun setHiddenCalendarIds(ids: Set<Long>) {
|
||||||
store.edit { prefs ->
|
store.edit { prefs -> prefs.writeIds(HIDDEN_IDS_KEY, ids) }
|
||||||
if (ids.isEmpty()) {
|
|
||||||
prefs.remove(HIDDEN_IDS_KEY)
|
|
||||||
} else {
|
|
||||||
prefs[HIDDEN_IDS_KEY] = ids.sorted().joinToString(",")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendars switched off in Settings → Calendars that the provider does not
|
||||||
|
* know about yet. That switch writes the system's `Calendars.VISIBLE` (#75),
|
||||||
|
* which needs `WRITE_CALENDAR` — a user who granted read-only keeps their
|
||||||
|
* choice here instead, and so does everyone upgrading from the retired
|
||||||
|
* app-local model, whose set is read straight back out of the same key.
|
||||||
|
*
|
||||||
|
* Honoured as a display and reminder filter for as long as it is non-empty,
|
||||||
|
* so an un-flushable switch still does what the user asked. Not a second
|
||||||
|
* visibility model: `CalendarVisibilityReconciler` drains it into the
|
||||||
|
* provider entry by entry the moment the app may write, and nothing ever
|
||||||
|
* adds to it while it may.
|
||||||
|
*/
|
||||||
|
val pendingDisabledCalendarIds: Flow<Set<Long>> = store.data
|
||||||
|
.map { prefs -> prefs[DISABLED_IDS_KEY].parseIds() }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
suspend fun addPendingDisabledCalendarIds(ids: Collection<Long>) =
|
||||||
|
editPendingDisabled { it + ids }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop [ids] from the pending set — one id at a time as the reconciler
|
||||||
|
* flushes it, so a run that fails part-way never re-applies what already
|
||||||
|
* landed (and can't undo a switch the user has since flipped by hand).
|
||||||
|
*/
|
||||||
|
suspend fun removePendingDisabledCalendarIds(ids: Collection<Long>) =
|
||||||
|
editPendingDisabled { it - ids.toSet() }
|
||||||
|
|
||||||
|
private suspend fun editPendingDisabled(transform: (Set<Long>) -> Set<Long>) {
|
||||||
|
store.edit { prefs ->
|
||||||
|
prefs.writeIds(DISABLED_IDS_KEY, transform(prefs[DISABLED_IDS_KEY].parseIds()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* App-side preference for "calendars the user has disabled in this app" — a
|
* Whether the one-time "visibility follows this device" notice is still
|
||||||
* heavier level than [hiddenCalendarIds]. A disabled calendar is removed from
|
* owed. Null until the reconciler has evaluated it (which needs the calendar
|
||||||
* every surface (drawer filter, event-form picker, import picker) and its
|
* permission), false once it has been shown or was never needed.
|
||||||
* events never appear; it stays listed only in Settings → Calendars so it can
|
|
||||||
* be re-enabled. Stored exactly like the hidden set; never touches the
|
|
||||||
* system's VISIBLE/SYNC_EVENTS flags, so other calendar apps are unaffected.
|
|
||||||
*/
|
*/
|
||||||
val disabledCalendarIds: Flow<Set<Long>> = store.data.map { prefs ->
|
val visibilityNoticePending: Flow<Boolean?> = store.data.map { prefs ->
|
||||||
prefs[DISABLED_IDS_KEY].orEmpty()
|
prefs[VISIBILITY_NOTICE_KEY]
|
||||||
.split(',')
|
|
||||||
.mapNotNull { it.trim().toLongOrNull() }
|
|
||||||
.toSet()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun setDisabledCalendarIds(ids: Set<Long>) {
|
suspend fun setVisibilityNoticePending(pending: Boolean) {
|
||||||
store.edit { prefs ->
|
store.edit { prefs -> prefs[VISIBILITY_NOTICE_KEY] = pending }
|
||||||
if (ids.isEmpty()) {
|
|
||||||
prefs.remove(DISABLED_IDS_KEY)
|
|
||||||
} else {
|
|
||||||
prefs[DISABLED_IDS_KEY] = ids.sorted().joinToString(",")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,6 +103,16 @@ class CalendarPrefs @Inject constructor(
|
|||||||
companion object {
|
companion object {
|
||||||
internal val HIDDEN_IDS_KEY = stringPreferencesKey("hidden_calendar_ids")
|
internal val HIDDEN_IDS_KEY = stringPreferencesKey("hidden_calendar_ids")
|
||||||
internal val DISABLED_IDS_KEY = stringPreferencesKey("disabled_calendar_ids")
|
internal val DISABLED_IDS_KEY = stringPreferencesKey("disabled_calendar_ids")
|
||||||
|
internal val VISIBILITY_NOTICE_KEY = booleanPreferencesKey("visibility_notice_pending")
|
||||||
internal val LAST_USED_CALENDAR_KEY = longPreferencesKey("last_used_calendar_id")
|
internal val LAST_USED_CALENDAR_KEY = longPreferencesKey("last_used_calendar_id")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String?.parseIds(): Set<Long> = orEmpty()
|
||||||
|
.split(',')
|
||||||
|
.mapNotNull { it.trim().toLongOrNull() }
|
||||||
|
.toSet()
|
||||||
|
|
||||||
|
private fun MutablePreferences.writeIds(key: Preferences.Key<String>, ids: Set<Long>) {
|
||||||
|
if (ids.isEmpty()) remove(key) else set(key, ids.sorted().joinToString(","))
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.data.reminders
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Still relevant while the event has not ended: a reminder for an event that is
|
||||||
|
* already over is pointless to re-surface. Falls back to the begin time when the
|
||||||
|
* end is unknown (0L).
|
||||||
|
*/
|
||||||
|
internal fun ReminderAlert.isRelevantAt(nowMillis: Long): Boolean =
|
||||||
|
(endMillis.takeIf { it > 0L } ?: beginMillis) >= nowMillis
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The alerts [EventReminderReceiver] may mark handled (`STATE_FIRED`): the ones
|
||||||
|
* it posted, plus the ones it silenced whose event is already over.
|
||||||
|
*
|
||||||
|
* A silenced alert for an event still ahead is deliberately left
|
||||||
|
* `STATE_SCHEDULED`. Silencing is not handling — the calendar is switched off in
|
||||||
|
* Calendula while the provider still holds `VISIBLE = 1` (a read-only install,
|
||||||
|
* or an upgrade whose flush hasn't landed), so switching it back on before the
|
||||||
|
* event must still be able to surface the reminder. [ReminderAlertStore.dueAlerts]
|
||||||
|
* only ever returns scheduled rows, so marking them here would lose them for
|
||||||
|
* good; leaving them makes the provider's own table the stash
|
||||||
|
* ([ReminderRecovery]).
|
||||||
|
*/
|
||||||
|
internal fun handledAlertIds(
|
||||||
|
due: List<ReminderAlert>,
|
||||||
|
postedIds: Set<Long>,
|
||||||
|
nowMillis: Long,
|
||||||
|
): List<Long> = due
|
||||||
|
.filter { it.alertId in postedIds || !it.isRelevantAt(nowMillis) }
|
||||||
|
.map { it.alertId }
|
||||||
@@ -8,7 +8,6 @@ import android.content.pm.PackageManager
|
|||||||
import android.provider.CalendarContract
|
import android.provider.CalendarContract
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -17,29 +16,6 @@ import kotlinx.coroutines.flow.first
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
|
||||||
* True when [this] alert belongs to a calendar the user disabled in-app, so its
|
|
||||||
* reminder must be suppressed (mirroring the event filtering in
|
|
||||||
* CalendarRepositoryImpl). Alerts whose calendar is unknown (id 0L — e.g. a
|
|
||||||
* pre-upgrade snooze PendingIntent minted before EXTRA_CALENDAR_ID existed) are
|
|
||||||
* never treated as disabled. This is the one predicate the disabled-calendar
|
|
||||||
* gate is built from: [postableAlerts] here and the choke point in
|
|
||||||
* [ReminderNotifier.post] both use it.
|
|
||||||
*/
|
|
||||||
internal fun ReminderAlert.isForDisabledCalendar(disabledCalendarIds: Set<Long>): Boolean =
|
|
||||||
calendarId != 0L && calendarId in disabledCalendarIds
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The due alerts that should actually surface as notifications: everything
|
|
||||||
* except alerts whose calendar the user has disabled in-app. The caller still
|
|
||||||
* marks the full due set fired, so suppressed alerts are not re-broadcast by the
|
|
||||||
* provider.
|
|
||||||
*/
|
|
||||||
internal fun postableAlerts(
|
|
||||||
due: List<ReminderAlert>,
|
|
||||||
disabledCalendarIds: Set<Long>,
|
|
||||||
): List<ReminderAlert> = due.filterNot { it.isForDisabledCalendar(disabledCalendarIds) }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Becomes the app that turns the calendar provider's reminder alarms into
|
* Becomes the app that turns the calendar provider's reminder alarms into
|
||||||
* visible notifications (the Etar model — the provider broadcasts
|
* visible notifications (the Etar model — the provider broadcasts
|
||||||
@@ -49,6 +25,14 @@ internal fun postableAlerts(
|
|||||||
* we query every still-scheduled, due `CalendarAlerts` row ourselves, post
|
* we query every still-scheduled, due `CalendarAlerts` row ourselves, post
|
||||||
* them, and mark them fired. Posting happens before marking — a crash in
|
* them, and mark them fired. Posting happens before marking — a crash in
|
||||||
* between re-posts silently (same tag) rather than losing the reminder.
|
* between re-posts silently (same tag) rather than losing the reminder.
|
||||||
|
*
|
||||||
|
* There is no per-calendar filtering here: a calendar switched off in
|
||||||
|
* Settings → Calendars has `Calendars.VISIBLE = 0`, and the provider creates no
|
||||||
|
* alert rows for it in the first place (#75). The one case that flag can't
|
||||||
|
* cover — a read-only install, which keeps its switches app-side — is gated in
|
||||||
|
* [ReminderNotifier.post], where the snoozed re-show passes too. What that gate
|
||||||
|
* silences is *not* marked fired while the event is still ahead, so switching
|
||||||
|
* the calendar back on can still surface it (see [handledAlertIds]).
|
||||||
*/
|
*/
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class EventReminderReceiver : BroadcastReceiver() {
|
class EventReminderReceiver : BroadcastReceiver() {
|
||||||
@@ -56,8 +40,6 @@ class EventReminderReceiver : BroadcastReceiver() {
|
|||||||
@Inject lateinit var alertStore: ReminderAlertStore
|
@Inject lateinit var alertStore: ReminderAlertStore
|
||||||
@Inject lateinit var notifier: ReminderNotifier
|
@Inject lateinit var notifier: ReminderNotifier
|
||||||
@Inject lateinit var settingsPrefs: SettingsPrefs
|
@Inject lateinit var settingsPrefs: SettingsPrefs
|
||||||
@Inject lateinit var calendarPrefs: CalendarPrefs
|
|
||||||
@Inject lateinit var suppressedStore: SuppressedReminderStore
|
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
if (intent.action != CalendarContract.ACTION_EVENT_REMINDER) return
|
if (intent.action != CalendarContract.ACTION_EVENT_REMINDER) return
|
||||||
@@ -72,17 +54,10 @@ class EventReminderReceiver : BroadcastReceiver() {
|
|||||||
if (settingsPrefs.remindersEnabled.first()) {
|
if (settingsPrefs.remindersEnabled.first()) {
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
val due = alertStore.dueAlerts(now)
|
val due = alertStore.dueAlerts(now)
|
||||||
val disabled = calendarPrefs.disabledCalendarIds.first()
|
val postedIds = due
|
||||||
val postable = postableAlerts(due, disabled)
|
.filter { notifier.post(it) }
|
||||||
// Suppress reminders for disabled calendars, but still mark
|
.mapTo(mutableSetOf()) { it.alertId }
|
||||||
// every due alert fired so the provider stops re-broadcasting
|
alertStore.markFired(handledAlertIds(due, postedIds, now), now)
|
||||||
// the suppressed ones. Stash those suppressed alerts so
|
|
||||||
// re-enabling their calendar can recover them (they would
|
|
||||||
// otherwise stay STATE_FIRED forever with no re-scan).
|
|
||||||
postable.forEach { notifier.post(it) }
|
|
||||||
alertStore.markFired(due.map { it.alertId }, now)
|
|
||||||
suppressedStore.stash(due - postable.toSet(), now)
|
|
||||||
suppressedStore.purgeExpired(now)
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
pendingResult.finish()
|
pendingResult.finish()
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import javax.inject.Inject
|
|||||||
* - **Snooze** cancels the notification and schedules an exact alarm to re-show
|
* - **Snooze** cancels the notification and schedules an exact alarm to re-show
|
||||||
* it after the user's snooze delay.
|
* it after the user's snooze delay.
|
||||||
* - **Show** (the alarm) re-posts the same notification, so the user can snooze
|
* - **Show** (the alarm) re-posts the same notification, so the user can snooze
|
||||||
* or dismiss it again.
|
* or dismiss it again — unless the calendar was switched off during the
|
||||||
|
* snooze, which [ReminderNotifier.post] catches (this alarm is ours, so no
|
||||||
|
* provider alert row stands between it and the notification).
|
||||||
*/
|
*/
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ReminderActionReceiver : BroadcastReceiver() {
|
class ReminderActionReceiver : BroadcastReceiver() {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import androidx.core.content.ContextCompat
|
|||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import de.jeanlucmakiola.calendula.MainActivity
|
import de.jeanlucmakiola.calendula.MainActivity
|
||||||
import de.jeanlucmakiola.calendula.R
|
import de.jeanlucmakiola.calendula.R
|
||||||
|
import de.jeanlucmakiola.calendula.data.calendar.CalendarDataSource
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.is24Hour
|
import de.jeanlucmakiola.calendula.data.prefs.is24Hour
|
||||||
@@ -39,6 +40,7 @@ class ReminderNotifier @Inject constructor(
|
|||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val settingsPrefs: SettingsPrefs,
|
private val settingsPrefs: SettingsPrefs,
|
||||||
private val calendarPrefs: CalendarPrefs,
|
private val calendarPrefs: CalendarPrefs,
|
||||||
|
private val calendarDataSource: CalendarDataSource,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/** False when the user declined `POST_NOTIFICATIONS` or muted the app. */
|
/** False when the user declined `POST_NOTIFICATIONS` or muted the app. */
|
||||||
@@ -49,12 +51,26 @@ class ReminderNotifier @Inject constructor(
|
|||||||
return granted && NotificationManagerCompat.from(context).areNotificationsEnabled()
|
return granted && NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun post(alert: ReminderAlert) {
|
/**
|
||||||
// The single choke point for the disabled-calendar gate: it covers both
|
* The single choke point for "this calendar is switched off". The provider
|
||||||
// the provider broadcast (EventReminderReceiver) and a snoozed re-show
|
* side needs no help — with `VISIBLE = 0` it creates no alert rows at all —
|
||||||
// (ReminderActionReceiver), so a calendar disabled after a snooze no
|
* but two paths reach [post] without one: a snooze we re-show from our own
|
||||||
// longer notifies — without either receiver duplicating the check.
|
* exact alarm, scheduled before the calendar was switched off, and a
|
||||||
if (alert.isForDisabledCalendar(calendarPrefs.disabledCalendarIds.first())) return
|
* read-only install whose switch lives app-side ([CalendarPrefs]) because it
|
||||||
|
* may not write the flag. Both are covered here rather than in either
|
||||||
|
* receiver.
|
||||||
|
*/
|
||||||
|
private suspend fun isSilenced(calendarId: Long): Boolean =
|
||||||
|
calendarId in calendarPrefs.pendingDisabledCalendarIds.first() ||
|
||||||
|
calendarDataSource.isCalendarVisible(calendarId) == false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post [alert], unless its calendar is switched off. Returns whether the
|
||||||
|
* notification was put up: a silenced alert must stay unhandled so that
|
||||||
|
* switching the calendar back on can still surface it (see [handledAlertIds]).
|
||||||
|
*/
|
||||||
|
suspend fun post(alert: ReminderAlert): Boolean {
|
||||||
|
if (isSilenced(alert.calendarId)) return false
|
||||||
ensureChannel()
|
ensureChannel()
|
||||||
val title = alert.title.ifBlank { context.getString(R.string.event_untitled) }
|
val title = alert.title.ifBlank { context.getString(R.string.event_untitled) }
|
||||||
val is24Hour = settingsPrefs.timeFormat.first()
|
val is24Hour = settingsPrefs.timeFormat.first()
|
||||||
@@ -106,6 +122,8 @@ class ReminderNotifier @Inject constructor(
|
|||||||
// POST_NOTIFICATIONS was revoked between canPost() and here.
|
// POST_NOTIFICATIONS was revoked between canPost() and here.
|
||||||
Log.w(TAG, "Could not post reminder for event ${alert.eventId}", e)
|
Log.w(TAG, "Could not post reminder for event ${alert.eventId}", e)
|
||||||
}
|
}
|
||||||
|
// Handled either way: re-running it would hit the same revoked permission.
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove a posted reminder (snooze re-shows it later; dismiss is final). */
|
/** Remove a posted reminder (snooze re-shows it later; dismiss is final). */
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.data.reminders
|
||||||
|
|
||||||
|
import de.jeanlucmakiola.calendula.data.di.IoDispatcher
|
||||||
|
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-posts the reminders a switched-off calendar silenced, when it is switched
|
||||||
|
* back on while they still matter.
|
||||||
|
*
|
||||||
|
* Only the app-side switch needs this — a read-only install, or an upgrade the
|
||||||
|
* reconciler hasn't flushed yet. With `Calendars.VISIBLE = 0` the provider
|
||||||
|
* deletes the calendar's alert rows itself and re-creates them on the way back;
|
||||||
|
* app-side the rows stay, still `STATE_SCHEDULED`, because
|
||||||
|
* [EventReminderReceiver] deliberately leaves the ones it silenced unhandled
|
||||||
|
* (see [handledAlertIds]). So the provider's own table is the stash, and nothing
|
||||||
|
* is mirrored locally.
|
||||||
|
*
|
||||||
|
* Best effort at switch-on time: it mirrors the receiver's gates (reminders on,
|
||||||
|
* notifications postable) and there is no later re-scan, so an alert left
|
||||||
|
* unposted because those are closed is simply released.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
class ReminderRecovery @Inject constructor(
|
||||||
|
private val alertStore: ReminderAlertStore,
|
||||||
|
private val notifier: ReminderNotifier,
|
||||||
|
private val settingsPrefs: SettingsPrefs,
|
||||||
|
@IoDispatcher private val io: CoroutineDispatcher,
|
||||||
|
) {
|
||||||
|
|
||||||
|
suspend fun rePostFor(calendarIds: Collection<Long>) = withContext(io) {
|
||||||
|
if (calendarIds.isEmpty()) return@withContext
|
||||||
|
if (!settingsPrefs.remindersEnabled.first() || !notifier.canPost()) return@withContext
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
val ids = calendarIds.toSet()
|
||||||
|
val recovered = alertStore.dueAlerts(now)
|
||||||
|
.filter { it.calendarId in ids && it.isRelevantAt(now) }
|
||||||
|
if (recovered.isEmpty()) return@withContext
|
||||||
|
val postedIds = recovered.filter { notifier.post(it) }.map { it.alertId }
|
||||||
|
alertStore.markFired(postedIds, now)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
package de.jeanlucmakiola.calendula.data.reminders
|
|
||||||
|
|
||||||
import androidx.datastore.core.DataStore
|
|
||||||
import androidx.datastore.preferences.core.MutablePreferences
|
|
||||||
import androidx.datastore.preferences.core.Preferences
|
|
||||||
import androidx.datastore.preferences.core.edit
|
|
||||||
import androidx.datastore.preferences.core.stringSetPreferencesKey
|
|
||||||
import java.util.Base64
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Still relevant while the event has not ended: a reminder for an event that is
|
|
||||||
* already over is pointless to re-surface. Falls back to the begin time when the
|
|
||||||
* end is unknown (0L). Used both to decide what to re-post and to purge the stash.
|
|
||||||
*/
|
|
||||||
internal fun ReminderAlert.isRelevantAt(nowMillis: Long): Boolean =
|
|
||||||
(endMillis.takeIf { it > 0L } ?: beginMillis) >= nowMillis
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local stash of reminder alerts that fired while their calendar was disabled
|
|
||||||
* in-app. [EventReminderReceiver] marks every due alert `STATE_FIRED` regardless
|
|
||||||
* (so the provider stops re-broadcasting the suppressed ones), which would
|
|
||||||
* otherwise lose those reminders forever — there is no re-scan. Stashing lets
|
|
||||||
* [de.jeanlucmakiola.calendula.ui.calendars.CalendarsViewModel] re-post them if
|
|
||||||
* the user re-enables the calendar before the event is over.
|
|
||||||
*
|
|
||||||
* Persisted in the shared preferences DataStore as a set of self-describing
|
|
||||||
* strings (one per alert); the stash never reaches a screen, so there is no
|
|
||||||
* domain model. Entries whose event has already ended are dropped on the next
|
|
||||||
* stash/recover/purge, so the stash only ever holds a handful of pending alerts.
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
class SuppressedReminderStore @Inject constructor(
|
|
||||||
private val store: DataStore<Preferences>,
|
|
||||||
) {
|
|
||||||
|
|
||||||
/** Add [alerts] to the stash, replacing any existing entry with the same id. */
|
|
||||||
suspend fun stash(alerts: List<ReminderAlert>, nowMillis: Long) {
|
|
||||||
if (alerts.isEmpty()) return
|
|
||||||
store.edit { prefs ->
|
|
||||||
val byId = decodeAll(prefs).associateByTo(mutableMapOf()) { it.alertId }
|
|
||||||
alerts.forEach { byId[it.alertId] = it }
|
|
||||||
prefs.putStash(byId.values.filter { it.isRelevantAt(nowMillis) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove and return the still-relevant stashed alerts belonging to any of
|
|
||||||
* [calendarIds]; drops expired entries for every calendar in passing.
|
|
||||||
*/
|
|
||||||
suspend fun recoverFor(calendarIds: Set<Long>, nowMillis: Long): List<ReminderAlert> {
|
|
||||||
val recovered = mutableListOf<ReminderAlert>()
|
|
||||||
store.edit { prefs ->
|
|
||||||
val kept = decodeAll(prefs).filter { alert ->
|
|
||||||
when {
|
|
||||||
!alert.isRelevantAt(nowMillis) -> false // expired: drop
|
|
||||||
alert.calendarId in calendarIds -> { recovered += alert; false }
|
|
||||||
else -> true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prefs.putStash(kept)
|
|
||||||
}
|
|
||||||
return recovered
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Drop entries whose event has already ended — cheap opportunistic cleanup. */
|
|
||||||
suspend fun purgeExpired(nowMillis: Long) {
|
|
||||||
store.edit { prefs ->
|
|
||||||
prefs.putStash(decodeAll(prefs).filter { it.isRelevantAt(nowMillis) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun decodeAll(prefs: Preferences): List<ReminderAlert> =
|
|
||||||
prefs[KEY].orEmpty().mapNotNull { decodeStashEntry(it) }
|
|
||||||
|
|
||||||
private fun MutablePreferences.putStash(alerts: List<ReminderAlert>) {
|
|
||||||
val encoded = alerts.map { encodeStashEntry(it) }.toSet()
|
|
||||||
if (encoded.isEmpty()) remove(KEY) else set(KEY, encoded)
|
|
||||||
}
|
|
||||||
|
|
||||||
private companion object {
|
|
||||||
val KEY = stringSetPreferencesKey("suppressed_reminders")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// One stash entry as a delimited string. The '|' separator is safe because every
|
|
||||||
// free-text field is Base64-encoded first (that alphabet never contains '|'), and
|
|
||||||
// a null location is stored as a distinct sentinel that Base64 also never yields.
|
|
||||||
private const val FIELD_SEP = "|"
|
|
||||||
private const val NULL_LOCATION = "-"
|
|
||||||
|
|
||||||
internal fun encodeStashEntry(alert: ReminderAlert): String = listOf(
|
|
||||||
alert.alertId.toString(),
|
|
||||||
alert.eventId.toString(),
|
|
||||||
alert.calendarId.toString(),
|
|
||||||
alert.beginMillis.toString(),
|
|
||||||
alert.endMillis.toString(),
|
|
||||||
if (alert.isAllDay) "1" else "0",
|
|
||||||
alert.title.toBase64(),
|
|
||||||
alert.location?.toBase64() ?: NULL_LOCATION,
|
|
||||||
).joinToString(FIELD_SEP)
|
|
||||||
|
|
||||||
/** Reverse of [encodeStashEntry]; returns null for a malformed entry (dropped). */
|
|
||||||
internal fun decodeStashEntry(raw: String): ReminderAlert? {
|
|
||||||
val parts = raw.split(FIELD_SEP)
|
|
||||||
if (parts.size != 8) return null
|
|
||||||
return try {
|
|
||||||
ReminderAlert(
|
|
||||||
alertId = parts[0].toLong(),
|
|
||||||
eventId = parts[1].toLong(),
|
|
||||||
calendarId = parts[2].toLong(),
|
|
||||||
beginMillis = parts[3].toLong(),
|
|
||||||
endMillis = parts[4].toLong(),
|
|
||||||
title = parts[6].fromBase64(),
|
|
||||||
location = parts[7].takeIf { it != NULL_LOCATION }?.fromBase64(),
|
|
||||||
isAllDay = parts[5] == "1",
|
|
||||||
)
|
|
||||||
} catch (e: NumberFormatException) {
|
|
||||||
null
|
|
||||||
} catch (e: IllegalArgumentException) { // bad Base64
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.toBase64(): String =
|
|
||||||
Base64.getEncoder().encodeToString(toByteArray(Charsets.UTF_8))
|
|
||||||
|
|
||||||
private fun String.fromBase64(): String =
|
|
||||||
String(Base64.getDecoder().decode(this), Charsets.UTF_8)
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.domain
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ways a calendar can behave unlike a plain, writable one — each of them a
|
||||||
|
* reason it is missing from the event and import pickers, and each of them
|
||||||
|
* something the app knows and used to keep to itself (#76).
|
||||||
|
*/
|
||||||
|
enum class CalendarStateLabel {
|
||||||
|
/**
|
||||||
|
* A special-dates mirror the app fills from contacts. Writable and visible,
|
||||||
|
* yet no event target: anything authored here is deleted by the next sync,
|
||||||
|
* which is why it is the one exclusion with nothing else to give it away.
|
||||||
|
*/
|
||||||
|
MANAGED,
|
||||||
|
|
||||||
|
/** Contents can't be modified: a WebCal subscription, a read-only share. */
|
||||||
|
READ_ONLY,
|
||||||
|
|
||||||
|
/** The account holds the events, but this device isn't syncing them down. */
|
||||||
|
NOT_SYNCED,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the account this calendar belongs to keeps its events off the device
|
||||||
|
* (`Calendars.SYNC_EVENTS = 0`) — an "empty by construction" calendar: the rows
|
||||||
|
* simply aren't here, so nothing can display them and no reminder can fire.
|
||||||
|
*
|
||||||
|
* Device-local calendars are excluded deliberately. Nothing syncs them by
|
||||||
|
* definition, so the flag says nothing about them, and a local calendar from
|
||||||
|
* another app can hold real events at `sync_events = 0` — the same unsoundness
|
||||||
|
* that made the #75 migration guard wrong.
|
||||||
|
*/
|
||||||
|
val CalendarSource.isNotSynced: Boolean
|
||||||
|
get() = !syncsEvents && !isLocal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a visibility switch on this calendar can change anything the user
|
||||||
|
* would see. It can't for a non-syncing one: there are no events on the device
|
||||||
|
* to reveal, so the switch would be a control that does nothing.
|
||||||
|
*/
|
||||||
|
val CalendarSource.hasVisibilitySwitch: Boolean
|
||||||
|
get() = !isNotSynced
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this calendar can be offered as a target for a new or imported event.
|
||||||
|
* The one predicate behind both pickers, so the states [CalendarStateLabel]
|
||||||
|
* names on a manager row are exactly the states that keep a calendar out of
|
||||||
|
* them (#76):
|
||||||
|
*
|
||||||
|
* - read-only has nowhere to write;
|
||||||
|
* - switched off would hide the event the moment it was saved;
|
||||||
|
* - a managed mirror has the next contact sync delete it;
|
||||||
|
* - a non-syncing one never carries the event up to the account, and
|
||||||
|
* `CalendarProvider2` wipes the calendar's rows outright when the
|
||||||
|
* subscription is switched back on — a saved event is a dead end either way.
|
||||||
|
*
|
||||||
|
* This is the test for *targets*. An event already living in an excluded
|
||||||
|
* calendar keeps it; the editor adds that calendar back to its picker.
|
||||||
|
*/
|
||||||
|
val CalendarSource.isEventTarget: Boolean
|
||||||
|
get() = canModifyContents && isVisibleInSystem && !isManaged && !isNotSynced
|
||||||
|
|
||||||
|
/** Every state worth naming on this calendar's row, in reading order. */
|
||||||
|
fun CalendarSource.stateLabels(): List<CalendarStateLabel> = buildList {
|
||||||
|
if (isManaged) add(CalendarStateLabel.MANAGED)
|
||||||
|
if (!canModifyContents) add(CalendarStateLabel.READ_ONLY)
|
||||||
|
if (isNotSynced) add(CalendarStateLabel.NOT_SYNCED)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar-manager order within one group: the ones you can actually act on
|
||||||
|
* first, the non-syncing ones after them. Stable otherwise, so the provider's
|
||||||
|
* display-name ordering survives.
|
||||||
|
*/
|
||||||
|
fun List<CalendarSource>.orderedForManager(): List<CalendarSource> =
|
||||||
|
sortedBy { it.isNotSynced }
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.domain
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `Calendars.VISIBLE` writes that flush the app's pending "switched off"
|
||||||
|
* set into the provider, plus the ids that need no write at all.
|
||||||
|
*/
|
||||||
|
data class CalendarVisibilityPlan(
|
||||||
|
val hide: Set<Long> = emptySet(),
|
||||||
|
val settled: Set<Long> = emptySet(),
|
||||||
|
) {
|
||||||
|
val isEmpty: Boolean get() = hide.isEmpty() && settled.isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reconcile [pendingDisabledIds] — calendars switched off in Settings →
|
||||||
|
* Calendars while the app could not write `Calendars.VISIBLE`, plus whatever
|
||||||
|
* the retired app-local visibility model left behind (#75) — against the
|
||||||
|
* calendars actually on the device.
|
||||||
|
*
|
||||||
|
* The plan only ever *hides*. Switching a calendar off is intent the user
|
||||||
|
* expressed in Calendula, so carrying it into the provider is fair. The other
|
||||||
|
* direction is deliberately absent: a calendar hidden at system level was hidden
|
||||||
|
* somewhere else (another calendar app, the account's own settings), and
|
||||||
|
* switching it back on would un-hide it there too *and* start firing reminders
|
||||||
|
* nobody asked for. Calendula follows that flag instead and explains itself once
|
||||||
|
* (see [hasSystemHiddenCalendars]).
|
||||||
|
*
|
||||||
|
* [CalendarVisibilityPlan.settled] carries the ids that need no write — already
|
||||||
|
* hidden, or gone from the device. They leave the pending set exactly as a
|
||||||
|
* successful write would.
|
||||||
|
*/
|
||||||
|
fun calendarVisibilityPlan(
|
||||||
|
calendars: List<CalendarSource>,
|
||||||
|
pendingDisabledIds: Set<Long>,
|
||||||
|
): CalendarVisibilityPlan {
|
||||||
|
val byId = calendars.associateBy { it.id }
|
||||||
|
val hide = mutableSetOf<Long>()
|
||||||
|
val settled = mutableSetOf<Long>()
|
||||||
|
for (id in pendingDisabledIds) {
|
||||||
|
val calendar = byId[id]
|
||||||
|
// No row means the calendar is gone; already invisible means someone
|
||||||
|
// (us, on an earlier run) got there first. Either way: nothing to write.
|
||||||
|
if (calendar != null && calendar.isVisibleInSystem) hide += id else settled += id
|
||||||
|
}
|
||||||
|
return CalendarVisibilityPlan(hide = hide, settled = settled)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether any calendar is switched off at system level without Calendula having
|
||||||
|
* asked for it. Those calendars showed their events before the app adopted
|
||||||
|
* `Calendars.VISIBLE` as its one visibility model and no longer do, which is
|
||||||
|
* what the one-time notice explains — the alternative, switching them on, would
|
||||||
|
* reach into every other calendar app on the device.
|
||||||
|
*/
|
||||||
|
fun hasSystemHiddenCalendars(
|
||||||
|
calendars: List<CalendarSource>,
|
||||||
|
pendingDisabledIds: Set<Long>,
|
||||||
|
): Boolean = calendars.any { !it.isVisibleInSystem && it.id !in pendingDisabledIds }
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package de.jeanlucmakiola.calendula.domain
|
package de.jeanlucmakiola.calendula.domain
|
||||||
|
|
||||||
|
import kotlinx.datetime.LocalDate
|
||||||
|
import kotlinx.datetime.TimeZone
|
||||||
|
import kotlinx.datetime.toLocalDateTime
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
import kotlin.time.Instant
|
import kotlin.time.Instant
|
||||||
|
|
||||||
data class CalendarSource(
|
data class CalendarSource(
|
||||||
@@ -8,6 +12,13 @@ data class CalendarSource(
|
|||||||
val accountName: String,
|
val accountName: String,
|
||||||
val accountType: String,
|
val accountType: String,
|
||||||
val color: Int,
|
val color: Int,
|
||||||
|
/**
|
||||||
|
* The system's per-calendar `Calendars.VISIBLE` flag — the single visibility
|
||||||
|
* model: it decides both what Calendula shows and whether the provider
|
||||||
|
* schedules this calendar's reminder alarms at all (#75). Settings →
|
||||||
|
* Calendars writes it; the drawer's filter sheet is a separate, purely
|
||||||
|
* in-app declutter that leaves reminders alone.
|
||||||
|
*/
|
||||||
val isVisibleInSystem: Boolean,
|
val isVisibleInSystem: Boolean,
|
||||||
/**
|
/**
|
||||||
* Whether events in this calendar can be created/edited/deleted
|
* Whether events in this calendar can be created/edited/deleted
|
||||||
@@ -34,6 +45,15 @@ data class CalendarSource(
|
|||||||
* even after a backup restore clears the app's stored ids.
|
* even after a backup restore clears the app's stored ids.
|
||||||
*/
|
*/
|
||||||
val isManaged: Boolean = false,
|
val isManaged: Boolean = false,
|
||||||
|
/**
|
||||||
|
* Whether the provider keeps this calendar's events on the device
|
||||||
|
* (`Calendars.SYNC_EVENTS`). Independent of [isVisibleInSystem]. For a
|
||||||
|
* synced account it means the events aren't stored locally at all, so the
|
||||||
|
* calendar reads as permanently empty; a device-local calendar another app
|
||||||
|
* created can hold events with the flag off, so it says nothing there.
|
||||||
|
* Read for the "not synced" row label (#76).
|
||||||
|
*/
|
||||||
|
val syncsEvents: Boolean = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class EventInstance(
|
data class EventInstance(
|
||||||
@@ -56,6 +76,35 @@ data class EventInstance(
|
|||||||
*/
|
*/
|
||||||
fun EventInstance.hasEnded(now: Instant): Boolean = end <= now
|
fun EventInstance.hasEnded(now: Instant): Boolean = end <= now
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The zone this event's calendar dates live in. Timed events are resolved in the
|
||||||
|
* device [zone]; all-day events live at UTC midnights with an exclusive end, so
|
||||||
|
* resolving them anywhere else shifts the day boundaries — east of UTC the end
|
||||||
|
* leaks onto the following day (#65), west of UTC the start pulls back onto the
|
||||||
|
* previous one (#82). Every surface that has to name an all-day event's date
|
||||||
|
* goes through here, so grid, agenda, detail and search cannot disagree.
|
||||||
|
*/
|
||||||
|
fun EventInstance.dateZone(zone: TimeZone): TimeZone =
|
||||||
|
if (isAllDay) TimeZone.UTC else zone
|
||||||
|
|
||||||
|
/** The first calendar day this event occupies. */
|
||||||
|
fun EventInstance.spanFirstDay(zone: TimeZone): LocalDate =
|
||||||
|
start.toLocalDateTime(dateZone(zone)).date
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last calendar day this event actually occupies. An event ending exactly at
|
||||||
|
* midnight (all-day events end at the exclusive next-midnight) does not reach
|
||||||
|
* into that boundary day, so resolve the instant just before [EventInstance.end].
|
||||||
|
*/
|
||||||
|
fun EventInstance.spanLastDay(zone: TimeZone): LocalDate {
|
||||||
|
val lastInstant = if (end > start) end - 1.milliseconds else start
|
||||||
|
return lastInstant.toLocalDateTime(dateZone(zone)).date
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether this event occupies more than one calendar day in [zone]. */
|
||||||
|
fun EventInstance.spansMultipleDays(zone: TimeZone): Boolean =
|
||||||
|
spanFirstDay(zone) != spanLastDay(zone)
|
||||||
|
|
||||||
data class EventDetail(
|
data class EventDetail(
|
||||||
val instance: EventInstance,
|
val instance: EventInstance,
|
||||||
val description: String?,
|
val description: String?,
|
||||||
|
|||||||
@@ -415,6 +415,7 @@ fun CalendarHost(
|
|||||||
initialStartMinutes = createStartMinutes ?: heldCreateMinutes,
|
initialStartMinutes = createStartMinutes ?: heldCreateMinutes,
|
||||||
onClose = { createDateIso = null },
|
onClose = { createDateIso = null },
|
||||||
onSaved = { createDateIso = null },
|
onSaved = { createDateIso = null },
|
||||||
|
onManageCalendars = { showCalendars = true },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -434,6 +435,7 @@ fun CalendarHost(
|
|||||||
editKey = null
|
editKey = null
|
||||||
detailKey = null
|
detailKey = null
|
||||||
},
|
},
|
||||||
|
onManageCalendars = { showCalendars = true },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,18 +452,6 @@ fun CalendarHost(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calendar manager — slides over Settings.
|
|
||||||
AnimatedVisibility(
|
|
||||||
visible = showCalendars,
|
|
||||||
enter = slideInHorizontally(slideSpec) { it } + fadeIn(),
|
|
||||||
exit = slideOutHorizontally(slideSpec) { it } + fadeOut(),
|
|
||||||
) {
|
|
||||||
CalendarsScreen(
|
|
||||||
onBack = { showCalendars = false },
|
|
||||||
onImport = { importUri = it; importForceMany = true },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Import flow for an opened/received .ics file. A single event routes
|
// Import flow for an opened/received .ics file. A single event routes
|
||||||
// into the create form (prefilled, for review); many open the picker.
|
// into the create form (prefilled, for review); many open the picker.
|
||||||
importUri?.let { uri ->
|
importUri?.let { uri ->
|
||||||
@@ -469,6 +459,7 @@ fun CalendarHost(
|
|||||||
uri = uri,
|
uri = uri,
|
||||||
forceMany = importForceMany,
|
forceMany = importForceMany,
|
||||||
onClose = { importUri = null },
|
onClose = { importUri = null },
|
||||||
|
onManageCalendars = { showCalendars = true },
|
||||||
onOpenSingle = { form ->
|
onOpenSingle = { form ->
|
||||||
importUri = null
|
importUri = null
|
||||||
importFormSource = ImportSource.File
|
importFormSource = ImportSource.File
|
||||||
@@ -483,6 +474,27 @@ fun CalendarHost(
|
|||||||
initialFormSource = importFormSource,
|
initialFormSource = importFormSource,
|
||||||
onClose = { importForm = null },
|
onClose = { importForm = null },
|
||||||
onSaved = { importForm = null },
|
onSaved = { importForm = null },
|
||||||
|
onManageCalendars = { showCalendars = true },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calendar manager — declared last so it covers every overlay that can
|
||||||
|
// open it: Settings, both event forms, and the .ics import picker (#76).
|
||||||
|
// Coming back from it leaves the caller exactly as it was, with the
|
||||||
|
// calendar list already refreshed by the provider's notification.
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = showCalendars,
|
||||||
|
enter = slideInHorizontally(slideSpec) { it } + fadeIn(),
|
||||||
|
exit = slideOutHorizontally(slideSpec) { it } + fadeOut(),
|
||||||
|
) {
|
||||||
|
CalendarsScreen(
|
||||||
|
onBack = { showCalendars = false },
|
||||||
|
// The manager opens the import too (restore from backup), and
|
||||||
|
// that way round it has to step aside: declared above the import
|
||||||
|
// overlays, it would otherwise cover the screen it just asked
|
||||||
|
// for. Closing it hands the user back to whatever opened the
|
||||||
|
// manager once the import is done.
|
||||||
|
onImport = { importUri = it; importForceMany = true; showCalendars = false },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@@ -21,6 +22,8 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
|
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
|
||||||
import de.jeanlucmakiola.calendula.data.contacts.hasContactsPermission
|
import de.jeanlucmakiola.calendula.data.contacts.hasContactsPermission
|
||||||
|
import de.jeanlucmakiola.calendula.ui.calendars.CalendarVisibilityNoticeDialog
|
||||||
|
import de.jeanlucmakiola.calendula.ui.calendars.CalendarVisibilityNoticeViewModel
|
||||||
import de.jeanlucmakiola.calendula.ui.permission.PermissionScreen
|
import de.jeanlucmakiola.calendula.ui.permission.PermissionScreen
|
||||||
import de.jeanlucmakiola.calendula.ui.permission.ReminderOnboardingScreen
|
import de.jeanlucmakiola.calendula.ui.permission.ReminderOnboardingScreen
|
||||||
import de.jeanlucmakiola.calendula.ui.permission.ReminderOnboardingViewModel
|
import de.jeanlucmakiola.calendula.ui.permission.ReminderOnboardingViewModel
|
||||||
@@ -78,6 +81,17 @@ fun RootScreen(
|
|||||||
// frame instead of flashing the wrong screen.
|
// frame instead of flashing the wrong screen.
|
||||||
val reminderOnboarding: ReminderOnboardingViewModel = hiltViewModel()
|
val reminderOnboarding: ReminderOnboardingViewModel = hiltViewModel()
|
||||||
val onboardingDone by reminderOnboarding.onboardingDone.collectAsStateWithLifecycle()
|
val onboardingDone by reminderOnboarding.onboardingDone.collectAsStateWithLifecycle()
|
||||||
|
// One-time explainer for the switch to the device's own calendar
|
||||||
|
// visibility (#75); armed by the reconciler, shown over the app.
|
||||||
|
val visibilityNotice: CalendarVisibilityNoticeViewModel = hiltViewModel()
|
||||||
|
val noticePending by visibilityNotice.pending.collectAsStateWithLifecycle()
|
||||||
|
// Runs on entry however the permission was granted — including from
|
||||||
|
// Android's app-settings screen, which only comes back through the
|
||||||
|
// ON_RESUME check above. Cheap once there is nothing left to do.
|
||||||
|
LaunchedEffect(Unit) { visibilityNotice.reconcile() }
|
||||||
|
if (onboardingDone == true && noticePending) {
|
||||||
|
CalendarVisibilityNoticeDialog(onDismiss = visibilityNotice::dismiss)
|
||||||
|
}
|
||||||
Crossfade(targetState = onboardingDone, animationSpec = gateSpec, label = "onboardingGate") { done ->
|
Crossfade(targetState = onboardingDone, animationSpec = gateSpec, label = "onboardingGate") { done ->
|
||||||
when (done) {
|
when (done) {
|
||||||
true -> CalendarHost(
|
true -> CalendarHost(
|
||||||
|
|||||||
@@ -2,41 +2,14 @@ package de.jeanlucmakiola.calendula.ui.agenda
|
|||||||
|
|
||||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||||
import de.jeanlucmakiola.calendula.domain.FailureReason
|
import de.jeanlucmakiola.calendula.domain.FailureReason
|
||||||
|
import de.jeanlucmakiola.calendula.domain.spanFirstDay
|
||||||
|
import de.jeanlucmakiola.calendula.domain.spanLastDay
|
||||||
import kotlinx.datetime.DateTimeUnit
|
import kotlinx.datetime.DateTimeUnit
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import kotlinx.datetime.TimeZone
|
import kotlinx.datetime.TimeZone
|
||||||
import kotlinx.datetime.plus
|
import kotlinx.datetime.plus
|
||||||
import kotlinx.datetime.toLocalDateTime
|
|
||||||
import kotlin.time.Duration.Companion.milliseconds
|
|
||||||
import kotlin.time.Instant
|
import kotlin.time.Instant
|
||||||
|
|
||||||
/**
|
|
||||||
* The zone the event's calendar dates live in. Timed events are resolved in the
|
|
||||||
* device [zone]; all-day events live at UTC midnights with an exclusive end, so
|
|
||||||
* resolving them anywhere but UTC shifts the boundaries — east of UTC that leaks
|
|
||||||
* a one-day event onto its next day. Matches the Week view and detail card.
|
|
||||||
*/
|
|
||||||
private fun EventInstance.dateZone(zone: TimeZone): TimeZone =
|
|
||||||
if (isAllDay) TimeZone.UTC else zone
|
|
||||||
|
|
||||||
/** The first calendar day this event occupies. */
|
|
||||||
fun EventInstance.spanFirstDay(zone: TimeZone): LocalDate =
|
|
||||||
start.toLocalDateTime(dateZone(zone)).date
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The last calendar day this event actually occupies. An event ending exactly at
|
|
||||||
* midnight (all-day events end at the exclusive next-midnight) does not reach
|
|
||||||
* into that boundary day, so resolve the instant just before [end].
|
|
||||||
*/
|
|
||||||
fun EventInstance.spanLastDay(zone: TimeZone): LocalDate {
|
|
||||||
val lastInstant = if (end > start) end - 1.milliseconds else start
|
|
||||||
return lastInstant.toLocalDateTime(dateZone(zone)).date
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Whether this event occupies more than one calendar day in [zone]. */
|
|
||||||
fun EventInstance.spansMultipleDays(zone: TimeZone): Boolean =
|
|
||||||
spanFirstDay(zone) != spanLastDay(zone)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What an agenda row's time line should convey for an event on a given day —
|
* What an agenda row's time line should convey for an event on a given day —
|
||||||
* the part of a multi-day span that [day] falls in. Pure and shared so the
|
* the part of a multi-day span that [day] falls in. Pure and shared so the
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.ui.calendars
|
||||||
|
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.VisibilityOff
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
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.CalendarVisibilityReconciler
|
||||||
|
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The one-time notice that Calendula now follows the device's per-calendar
|
||||||
|
* visibility (#75). Armed by `CalendarVisibilityReconciler` on the first launch
|
||||||
|
* that finds a calendar switched off outside the app — those used to show their
|
||||||
|
* events here and no longer do, and the app deliberately does not switch them
|
||||||
|
* back on, because that would un-hide them in every other calendar app too.
|
||||||
|
*/
|
||||||
|
@HiltViewModel
|
||||||
|
class CalendarVisibilityNoticeViewModel @Inject constructor(
|
||||||
|
private val prefs: CalendarPrefs,
|
||||||
|
private val reconciler: CalendarVisibilityReconciler,
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reconcile whenever the app comes up with the calendar permission held.
|
||||||
|
* The launch itself is covered by `CalendulaApp`, but a permission granted
|
||||||
|
* on Android's app-settings screen comes back through `RootScreen`'s
|
||||||
|
* ON_RESUME and never touches the permission screen's callback — so the
|
||||||
|
* trigger hangs off "we are showing the app", not off one grant route.
|
||||||
|
* Settled runs cost two DataStore reads and stop there.
|
||||||
|
*/
|
||||||
|
fun reconcile() {
|
||||||
|
viewModelScope.launch { reconciler.run() }
|
||||||
|
}
|
||||||
|
|
||||||
|
val pending: StateFlow<Boolean> = prefs.visibilityNoticePending
|
||||||
|
.map { it == true }
|
||||||
|
.stateIn(
|
||||||
|
scope = viewModelScope,
|
||||||
|
started = SharingStarted.WhileSubscribed(5_000L),
|
||||||
|
initialValue = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun dismiss() {
|
||||||
|
viewModelScope.launch { prefs.setVisibilityNoticePending(false) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Plain informational dialog — one acknowledgement, nothing to decide. */
|
||||||
|
@Composable
|
||||||
|
fun CalendarVisibilityNoticeDialog(onDismiss: () -> Unit) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
icon = { Icon(Icons.Default.VisibilityOff, contentDescription = null) },
|
||||||
|
title = { Text(stringResource(R.string.calendars_visibility_notice_title)) },
|
||||||
|
text = { Text(stringResource(R.string.calendars_visibility_notice_message)) },
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(stringResource(R.string.dialog_ok))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ import androidx.compose.material.icons.filled.CalendarMonth
|
|||||||
import androidx.compose.material.icons.filled.Close
|
import androidx.compose.material.icons.filled.Close
|
||||||
import androidx.compose.material.icons.filled.Cloud
|
import androidx.compose.material.icons.filled.Cloud
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Info
|
||||||
import androidx.compose.material.icons.filled.FileDownload
|
import androidx.compose.material.icons.filled.FileDownload
|
||||||
import androidx.compose.material.icons.filled.FileUpload
|
import androidx.compose.material.icons.filled.FileUpload
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
@@ -91,6 +92,12 @@ import de.jeanlucmakiola.calendula.R
|
|||||||
import de.jeanlucmakiola.calendula.data.prefs.BackupStatus
|
import de.jeanlucmakiola.calendula.data.prefs.BackupStatus
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||||
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
||||||
|
import de.jeanlucmakiola.calendula.domain.CalendarStateLabel
|
||||||
|
import de.jeanlucmakiola.calendula.domain.hasVisibilitySwitch
|
||||||
|
import de.jeanlucmakiola.calendula.domain.isEventTarget
|
||||||
|
import de.jeanlucmakiola.calendula.domain.isNotSynced
|
||||||
|
import de.jeanlucmakiola.calendula.domain.orderedForManager
|
||||||
|
import de.jeanlucmakiola.calendula.domain.stateLabels
|
||||||
import de.jeanlucmakiola.calendula.data.calendar.CalendarColorPalette
|
import de.jeanlucmakiola.calendula.data.calendar.CalendarColorPalette
|
||||||
import de.jeanlucmakiola.calendula.ui.common.CalendarColorChip
|
import de.jeanlucmakiola.calendula.ui.common.CalendarColorChip
|
||||||
import de.jeanlucmakiola.calendula.ui.common.LocalSoftenColors
|
import de.jeanlucmakiola.calendula.ui.common.LocalSoftenColors
|
||||||
@@ -139,7 +146,7 @@ fun CalendarsScreen(
|
|||||||
viewModel: CalendarsViewModel = hiltViewModel(),
|
viewModel: CalendarsViewModel = hiltViewModel(),
|
||||||
) {
|
) {
|
||||||
val calendars by viewModel.calendars.collectAsStateWithLifecycle()
|
val calendars by viewModel.calendars.collectAsStateWithLifecycle()
|
||||||
val disabledIds by viewModel.disabledCalendarIds.collectAsStateWithLifecycle()
|
val deleteLockedIds by viewModel.deleteLockedCalendarIds.collectAsStateWithLifecycle()
|
||||||
val error by viewModel.error.collectAsStateWithLifecycle()
|
val error by viewModel.error.collectAsStateWithLifecycle()
|
||||||
val backupResult by viewModel.backupResult.collectAsStateWithLifecycle()
|
val backupResult by viewModel.backupResult.collectAsStateWithLifecycle()
|
||||||
val autoBackup by viewModel.autoBackup.collectAsStateWithLifecycle()
|
val autoBackup by viewModel.autoBackup.collectAsStateWithLifecycle()
|
||||||
@@ -158,6 +165,7 @@ fun CalendarsScreen(
|
|||||||
initialName = editing?.displayName.orEmpty(),
|
initialName = editing?.displayName.orEmpty(),
|
||||||
initialColor = editing?.color ?: CalendarColorPalette.all.first(),
|
initialColor = editing?.color ?: CalendarColorPalette.all.first(),
|
||||||
initialDescription = editing?.description.orEmpty(),
|
initialDescription = editing?.description.orEmpty(),
|
||||||
|
deleteLocked = editing != null && editing.id in deleteLockedIds,
|
||||||
onSave = { name, color, description ->
|
onSave = { name, color, description ->
|
||||||
val id = editorId
|
val id = editorId
|
||||||
if (id == null || id == NEW_CALENDAR_ID) {
|
if (id == null || id == NEW_CALENDAR_ID) {
|
||||||
@@ -177,7 +185,6 @@ fun CalendarsScreen(
|
|||||||
CalendarsList(
|
CalendarsList(
|
||||||
local = calendars.filter { it.isLocal },
|
local = calendars.filter { it.isLocal },
|
||||||
synced = calendars.filterNot { it.isLocal },
|
synced = calendars.filterNot { it.isLocal },
|
||||||
disabledIds = disabledIds,
|
|
||||||
error = error,
|
error = error,
|
||||||
onConsumeError = viewModel::consumeError,
|
onConsumeError = viewModel::consumeError,
|
||||||
backupResult = backupResult,
|
backupResult = backupResult,
|
||||||
@@ -191,8 +198,8 @@ fun CalendarsScreen(
|
|||||||
onBack = onBack,
|
onBack = onBack,
|
||||||
onAdd = { editorSession++; editorId = NEW_CALENDAR_ID },
|
onAdd = { editorSession++; editorId = NEW_CALENDAR_ID },
|
||||||
onEdit = { calendar -> editorSession++; editorId = calendar.id },
|
onEdit = { calendar -> editorSession++; editorId = calendar.id },
|
||||||
onSetDisabled = viewModel::setDisabled,
|
onSetVisible = viewModel::setCalendarVisible,
|
||||||
onSetAccountDisabled = viewModel::setAccountDisabled,
|
onSetAccountVisible = viewModel::setAccountVisible,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,7 +208,6 @@ fun CalendarsScreen(
|
|||||||
private fun CalendarsList(
|
private fun CalendarsList(
|
||||||
local: List<CalendarSource>,
|
local: List<CalendarSource>,
|
||||||
synced: List<CalendarSource>,
|
synced: List<CalendarSource>,
|
||||||
disabledIds: Set<Long>,
|
|
||||||
error: Boolean,
|
error: Boolean,
|
||||||
onConsumeError: () -> Unit,
|
onConsumeError: () -> Unit,
|
||||||
backupResult: BackupResult?,
|
backupResult: BackupResult?,
|
||||||
@@ -215,8 +221,8 @@ private fun CalendarsList(
|
|||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onAdd: () -> Unit,
|
onAdd: () -> Unit,
|
||||||
onEdit: (CalendarSource) -> Unit,
|
onEdit: (CalendarSource) -> Unit,
|
||||||
onSetDisabled: (Long, Boolean) -> Unit,
|
onSetVisible: (Long, Boolean) -> Unit,
|
||||||
onSetAccountDisabled: (Collection<Long>, Boolean) -> Unit,
|
onSetAccountVisible: (Collection<Long>, Boolean) -> Unit,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val snackbarHostState = remember { SnackbarHostState() }
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
@@ -281,12 +287,12 @@ private fun CalendarsList(
|
|||||||
predictiveBack = true,
|
predictiveBack = true,
|
||||||
) {
|
) {
|
||||||
// What the per-calendar / per-account switches below actually do.
|
// What the per-calendar / per-account switches below actually do.
|
||||||
HintText(stringResource(R.string.calendars_disable_hint))
|
HintText(stringResource(R.string.calendars_visibility_hint))
|
||||||
|
|
||||||
// Local (device-only) calendars — one collapsible group. The header's
|
// Local (device-only) calendars — one collapsible group. The header's
|
||||||
// "+" adds a calendar; the switch enables/disables them all at once;
|
// "+" adds a calendar; the switch enables/disables them all at once;
|
||||||
// tapping a calendar row opens its editor.
|
// tapping a calendar row opens its editor.
|
||||||
val localDisabled = local.isNotEmpty() && local.all { it.id in disabledIds }
|
val localDisabled = local.isNotEmpty() && local.none { it.isVisibleInSystem }
|
||||||
CalendarGroup(
|
CalendarGroup(
|
||||||
title = stringResource(R.string.calendars_local_header),
|
title = stringResource(R.string.calendars_local_header),
|
||||||
expanded = localExpanded,
|
expanded = localExpanded,
|
||||||
@@ -298,17 +304,17 @@ private fun CalendarsList(
|
|||||||
onManage = onAdd,
|
onManage = onAdd,
|
||||||
onToggleExpand = { localExpanded = !localExpanded },
|
onToggleExpand = { localExpanded = !localExpanded },
|
||||||
showToggleAll = local.isNotEmpty(),
|
showToggleAll = local.isNotEmpty(),
|
||||||
allEnabled = local.none { it.id in disabledIds },
|
allEnabled = local.all { it.isVisibleInSystem },
|
||||||
onToggleAll = { enabled -> onSetAccountDisabled(local.map { it.id }, !enabled) },
|
onToggleAll = { enabled -> onSetAccountVisible(local.map { it.id }, enabled) },
|
||||||
) {
|
) {
|
||||||
if (local.isEmpty()) {
|
if (local.isEmpty()) {
|
||||||
HintText(stringResource(R.string.calendars_local_empty))
|
HintText(stringResource(R.string.calendars_local_empty))
|
||||||
} else {
|
} else {
|
||||||
local.forEachIndexed { index, calendar ->
|
local.forEachIndexed { index, calendar ->
|
||||||
val disabled = calendar.id in disabledIds
|
val disabled = !calendar.isVisibleInSystem
|
||||||
GroupedRow(
|
GroupedRow(
|
||||||
title = calendar.displayName,
|
title = calendar.displayName,
|
||||||
summary = calendar.description,
|
summary = calendarRowSummary(calendar),
|
||||||
position = if (index == local.lastIndex) Position.Bottom else Position.Middle,
|
position = if (index == local.lastIndex) Position.Bottom else Position.Middle,
|
||||||
container = MaterialTheme.colorScheme.surfaceContainerHighest,
|
container = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||||
dimmed = disabled,
|
dimmed = disabled,
|
||||||
@@ -317,7 +323,7 @@ private fun CalendarsList(
|
|||||||
EnableSwitch(
|
EnableSwitch(
|
||||||
calendarName = calendar.displayName,
|
calendarName = calendar.displayName,
|
||||||
enabled = !disabled,
|
enabled = !disabled,
|
||||||
onToggle = { enabled -> onSetDisabled(calendar.id, !enabled) },
|
onToggle = { enabled -> onSetVisible(calendar.id, enabled) },
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onClick = { onEdit(calendar) },
|
onClick = { onEdit(calendar) },
|
||||||
@@ -330,9 +336,9 @@ private fun CalendarsList(
|
|||||||
// safety net. Offered only when there is something exportable: the user's
|
// safety net. Offered only when there is something exportable: the user's
|
||||||
// own local calendars (managed special-dates mirrors don't count).
|
// own local calendars (managed special-dates mirrors don't count).
|
||||||
val exportable = local.filter { it.canModifyContents && !it.isManaged }
|
val exportable = local.filter { it.canModifyContents && !it.isManaged }
|
||||||
// Restore/import can target any writable, non-managed calendar (local or
|
// Restore/import can target any calendar the import picker would offer
|
||||||
// synced), so its availability is broader than export's.
|
// (local or synced), so its availability is broader than export's.
|
||||||
val canImport = (local + synced).any { it.canModifyContents && !it.isManaged }
|
val canImport = (local + synced).any { it.isEventTarget }
|
||||||
if (exportable.isNotEmpty()) {
|
if (exportable.isNotEmpty()) {
|
||||||
Spacer(Modifier.height(16.dp))
|
Spacer(Modifier.height(16.dp))
|
||||||
SectionHeader(stringResource(R.string.calendars_backup_header))
|
SectionHeader(stringResource(R.string.calendars_backup_header))
|
||||||
@@ -415,7 +421,11 @@ private fun CalendarsList(
|
|||||||
.forEach { (account, cals) ->
|
.forEach { (account, cals) ->
|
||||||
val expanded = account !in collapsedAccounts
|
val expanded = account !in collapsedAccounts
|
||||||
val accountType = cals.first().accountType
|
val accountType = cals.first().accountType
|
||||||
val accountDisabled = cals.all { it.id in disabledIds }
|
// A non-syncing calendar has no switch, so it neither counts
|
||||||
|
// towards "the whole account is off" nor moves with toggle-all.
|
||||||
|
val switchable = cals.filter { it.hasVisibilitySwitch }
|
||||||
|
val accountDisabled = switchable.isNotEmpty() &&
|
||||||
|
switchable.none { it.isVisibleInSystem }
|
||||||
Spacer(Modifier.height(16.dp))
|
Spacer(Modifier.height(16.dp))
|
||||||
CalendarGroup(
|
CalendarGroup(
|
||||||
title = account,
|
title = account,
|
||||||
@@ -435,24 +445,36 @@ private fun CalendarsList(
|
|||||||
collapsedAccounts - account
|
collapsedAccounts - account
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showToggleAll = true,
|
showToggleAll = switchable.isNotEmpty(),
|
||||||
allEnabled = cals.none { it.id in disabledIds },
|
allEnabled = switchable.all { it.isVisibleInSystem },
|
||||||
onToggleAll = { enabled -> onSetAccountDisabled(cals.map { it.id }, !enabled) },
|
onToggleAll = { enabled ->
|
||||||
|
onSetAccountVisible(switchable.map { it.id }, enabled)
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
cals.forEachIndexed { index, calendar ->
|
// Calendars you can act on first; the ones this device isn't
|
||||||
val disabled = calendar.id in disabledIds
|
// syncing sit at the bottom, dimmed and switchless.
|
||||||
|
val ordered = cals.orderedForManager()
|
||||||
|
ordered.forEachIndexed { index, calendar ->
|
||||||
|
val disabled = !calendar.isVisibleInSystem || calendar.isNotSynced
|
||||||
GroupedRow(
|
GroupedRow(
|
||||||
title = calendar.displayName,
|
title = calendar.displayName,
|
||||||
position = if (index == cals.lastIndex) Position.Bottom else Position.Middle,
|
summary = calendarRowSummary(calendar),
|
||||||
|
position = if (index == ordered.lastIndex) Position.Bottom else Position.Middle,
|
||||||
container = MaterialTheme.colorScheme.surfaceContainerHighest,
|
container = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||||
dimmed = disabled,
|
dimmed = disabled,
|
||||||
leading = { CalendarColorChip(calendar.color, dimIf(disabled)) },
|
leading = { CalendarColorChip(calendar.color, dimIf(disabled)) },
|
||||||
trailing = {
|
trailing = if (calendar.hasVisibilitySwitch) {
|
||||||
|
{
|
||||||
EnableSwitch(
|
EnableSwitch(
|
||||||
calendarName = calendar.displayName,
|
calendarName = calendar.displayName,
|
||||||
enabled = !disabled,
|
enabled = calendar.isVisibleInSystem,
|
||||||
onToggle = { enabled -> onSetDisabled(calendar.id, !enabled) },
|
onToggle = { enabled ->
|
||||||
|
onSetVisible(calendar.id, enabled)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -560,6 +582,7 @@ private fun CalendarEditor(
|
|||||||
onSave: (name: String, color: Int, description: String?) -> Unit,
|
onSave: (name: String, color: Int, description: String?) -> Unit,
|
||||||
onDelete: () -> Unit,
|
onDelete: () -> Unit,
|
||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
|
deleteLocked: Boolean = false,
|
||||||
) {
|
) {
|
||||||
var name by rememberSaveable(sessionKey) { mutableStateOf(initialName) }
|
var name by rememberSaveable(sessionKey) { mutableStateOf(initialName) }
|
||||||
var color by rememberSaveable(sessionKey) { mutableStateOf(initialColor) }
|
var color by rememberSaveable(sessionKey) { mutableStateOf(initialColor) }
|
||||||
@@ -593,11 +616,23 @@ private fun CalendarEditor(
|
|||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
if (!isNew) {
|
if (!isNew) {
|
||||||
IconButton(onClick = { confirmDelete = true }) {
|
// Kept in place while the special-dates sync owns this
|
||||||
|
// calendar, rather than hidden: the button is where you
|
||||||
|
// expect it, disabled, with the card below saying why —
|
||||||
|
// and it comes back to life the moment the feature is
|
||||||
|
// off, when the delete would actually stick.
|
||||||
|
IconButton(
|
||||||
|
onClick = { confirmDelete = true },
|
||||||
|
enabled = !deleteLocked,
|
||||||
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Delete,
|
Icons.Default.Delete,
|
||||||
contentDescription = stringResource(R.string.event_detail_delete),
|
contentDescription = stringResource(R.string.event_detail_delete),
|
||||||
tint = MaterialTheme.colorScheme.error,
|
tint = if (deleteLocked) {
|
||||||
|
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colorScheme.error
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -626,6 +661,19 @@ private fun CalendarEditor(
|
|||||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
) {
|
) {
|
||||||
|
if (deleteLocked) {
|
||||||
|
EditorCard(
|
||||||
|
icon = Icons.Default.Info,
|
||||||
|
iconTint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
iconAtTop = true,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.calendars_managed_delete_locked),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
EditorCard(icon = Icons.Default.CalendarMonth, iconTint = eventFill(color, dark, soften)) {
|
EditorCard(icon = Icons.Default.CalendarMonth, iconTint = eventFill(color, dark, soften)) {
|
||||||
InlineTextField(
|
InlineTextField(
|
||||||
value = name,
|
value = name,
|
||||||
@@ -698,10 +746,33 @@ private fun CalendarEditor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The per-row enable/disable control. Checked = the calendar is shown in the
|
* The row's supporting line: the states that make this calendar behave unlike a
|
||||||
* app; unchecking disables it (events, filters and pickers all drop it) without
|
* plain writable one (#76), then its own description. Text rather than badges —
|
||||||
* touching any provider data. Carries its own content description so the toggle
|
* a row can carry several of these at once next to a switch, which is exactly
|
||||||
* is self-describing to screen readers even on a dimmed row.
|
* what M3 supporting text composes and a row of static chips doesn't.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun calendarRowSummary(calendar: CalendarSource): String? {
|
||||||
|
val states = calendar.stateLabels().map { label ->
|
||||||
|
stringResource(
|
||||||
|
when (label) {
|
||||||
|
CalendarStateLabel.MANAGED -> R.string.calendars_state_managed
|
||||||
|
CalendarStateLabel.READ_ONLY -> R.string.calendars_state_read_only
|
||||||
|
CalendarStateLabel.NOT_SYNCED -> R.string.calendars_state_not_synced
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val parts = states + listOfNotNull(calendar.description?.takeIf { it.isNotBlank() })
|
||||||
|
return parts.joinToString(" · ").ifEmpty { null }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The per-row on/off control, writing the system's `Calendars.VISIBLE`: checked
|
||||||
|
* = the calendar is shown, unchecked = it drops out of every surface (events,
|
||||||
|
* filters, pickers) and the provider stops scheduling its reminders. The flag is
|
||||||
|
* device-local — nothing is deleted and nothing is synced anywhere. Carries its
|
||||||
|
* own content description so the toggle is self-describing to screen readers
|
||||||
|
* even on a dimmed row.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun EnableSwitch(
|
private fun EnableSwitch(
|
||||||
@@ -709,7 +780,7 @@ private fun EnableSwitch(
|
|||||||
enabled: Boolean,
|
enabled: Boolean,
|
||||||
onToggle: (Boolean) -> Unit,
|
onToggle: (Boolean) -> Unit,
|
||||||
) {
|
) {
|
||||||
val label = stringResource(R.string.calendars_show_in_app_a11y, calendarName)
|
val label = stringResource(R.string.calendars_visibility_a11y, calendarName)
|
||||||
Switch(
|
Switch(
|
||||||
checked = enabled,
|
checked = enabled,
|
||||||
onCheckedChange = onToggle,
|
onCheckedChange = onToggle,
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository
|
|||||||
import de.jeanlucmakiola.calendula.data.di.IoDispatcher
|
import de.jeanlucmakiola.calendula.data.di.IoDispatcher
|
||||||
import de.jeanlucmakiola.calendula.data.ics.IcsExporter
|
import de.jeanlucmakiola.calendula.data.ics.IcsExporter
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.BackupStatus
|
import de.jeanlucmakiola.calendula.data.prefs.BackupStatus
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||||
import de.jeanlucmakiola.calendula.data.reminders.ReminderNotifier
|
import de.jeanlucmakiola.calendula.data.reminders.ReminderRecovery
|
||||||
import de.jeanlucmakiola.calendula.data.reminders.SuppressedReminderStore
|
|
||||||
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
||||||
import de.jeanlucmakiola.calendula.domain.ics.IcsWriter
|
import de.jeanlucmakiola.calendula.domain.ics.IcsWriter
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -45,10 +43,8 @@ class CalendarsViewModel @Inject constructor(
|
|||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val repository: CalendarRepository,
|
private val repository: CalendarRepository,
|
||||||
private val icsExporter: IcsExporter,
|
private val icsExporter: IcsExporter,
|
||||||
private val prefs: CalendarPrefs,
|
|
||||||
private val settingsPrefs: SettingsPrefs,
|
private val settingsPrefs: SettingsPrefs,
|
||||||
private val suppressedStore: SuppressedReminderStore,
|
private val reminderRecovery: ReminderRecovery,
|
||||||
private val notifier: ReminderNotifier,
|
|
||||||
@IoDispatcher private val io: CoroutineDispatcher,
|
@IoDispatcher private val io: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
@@ -62,20 +58,6 @@ class CalendarsViewModel @Inject constructor(
|
|||||||
initialValue = emptyList(),
|
initialValue = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* Calendars the user has disabled in the app. This screen is the only
|
|
||||||
* surface that lists them, so it both reads the set (to dim the rows) and
|
|
||||||
* toggles it. Every other surface simply excludes these ids.
|
|
||||||
*/
|
|
||||||
val disabledCalendarIds: StateFlow<Set<Long>> =
|
|
||||||
prefs.disabledCalendarIds
|
|
||||||
.flowOn(io)
|
|
||||||
.stateIn(
|
|
||||||
scope = viewModelScope,
|
|
||||||
started = SharingStarted.WhileSubscribed(5_000L),
|
|
||||||
initialValue = emptySet(),
|
|
||||||
)
|
|
||||||
|
|
||||||
/** Automatic-backup settings + last-run status, for the Backup section UI. */
|
/** Automatic-backup settings + last-run status, for the Backup section UI. */
|
||||||
val autoBackup: StateFlow<AutoBackupUiState> = combine(
|
val autoBackup: StateFlow<AutoBackupUiState> = combine(
|
||||||
settingsPrefs.autoBackupEnabled,
|
settingsPrefs.autoBackupEnabled,
|
||||||
@@ -92,6 +74,33 @@ class CalendarsViewModel @Inject constructor(
|
|||||||
initialValue = AutoBackupUiState(),
|
initialValue = AutoBackupUiState(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Managed special-dates calendars whose deletion would not stick. While the
|
||||||
|
* feature is on, the sync owns every mirror: it recreates a missing one for
|
||||||
|
* an enabled type on the next pass and deletes the leftover of a disabled
|
||||||
|
* one (`SpecialDatesSyncEngine.reconcileCalendars`), so either way the
|
||||||
|
* delete would appear to work and then undo itself. Turning special dates
|
||||||
|
* off empties this set, and deleting a leftover mirror is a real delete from
|
||||||
|
* then on.
|
||||||
|
*
|
||||||
|
* Read off each calendar's own durable marker ([CalendarSource.isManaged],
|
||||||
|
* the `CAL_SYNC2` one the editor lock already trusts) rather than the stored
|
||||||
|
* ids, which are only rewritten on the next sync pass — a preferences loss
|
||||||
|
* would otherwise unlock a live mirror until then.
|
||||||
|
*/
|
||||||
|
val deleteLockedCalendarIds: StateFlow<Set<Long>> = combine(
|
||||||
|
calendars,
|
||||||
|
settingsPrefs.specialDatesEnabled,
|
||||||
|
) { sources, enabled ->
|
||||||
|
if (!enabled) emptySet() else sources.filter { it.isManaged }.map { it.id }.toSet()
|
||||||
|
}
|
||||||
|
.flowOn(io)
|
||||||
|
.stateIn(
|
||||||
|
scope = viewModelScope,
|
||||||
|
started = SharingStarted.WhileSubscribed(5_000L),
|
||||||
|
initialValue = emptySet(),
|
||||||
|
)
|
||||||
|
|
||||||
private val _error = MutableStateFlow(false)
|
private val _error = MutableStateFlow(false)
|
||||||
val error: StateFlow<Boolean> = _error.asStateFlow()
|
val error: StateFlow<Boolean> = _error.asStateFlow()
|
||||||
|
|
||||||
@@ -140,54 +149,30 @@ class CalendarsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable or disable a calendar app-side. Disabling removes it from every
|
* Switch a calendar on or off. This is the app's one visibility model: it
|
||||||
* surface but Settings → Calendars (and hides its events) without touching
|
* writes the system's `Calendars.VISIBLE`, so the calendar disappears from
|
||||||
* provider data — purely a reversible Calendula-local view choice.
|
* every surface *and* the provider stops (or resumes) scheduling its
|
||||||
|
* reminders. Nothing is patched by hand — the provider notifies and the
|
||||||
|
* observer re-queries.
|
||||||
|
*
|
||||||
|
* Switching one back on also re-posts the reminders it silenced while it was
|
||||||
|
* off and that are still relevant — those the app kept app-side because it
|
||||||
|
* may not write the flag ([ReminderRecovery]).
|
||||||
*/
|
*/
|
||||||
fun setDisabled(id: Long, disabled: Boolean) {
|
fun setCalendarVisible(id: Long, visible: Boolean) = write {
|
||||||
viewModelScope.launch {
|
repository.setCalendarsVisible(listOf(id), visible)
|
||||||
val current = prefs.disabledCalendarIds.first()
|
if (visible) reminderRecovery.rePostFor(listOf(id))
|
||||||
val next = if (disabled) current + id else current - id
|
|
||||||
if (next != current) {
|
|
||||||
prefs.setDisabledCalendarIds(next)
|
|
||||||
if (!disabled) recoverReminders(setOf(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable or disable every calendar of one account in a single write — the
|
* Switch every calendar of one account on or off — the "toggle all"
|
||||||
* "toggle all" affordance on an account header. Done as one set update so the
|
* affordance on an account header. Each row is written on its own (the
|
||||||
* per-calendar [setDisabled] calls can't race each other.
|
* provider only re-arms reminder alarms for a single-id update), in one
|
||||||
|
* coroutine so the writes can't race each other.
|
||||||
*/
|
*/
|
||||||
fun setAccountDisabled(ids: Collection<Long>, disabled: Boolean) {
|
fun setAccountVisible(ids: Collection<Long>, visible: Boolean) = write {
|
||||||
viewModelScope.launch {
|
repository.setCalendarsVisible(ids, visible)
|
||||||
val current = prefs.disabledCalendarIds.first()
|
if (visible) reminderRecovery.rePostFor(ids)
|
||||||
val next = if (disabled) current + ids else current - ids.toSet()
|
|
||||||
if (next != current) {
|
|
||||||
prefs.setDisabledCalendarIds(next)
|
|
||||||
if (!disabled) recoverReminders(current intersect ids.toSet())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Re-post the reminders that fired while [reEnabledIds] were disabled and are
|
|
||||||
* still relevant (event not yet over), then drop them from the stash. Runs
|
|
||||||
* after the disabled set is written, so the notifier's own disabled gate lets
|
|
||||||
* them through. Best-effort at re-enable time: it mirrors the receiver gates
|
|
||||||
* (reminders on + postable), and there is no later re-scan, so alerts left
|
|
||||||
* unposted because those gates are closed are simply released.
|
|
||||||
*/
|
|
||||||
private suspend fun recoverReminders(reEnabledIds: Set<Long>) {
|
|
||||||
if (reEnabledIds.isEmpty()) return
|
|
||||||
val recovered = suppressedStore.recoverFor(reEnabledIds, System.currentTimeMillis())
|
|
||||||
if (recovered.isNotEmpty() &&
|
|
||||||
settingsPrefs.remindersEnabled.first() &&
|
|
||||||
notifier.canPost()
|
|
||||||
) {
|
|
||||||
recovered.forEach { notifier.post(it) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Automatic backup (issue #8) ------------------------------------
|
// --- Automatic backup (issue #8) ------------------------------------
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import androidx.compose.foundation.layout.height
|
|||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||||
import androidx.compose.material.icons.filled.Cloud
|
import androidx.compose.material.icons.filled.Cloud
|
||||||
import androidx.compose.material.icons.filled.PhoneAndroid
|
import androidx.compose.material.icons.filled.PhoneAndroid
|
||||||
|
import androidx.compose.material.icons.filled.VisibilityOff
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -42,12 +44,19 @@ import de.jeanlucmakiola.floret.components.SelectedCheck
|
|||||||
* account — with the calendars beneath it as a connected card, a colour chip on
|
* account — with the calendars beneath it as a connected card, a colour chip on
|
||||||
* each and a check on the selected one. Emits into the caller's [ColumnScope]
|
* each and a check on the selected one. Emits into the caller's [ColumnScope]
|
||||||
* (a scrolling column), so the caller owns the surrounding chrome.
|
* (a scrolling column), so the caller owns the surrounding chrome.
|
||||||
|
*
|
||||||
|
* The list holds event *targets* only, so a calendar that is switched off,
|
||||||
|
* read-only or managed is silently absent — which reads as a missing calendar
|
||||||
|
* rather than an excluded one (#76). [onManageCalendars], when given, adds the
|
||||||
|
* footer row that names the possible reasons and opens the calendar manager,
|
||||||
|
* where each row then says which one applies.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun ColumnScope.CalendarPickerGroups(
|
fun ColumnScope.CalendarPickerGroups(
|
||||||
calendars: List<CalendarSource>,
|
calendars: List<CalendarSource>,
|
||||||
selectedId: Long?,
|
selectedId: Long?,
|
||||||
onSelect: (Long) -> Unit,
|
onSelect: (Long) -> Unit,
|
||||||
|
onManageCalendars: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
val local = remember(calendars) { calendars.filter { it.isLocal } }
|
val local = remember(calendars) { calendars.filter { it.isLocal } }
|
||||||
val syncedGroups = remember(calendars) {
|
val syncedGroups = remember(calendars) {
|
||||||
@@ -75,6 +84,23 @@ fun ColumnScope.CalendarPickerGroups(
|
|||||||
onSelect = onSelect,
|
onSelect = onSelect,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (onManageCalendars != null) {
|
||||||
|
Spacer(Modifier.height(16.dp))
|
||||||
|
GroupedRow(
|
||||||
|
title = stringResource(R.string.calendar_picker_missing_title),
|
||||||
|
summary = stringResource(R.string.calendar_picker_missing_summary),
|
||||||
|
position = Position.Alone,
|
||||||
|
leading = { LeadingAvatar(Icons.Default.VisibilityOff) },
|
||||||
|
trailing = {
|
||||||
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = onManageCalendars,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One account's category header (avatar + name) atop its selectable calendars. */
|
/** One account's category header (avatar + name) atop its selectable calendars. */
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ import androidx.compose.ui.graphics.isSpecified
|
|||||||
import androidx.compose.ui.graphics.Shape
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.pluralStringResource
|
import androidx.compose.ui.res.pluralStringResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
@@ -193,6 +195,7 @@ fun EventEditScreen(
|
|||||||
initialStartMinutes: Int? = null,
|
initialStartMinutes: Int? = null,
|
||||||
initialForm: EventForm? = null,
|
initialForm: EventForm? = null,
|
||||||
initialFormSource: ImportSource = ImportSource.File,
|
initialFormSource: ImportSource = ImportSource.File,
|
||||||
|
onManageCalendars: (() -> Unit)? = null,
|
||||||
viewModel: EventEditViewModel = hiltViewModel(),
|
viewModel: EventEditViewModel = hiltViewModel(),
|
||||||
) {
|
) {
|
||||||
LaunchedEffect(initialDateIso, editKey, initialForm) {
|
LaunchedEffect(initialDateIso, editKey, initialForm) {
|
||||||
@@ -309,6 +312,7 @@ fun EventEditScreen(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(innerPadding),
|
.padding(innerPadding),
|
||||||
|
onManageCalendars = onManageCalendars,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,6 +504,7 @@ private fun EventEditContent(
|
|||||||
state: EventEditUiState,
|
state: EventEditUiState,
|
||||||
viewModel: EventEditViewModel,
|
viewModel: EventEditViewModel,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
onManageCalendars: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
val form = state.form
|
val form = state.form
|
||||||
val locale = currentLocale()
|
val locale = currentLocale()
|
||||||
@@ -509,6 +514,10 @@ private fun EventEditContent(
|
|||||||
// they're locked here; everything else (reminders, location, notes) is the
|
// they're locked here; everything else (reminders, location, notes) is the
|
||||||
// user's to edit.
|
// user's to edit.
|
||||||
val locked = state.isManaged
|
val locked = state.isManaged
|
||||||
|
// Read in the form's own window, not the picker's: the field holding focus
|
||||||
|
// lives here, so this is the controller that can put its keyboard away.
|
||||||
|
val focusManager = LocalFocusManager.current
|
||||||
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
var picker by remember { mutableStateOf<PickerTarget?>(null) }
|
var picker by remember { mutableStateOf<PickerTarget?>(null) }
|
||||||
var showCalendarPicker by rememberSaveable { mutableStateOf(false) }
|
var showCalendarPicker by rememberSaveable { mutableStateOf(false) }
|
||||||
var showReminderPicker by rememberSaveable { mutableStateOf(false) }
|
var showReminderPicker by rememberSaveable { mutableStateOf(false) }
|
||||||
@@ -1114,6 +1123,17 @@ private fun EventEditContent(
|
|||||||
null -> Unit
|
null -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A full-screen picker over the form is a change of place, so the form's
|
||||||
|
// keyboard has no business following it there — least of all onto the
|
||||||
|
// calendar manager, which the picker can hand off to. The form's own field
|
||||||
|
// keeps its text; only focus and the IME go.
|
||||||
|
LaunchedEffect(showCalendarPicker) {
|
||||||
|
if (showCalendarPicker) {
|
||||||
|
focusManager.clearFocus(force = true)
|
||||||
|
keyboardController?.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (showCalendarPicker) {
|
if (showCalendarPicker) {
|
||||||
CalendarPicker(
|
CalendarPicker(
|
||||||
calendars = state.calendars,
|
calendars = state.calendars,
|
||||||
@@ -1122,6 +1142,17 @@ private fun EventEditContent(
|
|||||||
viewModel.setCalendar(it)
|
viewModel.setCalendar(it)
|
||||||
showCalendarPicker = false
|
showCalendarPicker = false
|
||||||
},
|
},
|
||||||
|
// Close the picker on the way out. It is a Compose Dialog — its own
|
||||||
|
// window, always above the activity's content — so the manager would
|
||||||
|
// otherwise open behind it and the tap would look dead. The form
|
||||||
|
// stays standing underneath, its calendar row one tap from a picker
|
||||||
|
// that re-queries on open.
|
||||||
|
onManageCalendars = onManageCalendars?.let { openManager ->
|
||||||
|
{
|
||||||
|
showCalendarPicker = false
|
||||||
|
openManager()
|
||||||
|
}
|
||||||
|
},
|
||||||
onDismiss = { showCalendarPicker = false },
|
onDismiss = { showCalendarPicker = false },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2277,6 +2308,7 @@ private fun CalendarPicker(
|
|||||||
selectedId: Long?,
|
selectedId: Long?,
|
||||||
onSelect: (Long) -> Unit,
|
onSelect: (Long) -> Unit,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
|
onManageCalendars: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
FullScreenPicker(
|
FullScreenPicker(
|
||||||
title = stringResource(R.string.event_detail_calendar),
|
title = stringResource(R.string.event_detail_calendar),
|
||||||
@@ -2286,6 +2318,7 @@ private fun CalendarPicker(
|
|||||||
calendars = calendars,
|
calendars = calendars,
|
||||||
selectedId = selectedId,
|
selectedId = selectedId,
|
||||||
onSelect = onSelect,
|
onSelect = onSelect,
|
||||||
|
onManageCalendars = onManageCalendars,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import de.jeanlucmakiola.calendula.domain.EventColorOption
|
|||||||
import de.jeanlucmakiola.calendula.domain.EventForm
|
import de.jeanlucmakiola.calendula.domain.EventForm
|
||||||
import de.jeanlucmakiola.calendula.domain.EventFormField
|
import de.jeanlucmakiola.calendula.domain.EventFormField
|
||||||
import de.jeanlucmakiola.calendula.domain.RecurringWriteScope
|
import de.jeanlucmakiola.calendula.domain.RecurringWriteScope
|
||||||
|
import de.jeanlucmakiola.calendula.domain.isEventTarget
|
||||||
import de.jeanlucmakiola.calendula.domain.populatedFields
|
import de.jeanlucmakiola.calendula.domain.populatedFields
|
||||||
import de.jeanlucmakiola.calendula.domain.problems
|
import de.jeanlucmakiola.calendula.domain.problems
|
||||||
import de.jeanlucmakiola.calendula.domain.toEditSnapshot
|
import de.jeanlucmakiola.calendula.domain.toEditSnapshot
|
||||||
@@ -177,18 +178,16 @@ class EventEditViewModel @Inject constructor(
|
|||||||
repository.calendars().catch { emit(emptyList()) }
|
repository.calendars().catch { emit(emptyList()) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writable calendars — the only valid event targets. Disabled calendars are
|
* The calendars a new event can be saved to ([isEventTarget]): writable,
|
||||||
* excluded, so you can't create into a calendar you've removed from the app;
|
* switched on, not a contact-filled mirror, not a non-syncing subscription.
|
||||||
* a last-used preselect landing on a now-disabled calendar falls back to the
|
* A last-used preselect landing on an excluded calendar falls back to the
|
||||||
* first remaining writable one (handled by [resolvedCalendarId] and [state]).
|
* first remaining one (handled by [resolvedCalendarId] and [state]).
|
||||||
* Managed special-dates calendars are excluded too: their events are owned by
|
*
|
||||||
* the contact sync, which would delete any user event created there.
|
* This is the list of *targets*. An event already living in an excluded
|
||||||
|
* calendar keeps it — [state] adds it back to the picker.
|
||||||
*/
|
*/
|
||||||
private val writableCalendars: Flow<List<CalendarSource>> = combine(
|
private val writableCalendars: Flow<List<CalendarSource>> = allCalendars.map { calendars ->
|
||||||
allCalendars,
|
calendars.filter { it.isEventTarget }
|
||||||
prefs.disabledCalendarIds,
|
|
||||||
) { calendars, disabled ->
|
|
||||||
calendars.filter { it.canModifyContents && it.id !in disabled && !it.isManaged }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The target calendar id, resolved exactly as the form shows it. */
|
/** The target calendar id, resolved exactly as the form shows it. */
|
||||||
@@ -234,11 +233,16 @@ class EventEditViewModel @Inject constructor(
|
|||||||
// off the calendar's durable marker, not a stored id, so it holds after a
|
// off the calendar's durable marker, not a stored id, so it holds after a
|
||||||
// backup restore too.
|
// backup restore too.
|
||||||
val isManaged = local.editTarget != null && resolvedCalendar?.isManaged == true
|
val isManaged = local.editTarget != null && resolvedCalendar?.isManaged == true
|
||||||
// The picker offers writable calendars only; when editing a managed event
|
// The picker offers writable calendars only; the event's own calendar is
|
||||||
// its own (excluded) calendar is added back so the row still names it.
|
// added back whenever it isn't among them — a managed special-dates one,
|
||||||
|
// or one switched off on this device — so the row keeps naming it instead
|
||||||
|
// of reading as the "no calendar" error, and saving can leave the event
|
||||||
|
// where it is. A calendar the app may not write to is still no target.
|
||||||
|
val ownCalendar = resolvedCalendar?.takeIf { own ->
|
||||||
|
own.canModifyContents && external.writable.none { it.id == own.id }
|
||||||
|
}
|
||||||
val pickerCalendars =
|
val pickerCalendars =
|
||||||
if (isManaged && resolvedCalendar != null) external.writable + resolvedCalendar
|
if (ownCalendar != null) external.writable + ownCalendar else external.writable
|
||||||
else external.writable
|
|
||||||
// An all-day event is date-anchored, so a zone is meaningless on it —
|
// An all-day event is date-anchored, so a zone is meaningless on it —
|
||||||
// the field is withheld from both lists rather than shown as a no-op.
|
// the field is withheld from both lists rather than shown as a no-op.
|
||||||
val offerableFields = EventFormField.entries.toSet() -
|
val offerableFields = EventFormField.entries.toSet() -
|
||||||
|
|||||||
@@ -30,12 +30,11 @@ class FilterViewModel @Inject constructor(
|
|||||||
combine(
|
combine(
|
||||||
repository.calendars(),
|
repository.calendars(),
|
||||||
prefs.hiddenCalendarIds,
|
prefs.hiddenCalendarIds,
|
||||||
prefs.disabledCalendarIds,
|
) { calendars, hidden ->
|
||||||
) { calendars, hidden, disabled ->
|
// Calendars switched off in Settings → Calendars are off device-wide
|
||||||
// Disabled calendars are gone from the app entirely — they don't
|
// and don't belong in the drawer's hide/show list (you can't hide
|
||||||
// belong in the drawer's hide/show list (you can't hide what's
|
// what is already off). They live only in Settings → Calendars.
|
||||||
// already disabled). They live only in Settings → Calendars.
|
val enabled = calendars.filter { it.isVisibleInSystem }
|
||||||
val enabled = calendars.filterNot { it.id in disabled }
|
|
||||||
if (enabled.isEmpty()) {
|
if (enabled.isEmpty()) {
|
||||||
FilterUiState.Failure(FailureReason.NoCalendarsConfigured)
|
FilterUiState.Failure(FailureReason.NoCalendarsConfigured)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ fun ImportScreen(
|
|||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
onOpenSingle: (EventForm) -> Unit,
|
onOpenSingle: (EventForm) -> Unit,
|
||||||
forceMany: Boolean = false,
|
forceMany: Boolean = false,
|
||||||
|
onManageCalendars: (() -> Unit)? = null,
|
||||||
// Key the VM by the file uri. This screen has no nav backstack, so an
|
// Key the VM by the file uri. This screen has no nav backstack, so an
|
||||||
// unkeyed hiltViewModel() resolves to the Activity's store and is retained
|
// unkeyed hiltViewModel() resolves to the Activity's store and is retained
|
||||||
// across imports — its one-shot `load` guard would then show the *previous*
|
// across imports — its one-shot `load` guard would then show the *previous*
|
||||||
@@ -155,7 +156,12 @@ fun ImportScreen(
|
|||||||
|
|
||||||
ImportUiState.Empty -> CenteredMessage(stringResource(R.string.import_empty), onClose)
|
ImportUiState.Empty -> CenteredMessage(stringResource(R.string.import_empty), onClose)
|
||||||
ImportUiState.Failed -> CenteredMessage(stringResource(R.string.import_failed), onClose)
|
ImportUiState.Failed -> CenteredMessage(stringResource(R.string.import_failed), onClose)
|
||||||
is ImportUiState.Many -> ManyContent(s, selected, onSelect = { selected = it })
|
is ImportUiState.Many -> ManyContent(
|
||||||
|
state = s,
|
||||||
|
selected = selected,
|
||||||
|
onSelect = { selected = it },
|
||||||
|
onManageCalendars = onManageCalendars,
|
||||||
|
)
|
||||||
is ImportUiState.Done -> DoneContent(s, onClose)
|
is ImportUiState.Done -> DoneContent(s, onClose)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,10 +169,24 @@ fun ImportScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ManyContent(state: ImportUiState.Many, selected: Long?, onSelect: (Long) -> Unit) {
|
private fun ManyContent(
|
||||||
// No writable calendar to import into — tell the user honestly.
|
state: ImportUiState.Many,
|
||||||
|
selected: Long?,
|
||||||
|
onSelect: (Long) -> Unit,
|
||||||
|
onManageCalendars: (() -> Unit)? = null,
|
||||||
|
) {
|
||||||
|
// No calendar to import into — tell the user honestly, and carry the same
|
||||||
|
// way out the picker's footer offers below. This is the state that footer
|
||||||
|
// exists for: every writable calendar being switched off, read-only or
|
||||||
|
// contact-filled is exactly what empties this list (#76).
|
||||||
if (state.calendars.isEmpty()) {
|
if (state.calendars.isEmpty()) {
|
||||||
CenteredMessage(stringResource(R.string.import_no_calendar), onClose = null)
|
CenteredMessage(
|
||||||
|
message = stringResource(R.string.import_no_calendar),
|
||||||
|
onClose = null,
|
||||||
|
actionLabel = stringResource(R.string.settings_manage_calendars)
|
||||||
|
.takeIf { onManageCalendars != null },
|
||||||
|
onAction = onManageCalendars,
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +198,7 @@ private fun ManyContent(state: ImportUiState.Many, selected: Long?, onSelect: (L
|
|||||||
calendars = state.calendars,
|
calendars = state.calendars,
|
||||||
selectedId = selected,
|
selectedId = selected,
|
||||||
onSelect = onSelect,
|
onSelect = onSelect,
|
||||||
|
onManageCalendars = onManageCalendars,
|
||||||
)
|
)
|
||||||
if (state.warnings.isNotEmpty()) {
|
if (state.warnings.isNotEmpty()) {
|
||||||
Column(
|
Column(
|
||||||
@@ -333,7 +354,12 @@ private fun WarningText(warning: IcsParseWarning) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun CenteredMessage(message: String, onClose: (() -> Unit)?) {
|
private fun CenteredMessage(
|
||||||
|
message: String,
|
||||||
|
onClose: (() -> Unit)?,
|
||||||
|
actionLabel: String? = null,
|
||||||
|
onAction: (() -> Unit)? = null,
|
||||||
|
) {
|
||||||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
Column(
|
Column(
|
||||||
Modifier.padding(24.dp),
|
Modifier.padding(24.dp),
|
||||||
@@ -344,6 +370,9 @@ private fun CenteredMessage(message: String, onClose: (() -> Unit)?) {
|
|||||||
if (onClose != null) {
|
if (onClose != null) {
|
||||||
Button(onClick = onClose) { Text(stringResource(R.string.import_close)) }
|
Button(onClick = onClose) { Text(stringResource(R.string.import_close)) }
|
||||||
}
|
}
|
||||||
|
if (actionLabel != null && onAction != null) {
|
||||||
|
Button(onClick = onAction) { Text(actionLabel) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
|||||||
import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository
|
import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository
|
||||||
import de.jeanlucmakiola.calendula.data.di.IoDispatcher
|
import de.jeanlucmakiola.calendula.data.di.IoDispatcher
|
||||||
import de.jeanlucmakiola.calendula.data.ics.IcsImporter
|
import de.jeanlucmakiola.calendula.data.ics.IcsImporter
|
||||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
|
||||||
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
||||||
import de.jeanlucmakiola.calendula.domain.EventForm
|
import de.jeanlucmakiola.calendula.domain.EventForm
|
||||||
import de.jeanlucmakiola.calendula.domain.ics.IcsImportSummary
|
import de.jeanlucmakiola.calendula.domain.ics.IcsImportSummary
|
||||||
@@ -15,6 +14,7 @@ import de.jeanlucmakiola.calendula.domain.ics.IcsParseWarning
|
|||||||
import de.jeanlucmakiola.calendula.domain.ics.IcsParser
|
import de.jeanlucmakiola.calendula.domain.ics.IcsParser
|
||||||
import de.jeanlucmakiola.calendula.domain.ics.ParsedIcsEvent
|
import de.jeanlucmakiola.calendula.domain.ics.ParsedIcsEvent
|
||||||
import de.jeanlucmakiola.calendula.domain.ics.toEventForm
|
import de.jeanlucmakiola.calendula.domain.ics.toEventForm
|
||||||
|
import de.jeanlucmakiola.calendula.domain.isEventTarget
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -57,7 +57,6 @@ sealed interface ImportUiState {
|
|||||||
class ImportViewModel @Inject constructor(
|
class ImportViewModel @Inject constructor(
|
||||||
private val repository: CalendarRepository,
|
private val repository: CalendarRepository,
|
||||||
private val importer: IcsImporter,
|
private val importer: IcsImporter,
|
||||||
private val prefs: CalendarPrefs,
|
|
||||||
@IoDispatcher private val io: CoroutineDispatcher,
|
@IoDispatcher private val io: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
@@ -87,16 +86,14 @@ class ImportViewModel @Inject constructor(
|
|||||||
warnings = parsed.warnings,
|
warnings = parsed.warnings,
|
||||||
)
|
)
|
||||||
else -> {
|
else -> {
|
||||||
// A disabled calendar is removed from the app, so it can't be
|
// The same targets the event form offers ([isEventTarget]):
|
||||||
// an import target — exclude it alongside the read-only ones.
|
// an import is a bulk create, so a calendar that can't hold
|
||||||
// Managed special-dates calendars are contact-derived and
|
// one event can't hold thirty.
|
||||||
// editor-locked, so they're not a valid destination either.
|
|
||||||
val disabled = prefs.disabledCalendarIds.first()
|
|
||||||
ImportUiState.Many(
|
ImportUiState.Many(
|
||||||
events = parsed.events,
|
events = parsed.events,
|
||||||
warnings = parsed.warnings,
|
warnings = parsed.warnings,
|
||||||
calendars = repository.calendars().first()
|
calendars = repository.calendars().first()
|
||||||
.filter { it.canModifyContents && !it.isManaged && it.id !in disabled },
|
.filter { it.isEventTarget },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class PermissionViewModel @Inject constructor() : ViewModel() {
|
|||||||
private val _state = MutableStateFlow<PermissionUiState>(PermissionUiState.Rationale)
|
private val _state = MutableStateFlow<PermissionUiState>(PermissionUiState.Rationale)
|
||||||
val state: StateFlow<PermissionUiState> = _state.asStateFlow()
|
val state: StateFlow<PermissionUiState> = _state.asStateFlow()
|
||||||
|
|
||||||
|
// The visibility reconcile a grant owes (#75) hangs off RootScreen showing
|
||||||
|
// the app instead: it has to cover the grants made outside it too.
|
||||||
fun onGranted() {
|
fun onGranted() {
|
||||||
_state.value = PermissionUiState.Granted
|
_state.value = PermissionUiState.Granted
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,9 +57,12 @@ import de.jeanlucmakiola.floret.components.Position
|
|||||||
import de.jeanlucmakiola.floret.locale.currentLocale
|
import de.jeanlucmakiola.floret.locale.currentLocale
|
||||||
import de.jeanlucmakiola.calendula.ui.common.LocalSoftenColors
|
import de.jeanlucmakiola.calendula.ui.common.LocalSoftenColors
|
||||||
import de.jeanlucmakiola.calendula.ui.common.eventFill
|
import de.jeanlucmakiola.calendula.ui.common.eventFill
|
||||||
|
import de.jeanlucmakiola.calendula.domain.spanFirstDay
|
||||||
import de.jeanlucmakiola.calendula.ui.common.LocalUse24HourFormat
|
import de.jeanlucmakiola.calendula.ui.common.LocalUse24HourFormat
|
||||||
import de.jeanlucmakiola.calendula.ui.common.timeOfDayFormatter
|
import de.jeanlucmakiola.calendula.ui.common.timeOfDayFormatter
|
||||||
import de.jeanlucmakiola.floret.components.positionOf
|
import de.jeanlucmakiola.floret.components.positionOf
|
||||||
|
import kotlinx.datetime.TimeZone
|
||||||
|
import kotlinx.datetime.toJavaLocalDate
|
||||||
import java.time.Instant as JavaInstant
|
import java.time.Instant as JavaInstant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
@@ -220,9 +223,14 @@ private fun searchSummary(event: EventInstance): String {
|
|||||||
val start = remember(event.start, zone) {
|
val start = remember(event.start, zone) {
|
||||||
JavaInstant.ofEpochMilli(event.start.toEpochMilliseconds()).atZone(zone)
|
JavaInstant.ofEpochMilli(event.start.toEpochMilliseconds()).atZone(zone)
|
||||||
}
|
}
|
||||||
val dateText = remember(locale) {
|
// The date comes from the shared span rule, not from [start]: an all-day
|
||||||
|
// event sits at UTC midnight, so reading its date in the device zone names
|
||||||
|
// the day before west of UTC (#82). The clock time below stays in the device
|
||||||
|
// zone — it is only ever rendered for timed events.
|
||||||
|
val dateText = remember(event.start, event.end, event.isAllDay, locale) {
|
||||||
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(locale)
|
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(locale)
|
||||||
}.format(start)
|
.format(event.spanFirstDay(TimeZone.currentSystemDefault()).toJavaLocalDate())
|
||||||
|
}
|
||||||
val use24Hour = LocalUse24HourFormat.current
|
val use24Hour = LocalUse24HourFormat.current
|
||||||
val timeText = if (event.isAllDay) {
|
val timeText = if (event.isAllDay) {
|
||||||
stringResource(R.string.event_detail_all_day)
|
stringResource(R.string.event_detail_all_day)
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import androidx.compose.material.icons.filled.Keyboard
|
|||||||
import androidx.compose.material.icons.filled.Language
|
import androidx.compose.material.icons.filled.Language
|
||||||
import androidx.compose.material.icons.filled.Notifications
|
import androidx.compose.material.icons.filled.Notifications
|
||||||
import androidx.compose.material.icons.filled.Palette
|
import androidx.compose.material.icons.filled.Palette
|
||||||
|
import androidx.compose.material.icons.filled.PrivacyTip
|
||||||
import androidx.compose.material.icons.filled.Translate
|
import androidx.compose.material.icons.filled.Translate
|
||||||
import androidx.compose.material.icons.filled.Tune
|
import androidx.compose.material.icons.filled.Tune
|
||||||
import androidx.compose.material.icons.filled.UploadFile
|
import androidx.compose.material.icons.filled.UploadFile
|
||||||
@@ -408,7 +409,9 @@ private fun LanguageRow(position: Position) {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun AboutCard() {
|
private fun AboutCard() {
|
||||||
// The card layout lives in floret-kit (components.AboutCard); Calendula
|
// The card layout lives in floret-kit (components.AboutCard); Calendula
|
||||||
// supplies its own logo, author and the source / licence / support links.
|
// supplies its own logo, author and the source / licence / privacy / support
|
||||||
|
// links. The privacy policy has to be reachable from inside the app, not just
|
||||||
|
// from the store listing, because Calendula touches calendar and contact data.
|
||||||
AboutCard(
|
AboutCard(
|
||||||
logo = { AppLogo() },
|
logo = { AppLogo() },
|
||||||
appName = stringResource(R.string.app_name),
|
appName = stringResource(R.string.app_name),
|
||||||
@@ -424,6 +427,11 @@ private fun AboutCard() {
|
|||||||
label = stringResource(R.string.settings_license),
|
label = stringResource(R.string.settings_license),
|
||||||
url = stringResource(R.string.about_license_url),
|
url = stringResource(R.string.about_license_url),
|
||||||
),
|
),
|
||||||
|
AboutLink(
|
||||||
|
icon = Icons.Default.PrivacyTip,
|
||||||
|
label = stringResource(R.string.settings_about_privacy),
|
||||||
|
url = stringResource(R.string.about_privacy_url),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
highlightLink = AboutLink(
|
highlightLink = AboutLink(
|
||||||
icon = Icons.Default.Favorite,
|
icon = Icons.Default.Favorite,
|
||||||
|
|||||||
@@ -74,9 +74,14 @@ class SettingsViewModel @Inject constructor(
|
|||||||
|
|
||||||
private val dynamicColorAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
private val dynamicColorAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||||
|
|
||||||
/** Writable calendars — the only ones that take a per-calendar reminder override. */
|
/**
|
||||||
|
* Writable calendars that are switched on — the only ones that take a
|
||||||
|
* per-calendar reminder override. A calendar switched off in Settings →
|
||||||
|
* Calendars is `VISIBLE = 0`, so the provider schedules no alarms for it and
|
||||||
|
* a default reminder configured there could never fire (#75).
|
||||||
|
*/
|
||||||
private val writableCalendars: Flow<List<CalendarSource>> = repository.calendars()
|
private val writableCalendars: Flow<List<CalendarSource>> = repository.calendars()
|
||||||
.map { calendars -> calendars.filter { it.canModifyContents } }
|
.map { calendars -> calendars.filter { it.canModifyContents && it.isVisibleInSystem } }
|
||||||
.catch { emit(emptyList()) }
|
.catch { emit(emptyList()) }
|
||||||
|
|
||||||
val state: StateFlow<SettingsUiState> =
|
val state: StateFlow<SettingsUiState> =
|
||||||
|
|||||||
@@ -53,11 +53,11 @@
|
|||||||
<string name="event_share_failed">تعذّر مشاركة هذا الحدث.</string>
|
<string name="event_share_failed">تعذّر مشاركة هذا الحدث.</string>
|
||||||
<string name="event_delete_title">حذف الحدث؟</string>
|
<string name="event_delete_title">حذف الحدث؟</string>
|
||||||
<string name="event_delete_body">الحدث أُزيل من تقويمك ومن كل جهاز تتم مزامنته معه.</string>
|
<string name="event_delete_body">الحدث أُزيل من تقويمك ومن كل جهاز تتم مزامنته معه.</string>
|
||||||
<string name="event_delete_recurring_title">حذف الحدث المتكرر</string>
|
<string name="event_delete_recurring_title">حذف الحدث المتكرّر</string>
|
||||||
<string name="event_delete_option_occurrence">فقط هذا الحدث</string>
|
<string name="event_delete_option_occurrence">فقط هذا الحدث</string>
|
||||||
<string name="event_delete_option_following">هذا وجميع الأحداث اللاحقة</string>
|
<string name="event_delete_option_following">هذا وجميع الأحداث اللاحقة</string>
|
||||||
<string name="event_delete_option_series">جميع الأحداث في السلسلة</string>
|
<string name="event_delete_option_series">جميع الأحداث في السلسلة</string>
|
||||||
<string name="event_edit_recurring_title">تعديل الحدث المتكرر</string>
|
<string name="event_edit_recurring_title">تعديل الحدث المتكرّر</string>
|
||||||
<string name="event_delete_failed">تعذّر حذف الحدث</string>
|
<string name="event_delete_failed">تعذّر حذف الحدث</string>
|
||||||
<string name="event_delete_write_denied">Calendula يحتاج إلى صلاحية للكتابة لحذف الأحداث</string>
|
<string name="event_delete_write_denied">Calendula يحتاج إلى صلاحية للكتابة لحذف الأحداث</string>
|
||||||
<string name="dialog_cancel">إلغاء</string>
|
<string name="dialog_cancel">إلغاء</string>
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
<string name="event_edit_conflict_discard_hint">الحدث يبقى كما هو الآن</string>
|
<string name="event_edit_conflict_discard_hint">الحدث يبقى كما هو الآن</string>
|
||||||
<string name="import_reminder_prompt_title">هل تريد تطبيق تذكيرك الافتراضي؟</string>
|
<string name="import_reminder_prompt_title">هل تريد تطبيق تذكيرك الافتراضي؟</string>
|
||||||
<string name="event_edit_gone_body">هذا الحدث حُذف في هذه الأثناء، على سبيل المثال على جهاز آخر. لم يعد من الممكن حفظ تغييراتك.</string>
|
<string name="event_edit_gone_body">هذا الحدث حُذف في هذه الأثناء، على سبيل المثال على جهاز آخر. لم يعد من الممكن حفظ تغييراتك.</string>
|
||||||
<string name="event_edit_more_fields">المزيد من الخيارات</string>
|
<string name="event_edit_more_fields">المزيد من الخانات</string>
|
||||||
<string name="event_access_public">علني</string>
|
<string name="event_access_public">علني</string>
|
||||||
<string name="event_access_default">الافتراضي</string>
|
<string name="event_access_default">الافتراضي</string>
|
||||||
<string name="event_availability_busy">مشغول</string>
|
<string name="event_availability_busy">مشغول</string>
|
||||||
@@ -153,7 +153,7 @@
|
|||||||
<string name="recurrence_with_until">%1$s حتى %2$s</string>
|
<string name="recurrence_with_until">%1$s حتى %2$s</string>
|
||||||
<string name="recurrence_with_count">%1$s، %2$d مرّات</string>
|
<string name="recurrence_with_count">%1$s، %2$d مرّات</string>
|
||||||
<string name="import_reminder_prompt_apply">طَبِّق الافتراضي</string>
|
<string name="import_reminder_prompt_apply">طَبِّق الافتراضي</string>
|
||||||
<string name="event_detail_recurring">حدث مُتكرر</string>
|
<string name="event_detail_recurring">حدث متكرّر</string>
|
||||||
<string name="recurrence_on_days">%1$s في %2$s</string>
|
<string name="recurrence_on_days">%1$s في %2$s</string>
|
||||||
<string name="event_attendee_unknown">—</string>
|
<string name="event_attendee_unknown">—</string>
|
||||||
<string name="event_attendee_accepted">تم القُبول</string>
|
<string name="event_attendee_accepted">تم القُبول</string>
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
<string name="event_status_cancelled">ملغي</string>
|
<string name="event_status_cancelled">ملغي</string>
|
||||||
<string name="event_availability_free">متاح</string>
|
<string name="event_availability_free">متاح</string>
|
||||||
<string name="event_access_private">خاص</string>
|
<string name="event_access_private">خاص</string>
|
||||||
<string name="event_access_confidential">سري</string>
|
<string name="event_access_confidential">سرّي</string>
|
||||||
<string name="event_attendee_organizer">المُنظِّم</string>
|
<string name="event_attendee_organizer">المُنظِّم</string>
|
||||||
<string name="event_attendee_optional">اختياري</string>
|
<string name="event_attendee_optional">اختياري</string>
|
||||||
<string name="reminder_default">التذكير الافتراضي</string>
|
<string name="reminder_default">التذكير الافتراضي</string>
|
||||||
@@ -180,7 +180,7 @@
|
|||||||
<string name="reminder_onboarding_body">Android لا يعرض تذكيرات الأحداث من نفسه — بل يجب أن يقوم تطبيق تقويم بذلك. دع Calendula يتولى هذه المهمة.</string>
|
<string name="reminder_onboarding_body">Android لا يعرض تذكيرات الأحداث من نفسه — بل يجب أن يقوم تطبيق تقويم بذلك. دع Calendula يتولى هذه المهمة.</string>
|
||||||
<string name="reminder_benefit_delivery_body">كل تذكير لأحداثك يصِل كإشعار، في الوقت المحدد تمامًا.</string>
|
<string name="reminder_benefit_delivery_body">كل تذكير لأحداثك يصِل كإشعار، في الوقت المحدد تمامًا.</string>
|
||||||
<string name="reminder_benefit_duplicates_title">هل تستخدم تطبيق تقويم ثانٍ؟</string>
|
<string name="reminder_benefit_duplicates_title">هل تستخدم تطبيق تقويم ثانٍ؟</string>
|
||||||
<string name="reminder_benefit_duplicates_body">إذا كان تطبيق آخر أيضًا ينشر تذكيرات، فستراهم مرتين — قم بإيقاف تشغيلهم هناك أو هنا.</string>
|
<string name="reminder_benefit_duplicates_body">إذا تطبيق آخر أيضًا ينشر تذكيرات، فستراهم مرتين — قم بإيقاف تشغيلهم هناك أو هنا.</string>
|
||||||
<string name="reminder_benefit_reversible_title">يمكنك تغييره في أي وقت</string>
|
<string name="reminder_benefit_reversible_title">يمكنك تغييره في أي وقت</string>
|
||||||
<string name="reminder_onboarding_enable_button">شَغِّل التذكيرات</string>
|
<string name="reminder_onboarding_enable_button">شَغِّل التذكيرات</string>
|
||||||
<string name="reminder_onboarding_skip_button">ليس الآن</string>
|
<string name="reminder_onboarding_skip_button">ليس الآن</string>
|
||||||
@@ -200,7 +200,7 @@
|
|||||||
<string name="search_hint">البحث عن الأحداث</string>
|
<string name="search_hint">البحث عن الأحداث</string>
|
||||||
<string name="search_clear">مسح</string>
|
<string name="search_clear">مسح</string>
|
||||||
<string name="agenda_no_more_today">لا مزيد من الأحداث اليوم</string>
|
<string name="agenda_no_more_today">لا مزيد من الأحداث اليوم</string>
|
||||||
<string name="search_empty">لا توجد أحداث مطابقة ”%1$s“.</string>
|
<string name="search_empty">لا أحداث مطابقة ”%1$s“.</string>
|
||||||
<string name="search_idle_hint">ابحث عن أحداثك بالعنوان، الموقع أو الملاحظات.</string>
|
<string name="search_idle_hint">ابحث عن أحداثك بالعنوان، الموقع أو الملاحظات.</string>
|
||||||
<string name="search_back">الرجوع</string>
|
<string name="search_back">الرجوع</string>
|
||||||
<string name="search_action">البحث</string>
|
<string name="search_action">البحث</string>
|
||||||
@@ -217,7 +217,7 @@
|
|||||||
<string name="back">رجوع</string>
|
<string name="back">رجوع</string>
|
||||||
<string name="settings_section_appearance">المظهر</string>
|
<string name="settings_section_appearance">المظهر</string>
|
||||||
<string name="settings_dynamic_color">اللون الديناميكي</string>
|
<string name="settings_dynamic_color">اللون الديناميكي</string>
|
||||||
<string name="settings_dynamic_color_unavailable">يتطلب Android 12 أو أحدث</string>
|
<string name="settings_dynamic_color_unavailable">يتطلب أندرويد ١٢ أو أحدث</string>
|
||||||
<string name="settings_default_view">طريقة العرض الافتراضية</string>
|
<string name="settings_default_view">طريقة العرض الافتراضية</string>
|
||||||
<string name="settings_soften_colors">ألوان تقويم ناعمة</string>
|
<string name="settings_soften_colors">ألوان تقويم ناعمة</string>
|
||||||
<string name="settings_soften_colors_summary">خفف ألوان التقويم والأحداث لتتناسب مع الثيم. قم بإيقافه لإظهار الألوان الخام من مصدر التقويم.</string>
|
<string name="settings_soften_colors_summary">خفف ألوان التقويم والأحداث لتتناسب مع الثيم. قم بإيقافه لإظهار الألوان الخام من مصدر التقويم.</string>
|
||||||
@@ -227,7 +227,7 @@
|
|||||||
<string name="settings_font_choose_file">اختر ملفًا…</string>
|
<string name="settings_font_choose_file">اختر ملفًا…</string>
|
||||||
<string name="settings_font_custom_selected">خط مخصص</string>
|
<string name="settings_font_custom_selected">خط مخصص</string>
|
||||||
<string name="settings_font_import_failed">تعذّر قراءة هذا الملف كخط</string>
|
<string name="settings_font_import_failed">تعذّر قراءة هذا الملف كخط</string>
|
||||||
<string name="settings_week_start">يبدأ الأسبوع في</string>
|
<string name="settings_week_start">الأسبوع يبدأ في</string>
|
||||||
<string name="settings_week_start_auto">تلقائي</string>
|
<string name="settings_week_start_auto">تلقائي</string>
|
||||||
<string name="settings_time_format_auto">تلقائي</string>
|
<string name="settings_time_format_auto">تلقائي</string>
|
||||||
<string name="settings_time_format">تنسيق الوقت</string>
|
<string name="settings_time_format">تنسيق الوقت</string>
|
||||||
@@ -243,4 +243,58 @@
|
|||||||
<string name="settings_past_events_show">إظهار</string>
|
<string name="settings_past_events_show">إظهار</string>
|
||||||
<string name="settings_past_events_hide">إخفاء</string>
|
<string name="settings_past_events_hide">إخفاء</string>
|
||||||
<string name="settings_agenda_header">جدول</string>
|
<string name="settings_agenda_header">جدول</string>
|
||||||
|
<string name="event_edit_timezone_device">المنطقة الزمنية للجهاز</string>
|
||||||
|
<string name="event_edit_timezone_search">البحث عن المناطق الزمنية</string>
|
||||||
|
<string name="event_edit_timezone_all">جميع المناطق الزمنية</string>
|
||||||
|
<string name="event_edit_timezone_none">لا منطقة زمنية تطابق \"%1$s\"</string>
|
||||||
|
<string name="event_edit_timezone_local_time">%1$s توقيتك</string>
|
||||||
|
<string name="event_edit_timezone_recent">الأحدث</string>
|
||||||
|
<string name="event_edit_recurrence_incomplete">أدخل رقمًا من ١ إلى ٩٩٩</string>
|
||||||
|
<plurals name="duration_minutes">
|
||||||
|
<item quantity="zero">(%d) لا دقائق</item>
|
||||||
|
<item quantity="one">(%d) دقيقة واحده</item>
|
||||||
|
<item quantity="two">%d دقيقتان</item>
|
||||||
|
<item quantity="few">%d دقائق</item>
|
||||||
|
<item quantity="many">%d دقيقة</item>
|
||||||
|
<item quantity="other">%d دقيقة</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="duration_hours">
|
||||||
|
<item quantity="zero">(%d) لا ساعات</item>
|
||||||
|
<item quantity="one">(%d) ساعة واحده</item>
|
||||||
|
<item quantity="two">%d ساعتان</item>
|
||||||
|
<item quantity="few">%d ساعات</item>
|
||||||
|
<item quantity="many">%d ساعة</item>
|
||||||
|
<item quantity="other">%d ساعة</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="duration_days">
|
||||||
|
<item quantity="zero">(%d) لا أيام</item>
|
||||||
|
<item quantity="one">(%d) يوم واحد</item>
|
||||||
|
<item quantity="two">%d يومان</item>
|
||||||
|
<item quantity="few">%d أيام</item>
|
||||||
|
<item quantity="many">%d يوم</item>
|
||||||
|
<item quantity="other">%d يوم</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="duration_weeks">
|
||||||
|
<item quantity="zero">(%d) لا أسابيع</item>
|
||||||
|
<item quantity="one">(%d) أسبوع واحد</item>
|
||||||
|
<item quantity="two">%d أسبوعان</item>
|
||||||
|
<item quantity="few">%d أسابيع</item>
|
||||||
|
<item quantity="many">%d أسبوع</item>
|
||||||
|
<item quantity="other">%d أسبوع</item>
|
||||||
|
</plurals>
|
||||||
|
<string name="agenda_span_starts">يبدأ %1$s</string>
|
||||||
|
<string name="agenda_span_ends">ينتهي %1$s</string>
|
||||||
|
<string name="today_jump_action">الانتقال إلى اليوم</string>
|
||||||
|
<string name="widget_refresh">تحديث</string>
|
||||||
|
<string name="settings_app_name">اسم التطبيق</string>
|
||||||
|
<string name="settings_dim_completed">تعتيم الأحداث المكتملة</string>
|
||||||
|
<string name="settings_dim_completed_summary">تعتيم الأحداث التي انتهت بالفعل في عرض الشهر والأسبوع</string>
|
||||||
|
<string name="settings_today_toolbar">زر اليوم في شريط الأدوات</string>
|
||||||
|
<string name="settings_today_toolbar_summary">إظهار زر الانتقال إلى اليوم في شريط الأدوات بدلاً من زر عائم</string>
|
||||||
|
<string name="settings_app_name_summary">اعرض Calendula كـ \"Calendar\" في مشغّل التطبيقات الخاص بك. فقط الاسم في المشغّل يتغير؛ وقد ينتقل الرمز إلى مكان جديد بعد التبديل.</string>
|
||||||
|
<string name="settings_past_events_dim">تعتيم</string>
|
||||||
|
<string name="settings_past_events">الأحداث السابقة</string>
|
||||||
|
<string name="settings_agenda_range">مدى الجدول</string>
|
||||||
|
<string name="agenda_range_custom">مخصص…</string>
|
||||||
|
<string name="agenda_range_custom_hint">أيام</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -449,8 +449,6 @@
|
|||||||
<string name="settings_special_dates_disable_type_message">Dadurch werden der Kalender „%1$s“ und seine Ereignisse gelöscht. Alle von dir hinzugefügten Erinnerungen oder Notizen gehen verloren.</string>
|
<string name="settings_special_dates_disable_type_message">Dadurch werden der Kalender „%1$s“ und seine Ereignisse gelöscht. Alle von dir hinzugefügten Erinnerungen oder Notizen gehen verloren.</string>
|
||||||
<string name="settings_special_dates_disable_confirm">Deaktivieren</string>
|
<string name="settings_special_dates_disable_confirm">Deaktivieren</string>
|
||||||
<string name="dialog_save">Speichern</string>
|
<string name="dialog_save">Speichern</string>
|
||||||
<string name="calendars_disable_hint">Deaktiviere einen Kalender, um ihn aus der App zu entfernen – seine Ereignisse, Filter und Auswahlmöglichkeiten. Es wird nichts gelöscht und du kannst ihn hier jederzeit wieder aktivieren.</string>
|
|
||||||
<string name="calendars_show_in_app_a11y">„%1$s“ in der App anzeigen</string>
|
|
||||||
<string name="calendars_account_menu_a11y">Weitere Optionen für %1$s</string>
|
<string name="calendars_account_menu_a11y">Weitere Optionen für %1$s</string>
|
||||||
<string name="calendars_enable_all">Alle aktivieren</string>
|
<string name="calendars_enable_all">Alle aktivieren</string>
|
||||||
<string name="calendars_disable_all">Alle deaktivieren</string>
|
<string name="calendars_disable_all">Alle deaktivieren</string>
|
||||||
|
|||||||
@@ -333,8 +333,6 @@
|
|||||||
<string name="calendars_local_header">Tus calendarios</string>
|
<string name="calendars_local_header">Tus calendarios</string>
|
||||||
<string name="calendars_local_empty">Sin calendarios locales todavia. Crea uno para mantener eventos solo en este dispositivo.</string>
|
<string name="calendars_local_empty">Sin calendarios locales todavia. Crea uno para mantener eventos solo en este dispositivo.</string>
|
||||||
<string name="calendars_add">Añadir calendario</string>
|
<string name="calendars_add">Añadir calendario</string>
|
||||||
<string name="calendars_disable_hint">Desactiva un calendario para removerlo de la aplicación — sus eventos, filtros y selectores. Nada se eliminara, y puedes reactivarlo en cualquier momento.</string>
|
|
||||||
<string name="calendars_show_in_app_a11y">Mostrar \"%1$s\" en la aplicación</string>
|
|
||||||
<string name="calendars_synced_header">Calendarios sincronizados</string>
|
<string name="calendars_synced_header">Calendarios sincronizados</string>
|
||||||
<string name="calendars_synced_hint">Estos provienen de cuentas en tu dispositivo. Crea o editalos en su propia aplicación.</string>
|
<string name="calendars_synced_hint">Estos provienen de cuentas en tu dispositivo. Crea o editalos en su propia aplicación.</string>
|
||||||
<string name="calendars_manage_in_app">Gestionar en aplicación</string>
|
<string name="calendars_manage_in_app">Gestionar en aplicación</string>
|
||||||
|
|||||||
@@ -400,8 +400,6 @@
|
|||||||
<string name="calendars_local_header">Vos calendriers</string>
|
<string name="calendars_local_header">Vos calendriers</string>
|
||||||
<string name="calendars_local_empty">Pas encore de calendrier local. Créez-en un pour conserver les événements uniquement sur cet appareil.</string>
|
<string name="calendars_local_empty">Pas encore de calendrier local. Créez-en un pour conserver les événements uniquement sur cet appareil.</string>
|
||||||
<string name="calendars_add">Ajouter un calendrier</string>
|
<string name="calendars_add">Ajouter un calendrier</string>
|
||||||
<string name="calendars_disable_hint">Désactivez un calendrier pour le retirer de l’application, ses événements, ses filtres et ses sélecteurs. Rien n’est supprimé et vous pouvez le réactiver à tout moment ici.</string>
|
|
||||||
<string name="calendars_show_in_app_a11y">Afficher « %1$s » dans l’application</string>
|
|
||||||
<string name="calendars_synced_header">Calendriers synchronisés</string>
|
<string name="calendars_synced_header">Calendriers synchronisés</string>
|
||||||
<string name="calendars_synced_hint">Ils proviennent de comptes sur votre appareil. Créez et modifiez-les dans leur propre application.</string>
|
<string name="calendars_synced_hint">Ils proviennent de comptes sur votre appareil. Créez et modifiez-les dans leur propre application.</string>
|
||||||
<string name="calendars_manage_in_app">Gérer dans l’application</string>
|
<string name="calendars_manage_in_app">Gérer dans l’application</string>
|
||||||
|
|||||||
@@ -317,8 +317,6 @@
|
|||||||
<string name="calendars_local_header">Calendari locali</string>
|
<string name="calendars_local_header">Calendari locali</string>
|
||||||
<string name="calendars_local_empty">Non ci sono ancora calendari locali. Creane uno con eventi salvati solo su questo dispositivo.</string>
|
<string name="calendars_local_empty">Non ci sono ancora calendari locali. Creane uno con eventi salvati solo su questo dispositivo.</string>
|
||||||
<string name="calendars_add">Aggiungi calendario</string>
|
<string name="calendars_add">Aggiungi calendario</string>
|
||||||
<string name="calendars_disable_hint">Disattiva un calendario per non vederlo più sull\'app. Non viene cancellato nulla, puoi riattivarlo in qualsiasi momento.</string>
|
|
||||||
<string name="calendars_show_in_app_a11y">Mostra \"%1$s\" nell\'app</string>
|
|
||||||
<string name="calendars_synced_header">Calendari sincronizzati</string>
|
<string name="calendars_synced_header">Calendari sincronizzati</string>
|
||||||
<string name="calendars_synced_hint">Questi calendari vengono dagli account sincronizzati sul tuo dispositivo. Puoi modificarli o crearne di nuovi dall\'app di sincronizzazione.</string>
|
<string name="calendars_synced_hint">Questi calendari vengono dagli account sincronizzati sul tuo dispositivo. Puoi modificarli o crearne di nuovi dall\'app di sincronizzazione.</string>
|
||||||
<string name="calendars_manage_in_app">Gestisci in app</string>
|
<string name="calendars_manage_in_app">Gestisci in app</string>
|
||||||
|
|||||||
@@ -354,7 +354,7 @@
|
|||||||
<string name="settings_translate">Pomóż w tłumaczeniu</string>
|
<string name="settings_translate">Pomóż w tłumaczeniu</string>
|
||||||
<string name="settings_translate_hint">Dodaj lub ulepsz tłumaczenie w Weblate</string>
|
<string name="settings_translate_hint">Dodaj lub ulepsz tłumaczenie w Weblate</string>
|
||||||
<string name="settings_appearance_subtitle">Motyw, domyślny widok, pierwszy dzień tygodnia</string>
|
<string name="settings_appearance_subtitle">Motyw, domyślny widok, pierwszy dzień tygodnia</string>
|
||||||
<string name="settings_views_subtitle">Kolejność przycisku szybkiego przełączania oraz menu</string>
|
<string name="settings_views_subtitle">Układ widoku miesiąca, przycisk szybkiego przełączania, kolejność menu</string>
|
||||||
<string name="settings_event_form_subtitle">Domyślne pola dla nowych wydarzeń</string>
|
<string name="settings_event_form_subtitle">Domyślne pola dla nowych wydarzeń</string>
|
||||||
<string name="settings_notifications_subtitle">Przypomnienia o wydarzeniach</string>
|
<string name="settings_notifications_subtitle">Przypomnienia o wydarzeniach</string>
|
||||||
<string name="settings_special_dates_subtitle">Urodziny i rocznice kontaktów</string>
|
<string name="settings_special_dates_subtitle">Urodziny i rocznice kontaktów</string>
|
||||||
@@ -396,8 +396,6 @@
|
|||||||
<string name="calendars_local_header">Twoje kalendarze</string>
|
<string name="calendars_local_header">Twoje kalendarze</string>
|
||||||
<string name="calendars_local_empty">Brak lokalnych kalendarzy. Utwórz kalendarz, aby zapisywać wydarzenia tylko na tym urządzeniu.</string>
|
<string name="calendars_local_empty">Brak lokalnych kalendarzy. Utwórz kalendarz, aby zapisywać wydarzenia tylko na tym urządzeniu.</string>
|
||||||
<string name="calendars_add">Dodaj kalendarz</string>
|
<string name="calendars_add">Dodaj kalendarz</string>
|
||||||
<string name="calendars_disable_hint">Wyłącz kalendarz, aby ukryć go w aplikacji — wraz z jego wydarzeniami, filtrami i selektorami. Nic nie zostanie usunięte, a w każdej chwili możesz go tutaj ponownie włączyć.</string>
|
|
||||||
<string name="calendars_show_in_app_a11y">Pokaż „%1$s” w aplikacji</string>
|
|
||||||
<string name="calendars_synced_header">Synchronizowane kalendarze</string>
|
<string name="calendars_synced_header">Synchronizowane kalendarze</string>
|
||||||
<string name="calendars_synced_hint">Pochodzą z kont na Twoim urządzeniu. Możesz je tworzyć i edytować w powiązanych z nimi aplikacjach.</string>
|
<string name="calendars_synced_hint">Pochodzą z kont na Twoim urządzeniu. Możesz je tworzyć i edytować w powiązanych z nimi aplikacjach.</string>
|
||||||
<string name="calendars_manage_in_app">Zarządzaj w aplikacji</string>
|
<string name="calendars_manage_in_app">Zarządzaj w aplikacji</string>
|
||||||
@@ -517,4 +515,32 @@
|
|||||||
<string name="settings_agenda_show_today_hint">Zachowaj dzisiejszy dzień na górze agendy i widżetu, nawet gdy nie ma już na dziś żadnych zadań.</string>
|
<string name="settings_agenda_show_today_hint">Zachowaj dzisiejszy dzień na górze agendy i widżetu, nawet gdy nie ma już na dziś żadnych zadań.</string>
|
||||||
<string name="special_dates_calendar_birthday">Urodziny</string>
|
<string name="special_dates_calendar_birthday">Urodziny</string>
|
||||||
<string name="special_dates_calendar_anniversary">Rocznice</string>
|
<string name="special_dates_calendar_anniversary">Rocznice</string>
|
||||||
|
<string name="event_edit_timezone_device">Strefa czasowa urządzenia</string>
|
||||||
|
<string name="event_edit_timezone_device_summary">Podąża za Twoją lokalizacją</string>
|
||||||
|
<string name="event_edit_timezone_search">Znajdź strefę czasową</string>
|
||||||
|
<string name="event_edit_timezone_recent">Ostatnie</string>
|
||||||
|
<string name="event_edit_timezone_all">Wszystkie strefy czasowe</string>
|
||||||
|
<string name="event_edit_timezone_none">Żadna strefa czasowa nie pasuje do „%1$s”</string>
|
||||||
|
<string name="event_edit_timezone_local_time">%1$s Twojego czasu</string>
|
||||||
|
<string name="event_edit_recurrence_incomplete">Wpisz liczbę od 1 do 999</string>
|
||||||
|
<string name="agenda_span_starts">Początek o %1$s</string>
|
||||||
|
<string name="agenda_span_ends">Koniec o %1$s</string>
|
||||||
|
<string name="today_jump_action">Dzisiaj</string>
|
||||||
|
<string name="settings_today_toolbar">Przycisk „Dzisiaj” na pasku narzędzi</string>
|
||||||
|
<string name="settings_today_toolbar_summary">Pokaż przycisk skoku do dzisiaj na pasku narzędzi zamiast przycisku pływającego</string>
|
||||||
|
<string name="settings_app_name">Nazwa aplikacji</string>
|
||||||
|
<string name="settings_app_name_summary">Wyświetlaj Calendula jako „Kalendarz” w menu aplikacji. Zmieni się tylko nazwa w menu; po przełączeniu ikona może pojawić się w innym miejscu.</string>
|
||||||
|
<string name="settings_month_header">Widok miesiąca</string>
|
||||||
|
<string name="settings_month_view_style">Styl widoku miesiąca</string>
|
||||||
|
<string name="month_style_paged">Strony</string>
|
||||||
|
<string name="month_style_paged_summary">Jeden miesiąc wypełnia ekran. Przesuń w lewo lub w prawo, aby zmienić miesiąc.</string>
|
||||||
|
<string name="month_style_continuous">Przewijanie miesięcy</string>
|
||||||
|
<string name="month_style_continuous_summary">Każdy miesiąc znajduje się pod własnym nagłówkiem, oddzielony od następnego niewielkim odstępem.</string>
|
||||||
|
<string name="month_style_dense">Tygodnie bez przerw</string>
|
||||||
|
<string name="month_style_dense_summary">Tygodnie są ułożone jeden po drugim, każdy miesiąc płynnie łączy się z następnym, bez odstępu pomiędzy.</string>
|
||||||
|
<string name="month_style_split">Podzielony</string>
|
||||||
|
<string name="month_style_split_summary">Zwięzła siatka wyróżnia dni z wydarzeniami a lista dla dnia wybranego dotknięciem wyświetla się poniżej.</string>
|
||||||
|
<string name="month_split_no_events">Brak planów</string>
|
||||||
|
<string name="month_split_expand">Pokaż cały miesiąc</string>
|
||||||
|
<string name="month_split_collapse">Pokaż wydarzenia dnia</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -462,6 +462,7 @@
|
|||||||
<string name="settings_license_value">MIT</string>
|
<string name="settings_license_value">MIT</string>
|
||||||
<string name="settings_about_author">by Jean-Luc Makiola</string>
|
<string name="settings_about_author">by Jean-Luc Makiola</string>
|
||||||
<string name="settings_about_source">Source</string>
|
<string name="settings_about_source">Source</string>
|
||||||
|
<string name="settings_about_privacy">Privacy policy</string>
|
||||||
<string name="settings_about_support">Support development</string>
|
<string name="settings_about_support">Support development</string>
|
||||||
<string name="settings_about_version">Version %1$s</string>
|
<string name="settings_about_version">Version %1$s</string>
|
||||||
<string name="settings_about_logo_desc">Calendula app icon</string>
|
<string name="settings_about_logo_desc">Calendula app icon</string>
|
||||||
@@ -473,8 +474,17 @@
|
|||||||
<string name="calendars_local_header">Your calendars</string>
|
<string name="calendars_local_header">Your calendars</string>
|
||||||
<string name="calendars_local_empty">No local calendars yet. Create one to keep events on this device only.</string>
|
<string name="calendars_local_empty">No local calendars yet. Create one to keep events on this device only.</string>
|
||||||
<string name="calendars_add">Add calendar</string>
|
<string name="calendars_add">Add calendar</string>
|
||||||
<string name="calendars_disable_hint">Turn a calendar off to remove it from the app — its events, filters and pickers. Nothing is deleted, and you can turn it back on here anytime.</string>
|
<string name="calendars_visibility_hint">Turn a calendar off to hide it on this device — its events disappear from the app and it stops reminding you. This is the same switch your other calendar apps use, so they hide it too. Nothing is deleted, no other device is affected, and you can turn it back on here anytime.</string>
|
||||||
<string name="calendars_show_in_app_a11y">Show \"%1$s\" in the app</string>
|
<string name="calendars_visibility_a11y">Show \"%1$s\"</string>
|
||||||
|
<string name="calendars_visibility_notice_title">Some calendars are switched off</string>
|
||||||
|
<string name="calendars_visibility_notice_message">Calendula now shows the calendars that are switched on for this device, so what you see and what reminds you can no longer disagree. Some of yours are currently off — they were switched off here or in another calendar app. Turn any of them back on in Settings → Calendars.</string>
|
||||||
|
<!-- Footer row under the event-form and .ics import calendar pickers. -->
|
||||||
|
<string name="calendar_picker_missing_title">Missing a calendar?</string>
|
||||||
|
<string name="calendar_picker_missing_summary">It may be switched off, read-only, or filled from your contacts — manage your calendars here.</string>
|
||||||
|
<string name="calendars_state_read_only">Read-only</string>
|
||||||
|
<string name="calendars_state_not_synced">Not synced to this device</string>
|
||||||
|
<string name="calendars_state_managed">Filled from your contacts</string>
|
||||||
|
<string name="calendars_managed_delete_locked">This calendar is filled from your contacts, so Calendula would create it again on the next sync. Turn special dates off under Settings → Special dates to delete it.</string>
|
||||||
<string name="calendars_synced_header">Synced calendars</string>
|
<string name="calendars_synced_header">Synced calendars</string>
|
||||||
<string name="calendars_synced_hint">These come from accounts on your device. Create and edit them in their own app.</string>
|
<string name="calendars_synced_hint">These come from accounts on your device. Create and edit them in their own app.</string>
|
||||||
<string name="calendars_manage_in_app">Manage in app</string>
|
<string name="calendars_manage_in_app">Manage in app</string>
|
||||||
@@ -570,8 +580,9 @@
|
|||||||
<string name="settings_qs_tile">Add Quick Settings tile</string>
|
<string name="settings_qs_tile">Add Quick Settings tile</string>
|
||||||
<string name="settings_qs_tile_hint">Add a “New event” tile to the Quick Settings panel.</string>
|
<string name="settings_qs_tile_hint">Add a “New event” tile to the Quick Settings panel.</string>
|
||||||
|
|
||||||
<string name="about_source_url" translatable="false">https://gitea.jeanlucmakiola.de/makiolaj/calendula</string>
|
<string name="about_source_url" translatable="false">https://codeberg.org/jlmakiola/calendula</string>
|
||||||
<string name="about_license_url" translatable="false">https://gitea.jeanlucmakiola.de/makiolaj/calendula/src/branch/main/LICENSE</string>
|
<string name="about_license_url" translatable="false">https://codeberg.org/jlmakiola/calendula/src/branch/main/LICENSE</string>
|
||||||
|
<string name="about_privacy_url" translatable="false">https://jeanlucmakiola.de/calendula/privacy</string>
|
||||||
<string name="about_support_url" translatable="false">https://ko-fi.com/jeanlucmakiola</string>
|
<string name="about_support_url" translatable="false">https://ko-fi.com/jeanlucmakiola</string>
|
||||||
<string name="about_translate_url" translatable="false">https://weblate.dev.jeanlucmakiola.de/engage/calendula/</string>
|
<string name="about_translate_url" translatable="false">https://weblate.dev.jeanlucmakiola.de/engage/calendula/</string>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class CalendarMapperTest {
|
|||||||
visible: Int = 1,
|
visible: Int = 1,
|
||||||
accessLevel: Int = CalendarContract.Calendars.CAL_ACCESS_OWNER,
|
accessLevel: Int = CalendarContract.Calendars.CAL_ACCESS_OWNER,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
|
syncEvents: Int? = 1,
|
||||||
): MapColumnReader = MapColumnReader(
|
): MapColumnReader = MapColumnReader(
|
||||||
CalendarProjection.IDX_ID to id,
|
CalendarProjection.IDX_ID to id,
|
||||||
CalendarProjection.IDX_DISPLAY_NAME to displayName,
|
CalendarProjection.IDX_DISPLAY_NAME to displayName,
|
||||||
@@ -24,6 +25,7 @@ class CalendarMapperTest {
|
|||||||
CalendarProjection.IDX_VISIBLE to visible,
|
CalendarProjection.IDX_VISIBLE to visible,
|
||||||
CalendarProjection.IDX_ACCESS_LEVEL to accessLevel,
|
CalendarProjection.IDX_ACCESS_LEVEL to accessLevel,
|
||||||
CalendarProjection.IDX_DESCRIPTION to description,
|
CalendarProjection.IDX_DESCRIPTION to description,
|
||||||
|
CalendarProjection.IDX_SYNC_EVENTS to syncEvents,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -49,6 +51,18 @@ class CalendarMapperTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `sync_events 0 marks the calendar as not syncing its events`() {
|
||||||
|
assertThat(reader(syncEvents = 0).toCalendarSource().syncsEvents).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a NULL sync_events column is treated as syncing`() {
|
||||||
|
// The harmless default: it only ever holds the visibility migration back
|
||||||
|
// from switching a calendar on.
|
||||||
|
assertThat(reader(syncEvents = null).toCalendarSource().syncsEvents).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `null displayName falls back to placeholder`() {
|
fun `null displayName falls back to placeholder`() {
|
||||||
val src = reader(displayName = null).toCalendarSource()
|
val src = reader(displayName = null).toCalendarSource()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import de.jeanlucmakiola.calendula.domain.EventColorOption
|
|||||||
import de.jeanlucmakiola.calendula.domain.EventForm
|
import de.jeanlucmakiola.calendula.domain.EventForm
|
||||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import kotlinx.datetime.LocalDateTime
|
import kotlinx.datetime.LocalDateTime
|
||||||
import kotlinx.datetime.LocalTime
|
import kotlinx.datetime.LocalTime
|
||||||
@@ -41,8 +42,12 @@ class CalendarRepositoryImplTest {
|
|||||||
produceFile = { tempDir.resolve("repo_test_prefs.preferences_pb").toFile() },
|
produceFile = { tempDir.resolve("repo_test_prefs.preferences_pb").toFile() },
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun makeCal(id: Long, name: String = "Cal $id"): CalendarSource =
|
private fun makeCal(
|
||||||
CalendarSource(id, name, "x@y", "LOCAL", 0xFF112233.toInt(), true)
|
id: Long,
|
||||||
|
name: String = "Cal $id",
|
||||||
|
visible: Boolean = true,
|
||||||
|
): CalendarSource =
|
||||||
|
CalendarSource(id, name, "x@y", "LOCAL", 0xFF112233.toInt(), visible)
|
||||||
|
|
||||||
private fun makeEvent(
|
private fun makeEvent(
|
||||||
id: Long,
|
id: Long,
|
||||||
@@ -171,37 +176,40 @@ class CalendarRepositoryImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `instances drops events whose calendar the user disabled`(@TempDir tempDir: Path) = runTest {
|
fun `instances drops events whose calendar is hidden at system level`(
|
||||||
val prefs = newPrefs(tempDir)
|
@TempDir tempDir: Path,
|
||||||
prefs.setDisabledCalendarIds(setOf(2L))
|
) = runTest {
|
||||||
val fake = FakeCalendarDataSource().apply {
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L, visible = false))
|
||||||
instancesResult = { _, _ ->
|
instancesResult = { _, _ ->
|
||||||
listOf(
|
listOf(
|
||||||
makeEvent(10L, "Enabled", calendarId = 1L),
|
makeEvent(10L, "Shown", calendarId = 1L),
|
||||||
makeEvent(11L, "Disabled", calendarId = 2L),
|
makeEvent(11L, "Switched off", calendarId = 2L),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val repo = CalendarRepositoryImpl(fake, prefs, newSettings(tempDir), UnconfinedTestDispatcher(testScheduler))
|
val repo = CalendarRepositoryImpl(fake, newPrefs(tempDir), newSettings(tempDir), UnconfinedTestDispatcher(testScheduler))
|
||||||
|
|
||||||
val range = Instant.fromEpochMilliseconds(0)..Instant.fromEpochMilliseconds(10_000L)
|
val range = Instant.fromEpochMilliseconds(0)..Instant.fromEpochMilliseconds(10_000L)
|
||||||
repo.instances(range).test {
|
repo.instances(range).test {
|
||||||
assertThat(awaitItem().map { it.title }).containsExactly("Enabled")
|
assertThat(awaitItem().map { it.title }).containsExactly("Shown")
|
||||||
cancelAndIgnoreRemainingEvents()
|
cancelAndIgnoreRemainingEvents()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `instances applies the union of hidden and disabled sets`(@TempDir tempDir: Path) = runTest {
|
fun `instances applies the union of hidden and system-invisible calendars`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
val prefs = newPrefs(tempDir)
|
val prefs = newPrefs(tempDir)
|
||||||
prefs.setHiddenCalendarIds(setOf(2L))
|
prefs.setHiddenCalendarIds(setOf(2L))
|
||||||
prefs.setDisabledCalendarIds(setOf(3L))
|
|
||||||
val fake = FakeCalendarDataSource().apply {
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L), makeCal(3L, visible = false))
|
||||||
instancesResult = { _, _ ->
|
instancesResult = { _, _ ->
|
||||||
listOf(
|
listOf(
|
||||||
makeEvent(10L, "Shown", calendarId = 1L),
|
makeEvent(10L, "Shown", calendarId = 1L),
|
||||||
makeEvent(11L, "Hidden", calendarId = 2L),
|
makeEvent(11L, "Hidden", calendarId = 2L),
|
||||||
makeEvent(12L, "Disabled", calendarId = 3L),
|
makeEvent(12L, "Switched off", calendarId = 3L),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,9 +223,61 @@ class CalendarRepositoryImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `instances re-emits when the disabled set changes`(@TempDir tempDir: Path) = runTest {
|
fun `instances re-emit after a calendar is switched off in the provider`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L))
|
||||||
|
instancesResult = { _, _ ->
|
||||||
|
listOf(
|
||||||
|
makeEvent(10L, "A", calendarId = 1L),
|
||||||
|
makeEvent(11L, "B", calendarId = 2L),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, newPrefs(tempDir), newSettings(tempDir), UnconfinedTestDispatcher(testScheduler))
|
||||||
|
|
||||||
|
val range = Instant.fromEpochMilliseconds(0)..Instant.fromEpochMilliseconds(10_000L)
|
||||||
|
repo.instances(range).test {
|
||||||
|
assertThat(awaitItem().map { it.title }).containsExactly("A", "B").inOrder()
|
||||||
|
|
||||||
|
// The write itself is what the provider notifies about; the observer
|
||||||
|
// tick is what makes the views re-query.
|
||||||
|
repo.setCalendarsVisible(listOf(2L), false)
|
||||||
|
fake.tick()
|
||||||
|
|
||||||
|
assertThat(awaitItem().map { it.title }).containsExactly("A")
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `setCalendarsVisible addresses each calendar on its own`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
// An _id IN (…) batch would skip the provider's own reminder-alarm
|
||||||
|
// reschedule, so every calendar must be written by appended id.
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L), makeCal(3L))
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, newPrefs(tempDir), newSettings(tempDir), Dispatchers.Unconfined)
|
||||||
|
|
||||||
|
repo.setCalendarsVisible(listOf(1L, 3L), false)
|
||||||
|
|
||||||
|
assertThat(fake.visibilityWrites).containsExactly(1L to false, 3L to false).inOrder()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `without write permission the switch is kept app-side and still filters`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
// READ granted, WRITE denied: the provider flag can't be written, so the
|
||||||
|
// choice is parked in the pending set — and honoured from there, or the
|
||||||
|
// user's switched-off calendars would come back on upgrade (#75).
|
||||||
val prefs = newPrefs(tempDir)
|
val prefs = newPrefs(tempDir)
|
||||||
val fake = FakeCalendarDataSource().apply {
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
canWrite = false
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L))
|
||||||
instancesResult = { _, _ ->
|
instancesResult = { _, _ ->
|
||||||
listOf(
|
listOf(
|
||||||
makeEvent(10L, "A", calendarId = 1L),
|
makeEvent(10L, "A", calendarId = 1L),
|
||||||
@@ -231,11 +291,177 @@ class CalendarRepositoryImplTest {
|
|||||||
repo.instances(range).test {
|
repo.instances(range).test {
|
||||||
assertThat(awaitItem().map { it.title }).containsExactly("A", "B").inOrder()
|
assertThat(awaitItem().map { it.title }).containsExactly("A", "B").inOrder()
|
||||||
|
|
||||||
prefs.setDisabledCalendarIds(setOf(2L))
|
repo.setCalendarsVisible(listOf(2L), false)
|
||||||
|
|
||||||
|
assertThat(awaitItem().map { it.title }).containsExactly("A")
|
||||||
|
assertThat(fake.visibilityWrites).isEmpty()
|
||||||
|
assertThat(prefs.pendingDisabledCalendarIds.first()).containsExactly(2L)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `calendars reports a pending switch-off as off`(@TempDir tempDir: Path) = runTest {
|
||||||
|
// Otherwise the Settings switch would snap straight back on for a
|
||||||
|
// read-only install, and the pickers would keep offering the calendar.
|
||||||
|
val prefs = newPrefs(tempDir)
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
canWrite = false
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L))
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, prefs, newSettings(tempDir), UnconfinedTestDispatcher(testScheduler))
|
||||||
|
|
||||||
|
repo.calendars().test {
|
||||||
|
assertThat(awaitItem().map { it.isVisibleInSystem }).containsExactly(true, true)
|
||||||
|
|
||||||
|
repo.setCalendarsVisible(listOf(2L), false)
|
||||||
|
|
||||||
|
assertThat(awaitItem().single { it.id == 2L }.isVisibleInSystem).isFalse()
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `switching a calendar back on without write permission retires its entry`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
val prefs = newPrefs(tempDir)
|
||||||
|
prefs.addPendingDisabledCalendarIds(setOf(2L))
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
canWrite = false
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L))
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, prefs, newSettings(tempDir), Dispatchers.Unconfined)
|
||||||
|
|
||||||
|
repo.setCalendarsVisible(listOf(2L), true)
|
||||||
|
|
||||||
|
assertThat(prefs.pendingDisabledCalendarIds.first()).isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a provider write clears anything still pending for that calendar`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
val prefs = newPrefs(tempDir)
|
||||||
|
prefs.addPendingDisabledCalendarIds(setOf(2L))
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L))
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, prefs, newSettings(tempDir), Dispatchers.Unconfined)
|
||||||
|
|
||||||
|
repo.setCalendarsVisible(listOf(2L), false)
|
||||||
|
|
||||||
|
assertThat(fake.visibilityWrites).containsExactly(2L to false)
|
||||||
|
assertThat(prefs.pendingDisabledCalendarIds.first()).isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `one tick costs one calendar query however many collectors there are`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L))
|
||||||
|
instancesResult = { _, _ -> listOf(makeEvent(10L, "A", calendarId = 1L)) }
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, newPrefs(tempDir), newSettings(tempDir), UnconfinedTestDispatcher(testScheduler))
|
||||||
|
|
||||||
|
val range = Instant.fromEpochMilliseconds(0)..Instant.fromEpochMilliseconds(10_000L)
|
||||||
|
repo.calendars().test {
|
||||||
|
awaitItem()
|
||||||
|
repo.instances(range).test {
|
||||||
|
awaitItem()
|
||||||
|
// Both flows listed/filtered off the same snapshot.
|
||||||
|
assertThat(fake.calendarQueries).isEqualTo(1)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
|
||||||
|
// The next tick invalidates it — one fresh read, not one per flow.
|
||||||
|
// (The list has to change: an identical one is collapsed.)
|
||||||
|
fake.calendarsResult = listOf(makeCal(1L), makeCal(2L), makeCal(3L))
|
||||||
|
fake.tick()
|
||||||
|
awaitItem()
|
||||||
|
assertThat(fake.calendarQueries).isEqualTo(2)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `calendars does not re-emit an unchanged list`(@TempDir tempDir: Path) = runTest {
|
||||||
|
// The store is shared with SettingsPrefs, so an unrelated write would
|
||||||
|
// otherwise re-run every view's combine for an identical list.
|
||||||
|
val prefs = newPrefs(tempDir)
|
||||||
|
val fake = FakeCalendarDataSource().apply { calendarsResult = listOf(makeCal(1L)) }
|
||||||
|
val repo = CalendarRepositoryImpl(fake, prefs, newSettings(tempDir), UnconfinedTestDispatcher(testScheduler))
|
||||||
|
|
||||||
|
repo.calendars().test {
|
||||||
|
assertThat(awaitItem().map { it.id }).containsExactly(1L)
|
||||||
|
|
||||||
|
prefs.setLastUsedCalendarId(1L)
|
||||||
|
fake.tick()
|
||||||
|
|
||||||
|
expectNoEvents()
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a flushed switch-off never reads as on again before the provider ticks`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
// The reconciler's shape: write VISIBLE = 0 straight to the provider,
|
||||||
|
// then release the id app-side. The provider's notification only arrives
|
||||||
|
// afterwards (it is dispatched through the main looper), so the release
|
||||||
|
// must not be read against the snapshot from before the write — that
|
||||||
|
// would flash exactly the events being hidden back into every view.
|
||||||
|
val prefs = newPrefs(tempDir)
|
||||||
|
prefs.addPendingDisabledCalendarIds(setOf(2L))
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L))
|
||||||
|
instancesResult = { _, _ ->
|
||||||
|
listOf(makeEvent(10L, "A", calendarId = 1L), makeEvent(11L, "B", calendarId = 2L))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, prefs, newSettings(tempDir), UnconfinedTestDispatcher(testScheduler))
|
||||||
|
val range = Instant.fromEpochMilliseconds(0)..Instant.fromEpochMilliseconds(10_000L)
|
||||||
|
|
||||||
|
// Warm the snapshot the way an open view would.
|
||||||
|
repo.instances(range).test {
|
||||||
assertThat(awaitItem().map { it.title }).containsExactly("A")
|
assertThat(awaitItem().map { it.title }).containsExactly("A")
|
||||||
cancelAndIgnoreRemainingEvents()
|
cancelAndIgnoreRemainingEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fake.setCalendarVisible(2L, false) // no tick(): the observer hasn't fired yet
|
||||||
|
prefs.removePendingDisabledCalendarIds(setOf(2L))
|
||||||
|
|
||||||
|
repo.instances(range).test {
|
||||||
|
assertThat(awaitItem().map { it.title }).containsExactly("A")
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
repo.calendars().test {
|
||||||
|
assertThat(awaitItem().single { it.id == 2L }.isVisibleInSystem).isFalse()
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `searchEvents drops results from calendars that are off or hidden`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
val prefs = newPrefs(tempDir)
|
||||||
|
prefs.setHiddenCalendarIds(setOf(3L))
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(makeCal(1L), makeCal(2L, visible = false), makeCal(3L))
|
||||||
|
searchResult = {
|
||||||
|
listOf(
|
||||||
|
makeEvent(10L, "Shown", calendarId = 1L),
|
||||||
|
makeEvent(11L, "Switched off", calendarId = 2L),
|
||||||
|
makeEvent(12L, "Hidden", calendarId = 3L),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val repo = CalendarRepositoryImpl(fake, prefs, newSettings(tempDir), Dispatchers.Unconfined)
|
||||||
|
|
||||||
|
assertThat(repo.searchEvents("e").map { it.title }).containsExactly("Shown")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -61,7 +61,14 @@ internal class FakeCalendarDataSource : CalendarDataSource {
|
|||||||
|
|
||||||
private val listeners = mutableListOf<() -> Unit>()
|
private val listeners = mutableListOf<() -> Unit>()
|
||||||
|
|
||||||
override fun calendars(): List<CalendarSource> = calendarsResult
|
/** How often [calendars] was queried — the repository shares one read per tick. */
|
||||||
|
var calendarQueries = 0
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun calendars(): List<CalendarSource> {
|
||||||
|
calendarQueries++
|
||||||
|
return calendarsResult
|
||||||
|
}
|
||||||
override fun instances(beginMillis: Long, endMillis: Long): List<EventInstance> =
|
override fun instances(beginMillis: Long, endMillis: Long): List<EventInstance> =
|
||||||
instancesResult(beginMillis, endMillis)
|
instancesResult(beginMillis, endMillis)
|
||||||
override fun searchEvents(query: String): List<EventInstance> = searchResult(query)
|
override fun searchEvents(query: String): List<EventInstance> = searchResult(query)
|
||||||
@@ -95,6 +102,27 @@ internal class FakeCalendarDataSource : CalendarDataSource {
|
|||||||
updatedCalendars += UpdatedCalendar(id, displayName, color, description)
|
updatedCalendars += UpdatedCalendar(id, displayName, color, description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** (id, visible) pairs passed to [setCalendarVisible], in call order. */
|
||||||
|
val visibilityWrites = mutableListOf<Pair<Long, Boolean>>()
|
||||||
|
|
||||||
|
override fun setCalendarVisible(id: Long, visible: Boolean) {
|
||||||
|
writeError?.let { throw it }
|
||||||
|
visibilityWrites += id to visible
|
||||||
|
// Reflect the write so a follow-up [calendars] read sees it, the way the
|
||||||
|
// provider would once its notification has re-triggered the query.
|
||||||
|
calendarsResult = calendarsResult.map {
|
||||||
|
if (it.id == id) it.copy(isVisibleInSystem = visible) else it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether the fake holds `WRITE_CALENDAR`; false models a read-only grant. */
|
||||||
|
var canWrite: Boolean = true
|
||||||
|
|
||||||
|
override fun canWriteCalendars(): Boolean = canWrite
|
||||||
|
|
||||||
|
override fun isCalendarVisible(id: Long): Boolean? =
|
||||||
|
calendarsResult.firstOrNull { it.id == id }?.isVisibleInSystem
|
||||||
|
|
||||||
override fun deleteCalendar(id: Long) {
|
override fun deleteCalendar(id: Long) {
|
||||||
writeError?.let { throw it }
|
writeError?.let { throw it }
|
||||||
deletedCalendarIds += id
|
deletedCalendarIds += id
|
||||||
|
|||||||
@@ -52,32 +52,65 @@ class CalendarPrefsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `disabledCalendarIds defaults to empty when unset`(@TempDir tempDir: Path) = runTest {
|
fun `the pending disabled set reads back what an older version stored`(
|
||||||
val prefs = CalendarPrefs(newDataStore(tempDir))
|
@TempDir tempDir: Path,
|
||||||
assertThat(prefs.disabledCalendarIds.first()).isEmpty()
|
) = runTest {
|
||||||
|
// Same key as the retired app-local "disabled calendars" model: an
|
||||||
|
// upgrade inherits that set as switch-offs still owed to the provider.
|
||||||
|
val store = newDataStore(tempDir)
|
||||||
|
val prefs = CalendarPrefs(store)
|
||||||
|
store.updateData { p ->
|
||||||
|
p.toMutablePreferences().apply { this[CalendarPrefs.DISABLED_IDS_KEY] = "2,9" }
|
||||||
|
}
|
||||||
|
assertThat(prefs.pendingDisabledCalendarIds.first()).isEqualTo(setOf(2L, 9L))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `setDisabledCalendarIds round-trips through DataStore`(@TempDir tempDir: Path) = runTest {
|
fun `the pending disabled set is empty when nothing was ever stored`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
val prefs = CalendarPrefs(newDataStore(tempDir))
|
val prefs = CalendarPrefs(newDataStore(tempDir))
|
||||||
prefs.setDisabledCalendarIds(setOf(1L, 42L, 7L))
|
assertThat(prefs.pendingDisabledCalendarIds.first()).isEmpty()
|
||||||
assertThat(prefs.disabledCalendarIds.first()).isEqualTo(setOf(1L, 42L, 7L))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `setting empty disabled set clears storage`(@TempDir tempDir: Path) = runTest {
|
fun `pending ids are added and dropped one at a time`(@TempDir tempDir: Path) = runTest {
|
||||||
val prefs = CalendarPrefs(newDataStore(tempDir))
|
val prefs = CalendarPrefs(newDataStore(tempDir))
|
||||||
prefs.setDisabledCalendarIds(setOf(1L))
|
prefs.addPendingDisabledCalendarIds(listOf(2L, 9L))
|
||||||
prefs.setDisabledCalendarIds(emptySet())
|
prefs.addPendingDisabledCalendarIds(listOf(4L))
|
||||||
assertThat(prefs.disabledCalendarIds.first()).isEmpty()
|
|
||||||
|
prefs.removePendingDisabledCalendarIds(setOf(9L))
|
||||||
|
|
||||||
|
assertThat(prefs.pendingDisabledCalendarIds.first()).isEqualTo(setOf(2L, 4L))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `hidden and disabled sets are stored independently`(@TempDir tempDir: Path) = runTest {
|
fun `draining the pending set leaves the hidden set alone`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
val prefs = CalendarPrefs(newDataStore(tempDir))
|
val prefs = CalendarPrefs(newDataStore(tempDir))
|
||||||
prefs.setHiddenCalendarIds(setOf(1L))
|
prefs.setHiddenCalendarIds(setOf(1L))
|
||||||
prefs.setDisabledCalendarIds(setOf(2L))
|
prefs.addPendingDisabledCalendarIds(setOf(2L))
|
||||||
|
|
||||||
|
prefs.removePendingDisabledCalendarIds(setOf(2L))
|
||||||
|
|
||||||
|
assertThat(prefs.pendingDisabledCalendarIds.first()).isEmpty()
|
||||||
assertThat(prefs.hiddenCalendarIds.first()).isEqualTo(setOf(1L))
|
assertThat(prefs.hiddenCalendarIds.first()).isEqualTo(setOf(1L))
|
||||||
assertThat(prefs.disabledCalendarIds.first()).isEqualTo(setOf(2L))
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `the visibility notice is unevaluated until it is written`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
// Null is what makes the evaluation one-shot: "no" is stored just as
|
||||||
|
// firmly as "yes", so the notice can't resurface on a later launch.
|
||||||
|
val prefs = CalendarPrefs(newDataStore(tempDir))
|
||||||
|
assertThat(prefs.visibilityNoticePending.first()).isNull()
|
||||||
|
|
||||||
|
prefs.setVisibilityNoticePending(true)
|
||||||
|
assertThat(prefs.visibilityNoticePending.first()).isTrue()
|
||||||
|
|
||||||
|
prefs.setVisibilityNoticePending(false)
|
||||||
|
assertThat(prefs.visibilityNoticePending.first()).isFalse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.data.reminders
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What the reminder receiver may mark handled. The silenced-but-still-ahead case
|
||||||
|
* is the one that matters: those rows are the only copy of the reminder (#75).
|
||||||
|
*/
|
||||||
|
class AlertHandlingTest {
|
||||||
|
|
||||||
|
private val now = 1_700_000_000_000L
|
||||||
|
|
||||||
|
private fun alert(
|
||||||
|
id: Long,
|
||||||
|
calendarId: Long = 1L,
|
||||||
|
beginMillis: Long = now + 60_000L,
|
||||||
|
endMillis: Long = now + 3_600_000L,
|
||||||
|
) = ReminderAlert(
|
||||||
|
alertId = id,
|
||||||
|
eventId = id * 10,
|
||||||
|
calendarId = calendarId,
|
||||||
|
beginMillis = beginMillis,
|
||||||
|
endMillis = endMillis,
|
||||||
|
title = "E $id",
|
||||||
|
location = null,
|
||||||
|
isAllDay = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `posted alerts are handled`() {
|
||||||
|
val due = listOf(alert(1L), alert(2L))
|
||||||
|
|
||||||
|
assertThat(handledAlertIds(due, postedIds = setOf(1L, 2L), nowMillis = now))
|
||||||
|
.containsExactly(1L, 2L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a silenced alert whose event is still ahead stays unhandled`() {
|
||||||
|
// Switching its calendar back on before the event has to bring it back,
|
||||||
|
// and dueAlerts only ever returns STATE_SCHEDULED rows.
|
||||||
|
val due = listOf(alert(1L), alert(2L))
|
||||||
|
|
||||||
|
assertThat(handledAlertIds(due, postedIds = setOf(1L), nowMillis = now))
|
||||||
|
.containsExactly(1L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a silenced alert whose event is over is handled`() {
|
||||||
|
// Nothing left to re-surface, so it must not linger as scheduled.
|
||||||
|
val over = alert(2L, beginMillis = now - 7_200_000L, endMillis = now - 3_600_000L)
|
||||||
|
val due = listOf(alert(1L), over)
|
||||||
|
|
||||||
|
assertThat(handledAlertIds(due, postedIds = setOf(1L), nowMillis = now))
|
||||||
|
.containsExactly(1L, 2L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `an unknown end time falls back to the begin time`() {
|
||||||
|
val started = alert(1L, beginMillis = now - 1L, endMillis = 0L)
|
||||||
|
val notYet = alert(2L, beginMillis = now + 1L, endMillis = 0L)
|
||||||
|
|
||||||
|
assertThat(handledAlertIds(listOf(started, notYet), postedIds = emptySet(), nowMillis = now))
|
||||||
|
.containsExactly(1L)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package de.jeanlucmakiola.calendula.data.reminders
|
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
|
|
||||||
class PostableAlertsTest {
|
|
||||||
|
|
||||||
private fun alert(alertId: Long, calendarId: Long) = ReminderAlert(
|
|
||||||
alertId = alertId,
|
|
||||||
eventId = alertId * 10,
|
|
||||||
calendarId = calendarId,
|
|
||||||
beginMillis = 0L,
|
|
||||||
endMillis = 0L,
|
|
||||||
title = "Event $alertId",
|
|
||||||
location = null,
|
|
||||||
isAllDay = false,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `keeps alerts when no calendar is disabled`() {
|
|
||||||
val due = listOf(alert(1, calendarId = 100), alert(2, calendarId = 200))
|
|
||||||
|
|
||||||
val postable = postableAlerts(due, disabledCalendarIds = emptySet())
|
|
||||||
|
|
||||||
assertThat(postable).isEqualTo(due)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `drops alerts for a disabled calendar`() {
|
|
||||||
val keep = alert(1, calendarId = 100)
|
|
||||||
val drop = alert(2, calendarId = 200)
|
|
||||||
|
|
||||||
val postable = postableAlerts(listOf(keep, drop), disabledCalendarIds = setOf(200))
|
|
||||||
|
|
||||||
assertThat(postable).containsExactly(keep)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `drops every alert when all their calendars are disabled`() {
|
|
||||||
val due = listOf(alert(1, calendarId = 100), alert(2, calendarId = 100))
|
|
||||||
|
|
||||||
val postable = postableAlerts(due, disabledCalendarIds = setOf(100))
|
|
||||||
|
|
||||||
assertThat(postable).isEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `keeps multiple alerts from the same enabled calendar`() {
|
|
||||||
val due = listOf(alert(1, calendarId = 100), alert(2, calendarId = 100))
|
|
||||||
|
|
||||||
val postable = postableAlerts(due, disabledCalendarIds = setOf(999))
|
|
||||||
|
|
||||||
assertThat(postable).isEqualTo(due)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `alert with unknown calendar id 0 is never treated as disabled`() {
|
|
||||||
// Pre-upgrade snooze PendingIntents carry no calendar id (defaults to 0L).
|
|
||||||
val preUpgrade = alert(1, calendarId = 0L)
|
|
||||||
|
|
||||||
assertThat(preUpgrade.isForDisabledCalendar(disabledCalendarIds = setOf(0L))).isFalse()
|
|
||||||
assertThat(postableAlerts(listOf(preUpgrade), disabledCalendarIds = setOf(0L)))
|
|
||||||
.containsExactly(preUpgrade)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `isForDisabledCalendar matches only the disabled ids`() {
|
|
||||||
assertThat(alert(1, calendarId = 200).isForDisabledCalendar(setOf(200))).isTrue()
|
|
||||||
assertThat(alert(1, calendarId = 100).isForDisabledCalendar(setOf(200))).isFalse()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
package de.jeanlucmakiola.calendula.data.reminders
|
|
||||||
|
|
||||||
import androidx.datastore.core.DataStore
|
|
||||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
|
||||||
import androidx.datastore.preferences.core.Preferences
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
|
||||||
import kotlinx.coroutines.test.runTest
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import org.junit.jupiter.api.io.TempDir
|
|
||||||
import java.nio.file.Path
|
|
||||||
|
|
||||||
class SuppressedReminderStoreTest {
|
|
||||||
|
|
||||||
private fun newDataStore(tempDir: Path): DataStore<Preferences> =
|
|
||||||
PreferenceDataStoreFactory.create(
|
|
||||||
produceFile = { tempDir.resolve("test_prefs.preferences_pb").toFile() },
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun alert(
|
|
||||||
alertId: Long,
|
|
||||||
calendarId: Long,
|
|
||||||
endMillis: Long = Long.MAX_VALUE,
|
|
||||||
title: String = "Event $alertId",
|
|
||||||
location: String? = null,
|
|
||||||
) = ReminderAlert(
|
|
||||||
alertId = alertId,
|
|
||||||
eventId = alertId * 10,
|
|
||||||
calendarId = calendarId,
|
|
||||||
beginMillis = 0L,
|
|
||||||
endMillis = endMillis,
|
|
||||||
title = title,
|
|
||||||
location = location,
|
|
||||||
isAllDay = false,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `encode then decode round-trips every field including delimiters`() {
|
|
||||||
val original = alert(
|
|
||||||
alertId = 7,
|
|
||||||
calendarId = 42,
|
|
||||||
endMillis = 123_456_789L,
|
|
||||||
// Free-text with the field separator and other awkward characters.
|
|
||||||
title = "Lunch | with | Alice",
|
|
||||||
location = "Café, 3rd floor | room B",
|
|
||||||
).copy(beginMillis = 100L, isAllDay = true)
|
|
||||||
|
|
||||||
val decoded = decodeStashEntry(encodeStashEntry(original))
|
|
||||||
|
|
||||||
assertThat(decoded).isEqualTo(original)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `decode returns null for a malformed entry`() {
|
|
||||||
assertThat(decodeStashEntry("not-a-valid-entry")).isNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `null location round-trips`() {
|
|
||||||
val original = alert(1, calendarId = 1, location = null)
|
|
||||||
assertThat(decodeStashEntry(encodeStashEntry(original))).isEqualTo(original)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `recoverFor returns and removes only the re-enabled calendars`() = runTest {
|
|
||||||
val store = SuppressedReminderStore(newDataStore(tempDir))
|
|
||||||
val keep = alert(1, calendarId = 100)
|
|
||||||
val recoverA = alert(2, calendarId = 200)
|
|
||||||
val recoverB = alert(3, calendarId = 200)
|
|
||||||
store.stash(listOf(keep, recoverA, recoverB), nowMillis = 0L)
|
|
||||||
|
|
||||||
val recovered = store.recoverFor(setOf(200L), nowMillis = 0L)
|
|
||||||
|
|
||||||
assertThat(recovered).containsExactly(recoverA, recoverB)
|
|
||||||
// The still-disabled calendar's alert stays stashed; the recovered ones are gone.
|
|
||||||
assertThat(store.recoverFor(setOf(100L, 200L), nowMillis = 0L)).containsExactly(keep)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `stash drops alerts whose event already ended`() = runTest {
|
|
||||||
val store = SuppressedReminderStore(newDataStore(tempDir))
|
|
||||||
val past = alert(1, calendarId = 100, endMillis = 500L)
|
|
||||||
val future = alert(2, calendarId = 100, endMillis = 2_000L)
|
|
||||||
|
|
||||||
store.stash(listOf(past, future), nowMillis = 1_000L)
|
|
||||||
|
|
||||||
assertThat(store.recoverFor(setOf(100L), nowMillis = 1_000L)).containsExactly(future)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `purgeExpired removes only entries past their event end`() = runTest {
|
|
||||||
val store = SuppressedReminderStore(newDataStore(tempDir))
|
|
||||||
// Stash both before "now" so neither is dropped on write, then advance time.
|
|
||||||
store.stash(
|
|
||||||
listOf(
|
|
||||||
alert(1, calendarId = 100, endMillis = 500L),
|
|
||||||
alert(2, calendarId = 100, endMillis = 2_000L),
|
|
||||||
),
|
|
||||||
nowMillis = 0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
store.purgeExpired(nowMillis = 1_000L)
|
|
||||||
|
|
||||||
assertThat(store.recoverFor(setOf(100L), nowMillis = 0L).map { it.alertId })
|
|
||||||
.containsExactly(2L)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `stash replaces an existing entry with the same alert id`() = runTest {
|
|
||||||
val store = SuppressedReminderStore(newDataStore(tempDir))
|
|
||||||
store.stash(listOf(alert(1, calendarId = 100, title = "old")), nowMillis = 0L)
|
|
||||||
store.stash(listOf(alert(1, calendarId = 100, title = "new")), nowMillis = 0L)
|
|
||||||
|
|
||||||
val recovered = store.recoverFor(setOf(100L), nowMillis = 0L)
|
|
||||||
|
|
||||||
assertThat(recovered).hasSize(1)
|
|
||||||
assertThat(recovered.single().title).isEqualTo("new")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `isRelevantAt is true up to the event end and false after`() {
|
|
||||||
val a = alert(1, calendarId = 1, endMillis = 1_000L)
|
|
||||||
assertThat(a.isRelevantAt(999L)).isTrue()
|
|
||||||
assertThat(a.isRelevantAt(1_000L)).isTrue()
|
|
||||||
assertThat(a.isRelevantAt(1_001L)).isFalse()
|
|
||||||
}
|
|
||||||
|
|
||||||
@TempDir
|
|
||||||
lateinit var tempDir: Path
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.domain
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class CalendarRowStateTest {
|
||||||
|
|
||||||
|
private fun cal(
|
||||||
|
id: Long = 1L,
|
||||||
|
name: String = "Cal $id",
|
||||||
|
writable: Boolean = true,
|
||||||
|
syncsEvents: Boolean = true,
|
||||||
|
local: Boolean = false,
|
||||||
|
managed: Boolean = false,
|
||||||
|
) = CalendarSource(
|
||||||
|
id = id,
|
||||||
|
displayName = name,
|
||||||
|
accountName = "account",
|
||||||
|
accountType = if (local) "LOCAL" else "com.google",
|
||||||
|
color = 0,
|
||||||
|
isVisibleInSystem = true,
|
||||||
|
canModifyContents = writable,
|
||||||
|
isLocal = local,
|
||||||
|
syncsEvents = syncsEvents,
|
||||||
|
isManaged = managed,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a plain writable calendar carries no state labels`() {
|
||||||
|
assertThat(cal().stateLabels()).isEmpty()
|
||||||
|
assertThat(cal().hasVisibilitySwitch).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a read-only calendar is labelled`() {
|
||||||
|
assertThat(cal(writable = false).stateLabels())
|
||||||
|
.containsExactly(CalendarStateLabel.READ_ONLY)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a non-syncing account calendar is labelled and loses its switch`() {
|
||||||
|
val calendar = cal(syncsEvents = false)
|
||||||
|
assertThat(calendar.stateLabels()).containsExactly(CalendarStateLabel.NOT_SYNCED)
|
||||||
|
assertThat(calendar.hasVisibilitySwitch).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `both states can hold at once, read-only first`() {
|
||||||
|
assertThat(cal(writable = false, syncsEvents = false).stateLabels())
|
||||||
|
.containsExactly(CalendarStateLabel.READ_ONLY, CalendarStateLabel.NOT_SYNCED)
|
||||||
|
.inOrder()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a managed special-dates mirror is labelled although it is writable`() {
|
||||||
|
// Writable, visible, syncing — nothing else on the row would hint at why
|
||||||
|
// it can't be picked as an event target.
|
||||||
|
val calendar = cal(local = true, managed = true)
|
||||||
|
assertThat(calendar.stateLabels()).containsExactly(CalendarStateLabel.MANAGED)
|
||||||
|
assertThat(calendar.hasVisibilitySwitch).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a local calendar is never called not-synced`() {
|
||||||
|
// Nothing syncs a device-local calendar, so sync_events says nothing
|
||||||
|
// about it — and another app's local calendar can hold real events at 0.
|
||||||
|
val calendar = cal(syncsEvents = false, local = true)
|
||||||
|
assertThat(calendar.isNotSynced).isFalse()
|
||||||
|
assertThat(calendar.stateLabels()).isEmpty()
|
||||||
|
assertThat(calendar.hasVisibilitySwitch).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `every named state keeps a calendar out of the pickers`() {
|
||||||
|
// The labels and the picker exclusion are the same set, stated twice —
|
||||||
|
// a labelled row the pickers still offered would make the footer's
|
||||||
|
// "manage your calendars to see why" a lie (#76).
|
||||||
|
assertThat(cal().isEventTarget).isTrue()
|
||||||
|
listOf(
|
||||||
|
cal(writable = false),
|
||||||
|
cal(syncsEvents = false),
|
||||||
|
cal(local = true, managed = true),
|
||||||
|
).forEach { calendar ->
|
||||||
|
assertThat(calendar.stateLabels()).isNotEmpty()
|
||||||
|
assertThat(calendar.isEventTarget).isFalse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a switched-off calendar is no target although it carries no label`() {
|
||||||
|
// The switch is right there on the row, so the state speaks for itself.
|
||||||
|
val calendar = cal().copy(isVisibleInSystem = false)
|
||||||
|
assertThat(calendar.stateLabels()).isEmpty()
|
||||||
|
assertThat(calendar.isEventTarget).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `manager order puts non-syncing calendars last and is otherwise stable`() {
|
||||||
|
val ordered = listOf(
|
||||||
|
cal(id = 1L, name = "Anna", syncsEvents = false),
|
||||||
|
cal(id = 2L, name = "Bert"),
|
||||||
|
cal(id = 3L, name = "Cleo", syncsEvents = false),
|
||||||
|
cal(id = 4L, name = "Dana"),
|
||||||
|
).orderedForManager()
|
||||||
|
|
||||||
|
assertThat(ordered.map { it.displayName })
|
||||||
|
.containsExactly("Bert", "Dana", "Anna", "Cleo")
|
||||||
|
.inOrder()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.domain
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draining the app's pending "switched off" set into the system's
|
||||||
|
* `Calendars.VISIBLE` (#75) — including the set an upgrade inherits from the
|
||||||
|
* retired app-local visibility model.
|
||||||
|
*/
|
||||||
|
class CalendarVisibilityPlanTest {
|
||||||
|
|
||||||
|
private fun cal(
|
||||||
|
id: Long,
|
||||||
|
visible: Boolean = true,
|
||||||
|
local: Boolean = false,
|
||||||
|
syncsEvents: Boolean = true,
|
||||||
|
): CalendarSource = CalendarSource(
|
||||||
|
id = id,
|
||||||
|
displayName = "Cal $id",
|
||||||
|
accountName = "acc@local",
|
||||||
|
accountType = if (local) "LOCAL" else "com.google",
|
||||||
|
color = 0,
|
||||||
|
isVisibleInSystem = visible,
|
||||||
|
isLocal = local,
|
||||||
|
syncsEvents = syncsEvents,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a pending calendar is switched off at system level`() {
|
||||||
|
val plan = calendarVisibilityPlan(listOf(cal(1L, visible = true)), setOf(1L))
|
||||||
|
assertThat(plan.hide).containsExactly(1L)
|
||||||
|
assertThat(plan.settled).isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a calendar hidden at system level is never switched on`() {
|
||||||
|
// The plan only hides: switching it on would un-hide the calendar in
|
||||||
|
// every other calendar app and start firing its reminders.
|
||||||
|
val plan = calendarVisibilityPlan(listOf(cal(1L, visible = false)), emptySet())
|
||||||
|
assertThat(plan.isEmpty).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a not-synced calendar is switched off like any other`() {
|
||||||
|
val plan = calendarVisibilityPlan(
|
||||||
|
listOf(cal(1L, visible = true, syncsEvents = false)),
|
||||||
|
setOf(1L),
|
||||||
|
)
|
||||||
|
assertThat(plan.hide).containsExactly(1L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a pending calendar already switched off is settled without a write`() {
|
||||||
|
val plan = calendarVisibilityPlan(listOf(cal(1L, visible = false)), setOf(1L))
|
||||||
|
assertThat(plan.hide).isEmpty()
|
||||||
|
assertThat(plan.settled).containsExactly(1L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a pending id for a calendar that no longer exists is settled`() {
|
||||||
|
val plan = calendarVisibilityPlan(listOf(cal(1L)), setOf(99L))
|
||||||
|
assertThat(plan.hide).isEmpty()
|
||||||
|
assertThat(plan.settled).containsExactly(99L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `an empty pending set writes nothing`() {
|
||||||
|
val plan = calendarVisibilityPlan(listOf(cal(1L), cal(2L, visible = false)), emptySet())
|
||||||
|
assertThat(plan.isEmpty).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a mixed device splits into writes and settled ids`() {
|
||||||
|
val plan = calendarVisibilityPlan(
|
||||||
|
listOf(
|
||||||
|
cal(1L, visible = true), // not pending → untouched
|
||||||
|
cal(2L, visible = false), // hidden elsewhere → untouched
|
||||||
|
cal(3L, visible = true), // pending → hide
|
||||||
|
cal(4L, visible = false), // pending, already off → settled
|
||||||
|
),
|
||||||
|
pendingDisabledIds = setOf(3L, 4L, 77L),
|
||||||
|
)
|
||||||
|
assertThat(plan.hide).containsExactly(3L)
|
||||||
|
assertThat(plan.settled).containsExactly(4L, 77L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a calendar hidden outside the app arms the notice`() {
|
||||||
|
assertThat(
|
||||||
|
hasSystemHiddenCalendars(listOf(cal(1L), cal(2L, visible = false)), emptySet()),
|
||||||
|
).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a calendar we are about to hide ourselves does not arm the notice`() {
|
||||||
|
// It is off because the user switched it off here — nothing to explain.
|
||||||
|
assertThat(
|
||||||
|
hasSystemHiddenCalendars(listOf(cal(1L, visible = false)), setOf(1L)),
|
||||||
|
).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `an all-visible device does not arm the notice`() {
|
||||||
|
assertThat(hasSystemHiddenCalendars(listOf(cal(1L), cal(2L)), emptySet())).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a device-local calendar is treated like any other`() {
|
||||||
|
// Its sync_events flag says nothing about whether it holds events, so
|
||||||
|
// neither the plan nor the notice may reason about it.
|
||||||
|
val plan = calendarVisibilityPlan(
|
||||||
|
listOf(cal(1L, visible = true, local = true, syncsEvents = false)),
|
||||||
|
setOf(1L),
|
||||||
|
)
|
||||||
|
assertThat(plan.hide).containsExactly(1L)
|
||||||
|
assertThat(
|
||||||
|
hasSystemHiddenCalendars(
|
||||||
|
listOf(cal(2L, visible = false, local = true, syncsEvents = false)),
|
||||||
|
emptySet(),
|
||||||
|
),
|
||||||
|
).isTrue()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package de.jeanlucmakiola.calendula.domain
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import kotlinx.datetime.LocalDate
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
import kotlinx.datetime.TimeZone
|
||||||
|
import kotlinx.datetime.toInstant
|
||||||
|
import kotlin.time.Instant
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The all-day day-boundary rule every surface shares. All-day events are stored
|
||||||
|
* at UTC midnights with an exclusive end, so their dates must be resolved in UTC
|
||||||
|
* whatever the device zone is — reading them in the device zone names the wrong
|
||||||
|
* day on both sides of the meridian (#65 east, #82 west).
|
||||||
|
*/
|
||||||
|
class EventInstanceSpanTest {
|
||||||
|
|
||||||
|
private val berlin = TimeZone.of("Europe/Berlin") // UTC+2 in July
|
||||||
|
private val newYork = TimeZone.of("America/New_York") // UTC-4 in July
|
||||||
|
|
||||||
|
/** 19 July 2026, all day: UTC midnight to the exclusive next UTC midnight. */
|
||||||
|
private fun allDayJul19(): EventInstance = instance(
|
||||||
|
start = utc(2026, 7, 19),
|
||||||
|
end = utc(2026, 7, 20),
|
||||||
|
isAllDay = true,
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun utc(y: Int, mo: Int, d: Int, h: Int = 0): Instant =
|
||||||
|
LocalDateTime(y, mo, d, h, 0).toInstant(TimeZone.UTC)
|
||||||
|
|
||||||
|
private fun instance(start: Instant, end: Instant, isAllDay: Boolean) = EventInstance(
|
||||||
|
instanceId = 1L,
|
||||||
|
eventId = 1L,
|
||||||
|
calendarId = 1L,
|
||||||
|
title = "Event",
|
||||||
|
start = start,
|
||||||
|
end = end,
|
||||||
|
isAllDay = isAllDay,
|
||||||
|
color = 0xFF000000.toInt(),
|
||||||
|
location = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `all-day event keeps its date west of UTC`() {
|
||||||
|
// Regression for #82: 00:00 UTC on the 19th is 20:00 on the 18th in New
|
||||||
|
// York, so resolving in the device zone would name the 18th.
|
||||||
|
val event = allDayJul19()
|
||||||
|
assertThat(event.spanFirstDay(newYork)).isEqualTo(LocalDate(2026, 7, 19))
|
||||||
|
assertThat(event.spanLastDay(newYork)).isEqualTo(LocalDate(2026, 7, 19))
|
||||||
|
assertThat(event.spansMultipleDays(newYork)).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `all-day event keeps its date east of UTC`() {
|
||||||
|
// Regression for #65: the exclusive end dips past local midnight in
|
||||||
|
// Berlin, which would leak the event onto the 20th.
|
||||||
|
val event = allDayJul19()
|
||||||
|
assertThat(event.spanFirstDay(berlin)).isEqualTo(LocalDate(2026, 7, 19))
|
||||||
|
assertThat(event.spanLastDay(berlin)).isEqualTo(LocalDate(2026, 7, 19))
|
||||||
|
assertThat(event.spansMultipleDays(berlin)).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `multi-day all-day event ends on its last covered day`() {
|
||||||
|
val event = instance(utc(2026, 7, 19), utc(2026, 7, 22), isAllDay = true)
|
||||||
|
assertThat(event.spanFirstDay(newYork)).isEqualTo(LocalDate(2026, 7, 19))
|
||||||
|
assertThat(event.spanLastDay(newYork)).isEqualTo(LocalDate(2026, 7, 21))
|
||||||
|
assertThat(event.spansMultipleDays(newYork)).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `timed event resolves in the device zone`() {
|
||||||
|
// 23:30 UTC on the 19th is already the 20th in Berlin and still the 19th
|
||||||
|
// in New York — a timed event follows the device zone, unlike all-day.
|
||||||
|
val event = instance(utc(2026, 7, 19, 23), utc(2026, 7, 20, 1), isAllDay = false)
|
||||||
|
assertThat(event.spanFirstDay(berlin)).isEqualTo(LocalDate(2026, 7, 20))
|
||||||
|
assertThat(event.spanFirstDay(newYork)).isEqualTo(LocalDate(2026, 7, 19))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `zero-length event occupies its start day`() {
|
||||||
|
val event = instance(utc(2026, 7, 19, 12), utc(2026, 7, 19, 12), isAllDay = false)
|
||||||
|
assertThat(event.spanLastDay(newYork)).isEqualTo(LocalDate(2026, 7, 19))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `dateZone pins all-day events to UTC and leaves timed events alone`() {
|
||||||
|
assertThat(allDayJul19().dateZone(newYork)).isEqualTo(TimeZone.UTC)
|
||||||
|
val timed = instance(utc(2026, 7, 19, 12), utc(2026, 7, 19, 13), isAllDay = false)
|
||||||
|
assertThat(timed.dateZone(newYork)).isEqualTo(newYork)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package de.jeanlucmakiola.calendula.ui.agenda
|
|||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||||
|
import de.jeanlucmakiola.calendula.domain.spansMultipleDays
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import kotlinx.datetime.LocalDateTime
|
import kotlinx.datetime.LocalDateTime
|
||||||
import kotlinx.datetime.TimeZone
|
import kotlinx.datetime.TimeZone
|
||||||
|
|||||||
@@ -45,9 +45,14 @@ class EventEditViewModelTest {
|
|||||||
private val beginMillis = 1_781_164_800_000L
|
private val beginMillis = 1_781_164_800_000L
|
||||||
private val endMillis = beginMillis + 3_600_000L
|
private val endMillis = beginMillis + 3_600_000L
|
||||||
|
|
||||||
private fun cal(id: Long): CalendarSource = CalendarSource(
|
private fun cal(
|
||||||
|
id: Long,
|
||||||
|
visible: Boolean = true,
|
||||||
|
syncsEvents: Boolean = true,
|
||||||
|
): CalendarSource = CalendarSource(
|
||||||
id = id, displayName = "Cal $id", accountName = "acc@local", accountType = "LOCAL",
|
id = id, displayName = "Cal $id", accountName = "acc@local", accountType = "LOCAL",
|
||||||
color = 0xFF112233.toInt(), isVisibleInSystem = true, canModifyContents = true,
|
color = 0xFF112233.toInt(), isVisibleInSystem = visible, canModifyContents = true,
|
||||||
|
syncsEvents = syncsEvents,
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun detail(calendarId: Long, rrule: String? = null): EventDetail = EventDetail(
|
private fun detail(calendarId: Long, rrule: String? = null): EventDetail = EventDetail(
|
||||||
@@ -90,6 +95,66 @@ class EventEditViewModelTest {
|
|||||||
/** Keep [EventEditViewModel.state] hot so it computes while the test drives it. */
|
/** Keep [EventEditViewModel.state] hot so it computes while the test drives it. */
|
||||||
private fun CoroutineScope.activate(vm: EventEditViewModel): Job = launch { vm.state.collect {} }
|
private fun CoroutineScope.activate(vm: EventEditViewModel): Job = launch { vm.state.collect {} }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a calendar switched off in settings is not offered as a target`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest(dispatcher) {
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(cal(1L), cal(2L, visible = false))
|
||||||
|
eventDetailResult = { detail(calendarId = 1L) }
|
||||||
|
}
|
||||||
|
val vm = viewModel(tempDir, fake)
|
||||||
|
val job = activate(vm)
|
||||||
|
|
||||||
|
vm.openForEdit(eventId = 42L, beginMillis = beginMillis, endMillis = endMillis)
|
||||||
|
advanceUntilIdle()
|
||||||
|
|
||||||
|
assertThat(vm.state.value?.calendars?.map { it.id }).containsExactly(1L)
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a calendar whose account is not synced to this device is not a target`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest(dispatcher) {
|
||||||
|
// Writable and switched on, but the account keeps its events off the
|
||||||
|
// device: nothing saved here ever reaches it, and the provider drops the
|
||||||
|
// rows when the subscription comes back (#76).
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(cal(1L), cal(2L, syncsEvents = false))
|
||||||
|
eventDetailResult = { detail(calendarId = 1L) }
|
||||||
|
}
|
||||||
|
val vm = viewModel(tempDir, fake)
|
||||||
|
val job = activate(vm)
|
||||||
|
|
||||||
|
vm.openForEdit(eventId = 42L, beginMillis = beginMillis, endMillis = endMillis)
|
||||||
|
advanceUntilIdle()
|
||||||
|
|
||||||
|
assertThat(vm.state.value?.calendars?.map { it.id }).containsExactly(1L)
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `editing an event in a switched-off calendar keeps it in the picker`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest(dispatcher) {
|
||||||
|
// Otherwise the calendar row renders as the "no calendar" error and any
|
||||||
|
// pick routes the save through a move the user never asked for.
|
||||||
|
val fake = FakeCalendarDataSource().apply {
|
||||||
|
calendarsResult = listOf(cal(1L), cal(2L, visible = false))
|
||||||
|
eventDetailResult = { detail(calendarId = 2L) }
|
||||||
|
}
|
||||||
|
val vm = viewModel(tempDir, fake)
|
||||||
|
val job = activate(vm)
|
||||||
|
|
||||||
|
vm.openForEdit(eventId = 42L, beginMillis = beginMillis, endMillis = endMillis)
|
||||||
|
advanceUntilIdle()
|
||||||
|
|
||||||
|
assertThat(vm.state.value?.calendars?.map { it.id }).containsExactly(1L, 2L)
|
||||||
|
assertThat(vm.state.value?.form?.calendarId).isEqualTo(2L)
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `changing the calendar routes the save through a move, not an update`(
|
fun `changing the calendar routes the save through a move, not an update`(
|
||||||
@TempDir tempDir: Path,
|
@TempDir tempDir: Path,
|
||||||
|
|||||||
@@ -157,6 +157,27 @@ sequenceDiagram
|
|||||||
Posting happens before marking: a crash in between re-posts silently (same
|
Posting happens before marking: a crash in between re-posts silently (same
|
||||||
tag + `setOnlyAlertOnce`) rather than losing a reminder. Swiped
|
tag + `setOnlyAlertOnce`) rather than losing a reminder. Swiped
|
||||||
notifications never return because `FIRED` rows are never re-queried.
|
notifications never return because `FIRED` rows are never re-queried.
|
||||||
|
|
||||||
|
**One visibility model.** The provider only schedules alarms for calendars with
|
||||||
|
`Calendars.VISIBLE = 1`, so that flag *is* the app's on/off switch: Settings →
|
||||||
|
Calendars writes it (one calendar per update — `CalendarProvider2` skips its own
|
||||||
|
`checkNextAlarm()` reschedule for any selection that isn't `_id=`), and every
|
||||||
|
display predicate reads `CalendarSource.isVisibleInSystem`. The reconciliation
|
||||||
|
runs one way only: a calendar the user switched off in Calendula is switched off
|
||||||
|
in the provider, never the reverse — un-hiding one would reach into every other
|
||||||
|
calendar app on the device — and a one-time notice explains the calendars that
|
||||||
|
were already off. `CalendarPrefs.pendingDisabledCalendarIds` holds the switch-offs
|
||||||
|
the app has not been allowed to write yet (read-only permission grant, or a
|
||||||
|
pre-permission launch); `CalendarVisibilityReconciler` drains it entry by entry,
|
||||||
|
and until it does, the repository and `ReminderNotifier.post` honour it. That
|
||||||
|
gate also covers a snooze re-shown from our own alarm after its calendar was
|
||||||
|
switched off. Silencing is not handling: an alert the gate drops keeps its
|
||||||
|
`SCHEDULED` state while its event is still ahead (`handledAlertIds`), so
|
||||||
|
switching the calendar back on re-posts it (`ReminderRecovery`) instead of
|
||||||
|
losing it — the provider's own table is the stash. The drawer's filter sheet
|
||||||
|
(`CalendarPrefs.hiddenCalendarIds`) is a separate in-app declutter that never
|
||||||
|
touches reminders.
|
||||||
|
|
||||||
Deliberately absent until real devices prove it necessary: own alarm
|
Deliberately absent until real devices prove it necessary: own alarm
|
||||||
scheduling, `BOOT_COMPLETED`, snooze/dismiss actions, battery-exemption
|
scheduling, `BOOT_COMPLETED`, snooze/dismiss actions, battery-exemption
|
||||||
prompts.
|
prompts.
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ Published version codes so far: `v0.1.0`→100 … `v1.0.0`→10000 … `v2.0.0`
|
|||||||
CI and release are split so a change is built once on its PR and only does
|
CI and release are split so a change is built once on its PR and only does
|
||||||
release work when a merge actually cuts a release:
|
release work when a merge actually cuts a release:
|
||||||
|
|
||||||
- **`ci.yaml`** (on `pull_request`) — lint + unit tests + a debug assemble (and
|
- **`ci.yaml`** (`.forgejo/workflows/`, on `pull_request`, **Codeberg**) — lint +
|
||||||
|
unit tests + a debug assemble (and
|
||||||
a Trivy scan), once per PR. Docs/metadata-only PRs skip the Android build but
|
a Trivy scan), once per PR. Docs/metadata-only PRs skip the Android build but
|
||||||
still report a green `CI` check.
|
still report a green `CI` check.
|
||||||
- **`release.yaml`** (on push to `main`, plus `workflow_dispatch`) — a cheap
|
- **`release.yaml`** (on push to `main`, plus `workflow_dispatch`) — a cheap
|
||||||
@@ -91,9 +92,9 @@ release work when a merge actually cuts a release:
|
|||||||
|
|
||||||
Alongside F-Droid, each release is mirrored to the Codeberg repo
|
Alongside F-Droid, each release is mirrored to the Codeberg repo
|
||||||
(`jlmakiola/calendula`) as a plain download for users who don't want F-Droid.
|
(`jlmakiola/calendula`) as a plain download for users who don't want F-Droid.
|
||||||
Gitea already **push-mirrors** branches and tags to Codeberg, but releases
|
Codeberg **push-mirrors** branches and tags to Gitea, but releases aren't git
|
||||||
aren't git objects and don't sync, so the pipeline creates the release over the
|
objects and don't sync in either direction, so the pipeline creates the release
|
||||||
Codeberg API and attaches `calendula_v<version>.apk` + its `.sha256`. It's the
|
over the Codeberg API and attaches `calendula_v<version>.apk` + its `.sha256`. It's the
|
||||||
same APK the F-Droid repo serves (same **app key**), so it adds no trust
|
same APK the F-Droid repo serves (same **app key**), so it adds no trust
|
||||||
surface. The step is best-effort: a Codeberg outage never fails an
|
surface. The step is best-effort: a Codeberg outage never fails an
|
||||||
already-published F-Droid release, and it skips cleanly if `CODEBERG_RELEASE_TOKEN` is
|
already-published F-Droid release, and it skips cleanly if `CODEBERG_RELEASE_TOKEN` is
|
||||||
@@ -109,6 +110,39 @@ build, the version bump, and tag/release creation, and just re-signs the
|
|||||||
existing F-Droid index with the configured repo key and re-uploads. Use this
|
existing F-Droid index with the configured repo key and re-uploads. Use this
|
||||||
for key rotation or repo recovery without publishing a new app version.
|
for key rotation or repo recovery without publishing a new app version.
|
||||||
|
|
||||||
|
## Two forges, one repo
|
||||||
|
|
||||||
|
**Codeberg (`jlmakiola/calendula`) is canonical** — git, issues, PRs, tags and
|
||||||
|
releases. The self-hosted Gitea instance is build infrastructure: it holds the
|
||||||
|
signing key, publishes the F-Droid repo, and runs the release pipeline. Codeberg
|
||||||
|
push-mirrors `main` and tags to Gitea, and a bumped `versionName` arriving there
|
||||||
|
triggers `release.yaml` exactly as before.
|
||||||
|
|
||||||
|
Workflows are separated by **directory**, not by conditionals. Forgejo looks in
|
||||||
|
`.forgejo/workflows` → `.gitea/workflows` → `.github/workflows` and stops at the
|
||||||
|
first that exists; Gitea doesn't know `.forgejo/` at all:
|
||||||
|
|
||||||
|
| Directory | Runs on | Contains | Secrets |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `.forgejo/workflows/` | Codeberg | `ci.yaml`, `translations.yaml` | **none** |
|
||||||
|
| `.gitea/workflows/` | Gitea | `release.yaml`, `renovate.yml` | signing key, F-Droid, Play, bot tokens |
|
||||||
|
|
||||||
|
The line is drawn at **secrets, not at CI-vs-release**. That's what makes fork
|
||||||
|
PRs safe: everything a contributor can trigger lives in `.forgejo/` and can
|
||||||
|
reference no secret. Renovate stays on the Gitea runner *even though it opens
|
||||||
|
PRs on Codeberg* — it talks to Codeberg's API rather than moving its token onto
|
||||||
|
the contributor-facing runner.
|
||||||
|
|
||||||
|
Two consequences worth remembering:
|
||||||
|
|
||||||
|
- **`detect` reads tags from Codeberg**, not from the Gitea instance it runs on.
|
||||||
|
Push mirroring is `git push --mirror`, so a tag minted on Gitea is deleted by
|
||||||
|
the next sync until the Codeberg tag push propagates back. Asking Gitea inside
|
||||||
|
that window would re-cut a shipped release.
|
||||||
|
- **Any ref that exists only on Gitea gets deleted** by the mirror. That's
|
||||||
|
correct under Codeberg-canonical, but don't debug a "vanished" branch without
|
||||||
|
remembering it.
|
||||||
|
|
||||||
## Secrets (Gitea → repo Settings → Actions → Secrets)
|
## Secrets (Gitea → repo Settings → Actions → Secrets)
|
||||||
|
|
||||||
| Secret | Purpose |
|
| Secret | Purpose |
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ Categories:
|
|||||||
- Calendar & Agenda
|
- Calendar & Agenda
|
||||||
License: MIT
|
License: MIT
|
||||||
AuthorName: Jean-Luc Makiola
|
AuthorName: Jean-Luc Makiola
|
||||||
SourceCode: https://gitea.jeanlucmakiola.de/makiolaj/calendula
|
SourceCode: https://codeberg.org/jlmakiola/calendula
|
||||||
IssueTracker: https://gitea.jeanlucmakiola.de/makiolaj/calendula/issues
|
IssueTracker: https://codeberg.org/jlmakiola/calendula/issues
|
||||||
Changelog: https://gitea.jeanlucmakiola.de/makiolaj/calendula/src/branch/main/CHANGELOG.md
|
Changelog: https://codeberg.org/jlmakiola/calendula/src/branch/main/CHANGELOG.md
|
||||||
Donate: https://ko-fi.com/jeanlucmakiola
|
Donate: https://ko-fi.com/jeanlucmakiola
|
||||||
|
|
||||||
AutoName: Calendula
|
AutoName: Calendula
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ Summary: A modern Material 3 Expressive calendar for Android.
|
|||||||
Categories:
|
Categories:
|
||||||
- Time
|
- Time
|
||||||
|
|
||||||
SourceCode: https://gitea.jeanlucmakiola.de/makiolaj/calendula
|
SourceCode: https://codeberg.org/jlmakiola/calendula
|
||||||
IssueTracker: https://gitea.jeanlucmakiola.de/makiolaj/calendula/issues
|
IssueTracker: https://codeberg.org/jlmakiola/calendula/issues
|
||||||
Donate: https://ko-fi.com/jeanlucmakiola
|
Donate: https://ko-fi.com/jeanlucmakiola
|
||||||
|
|||||||
@@ -7,6 +7,23 @@
|
|||||||
":semanticCommits",
|
":semanticCommits",
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// `config:recommended` brings in mergeConfidence:age-confidence-badges, whose
|
||||||
|
// Age column is a Mend badge. Mend's Merge Confidence index only covers Maven
|
||||||
|
// Central: org.jetbrains.kotlin, junit, truth, turbine et al resolve, but
|
||||||
|
// every androidx/compose artifact lives on Google's Maven repo and comes back
|
||||||
|
// as a grey UNKNOWN — i.e. most of this project. Renovate already knows the
|
||||||
|
// real answer, since it derives release timestamps itself for the
|
||||||
|
// minimumReleaseAge rules below (Google Maven serves `last-modified` on its
|
||||||
|
// POMs), so take the age from there and leave Mend to the Confidence column,
|
||||||
|
// which still carries signal for the Maven Central half.
|
||||||
|
prBodyDefinitions: {
|
||||||
|
Age: "{{#if releaseTimestamp}}{{{newVersionAgeInDays}}} d{{else}}unknown{{/if}}",
|
||||||
|
},
|
||||||
|
// Default heading links to the Merge Confidence docs; this column is ours now.
|
||||||
|
prBodyHeadingDefinitions: {
|
||||||
|
Age: "Age",
|
||||||
|
},
|
||||||
|
|
||||||
// No automerge: a dependency bump goes through the same review (and, for
|
// No automerge: a dependency bump goes through the same review (and, for
|
||||||
// anything touching the build, the same on-device check) as a feature
|
// anything touching the build, the same on-device check) as a feature
|
||||||
// before it can ride a release — see docs/RELEASING.md and the
|
// before it can ride a release — see docs/RELEASING.md and the
|
||||||
@@ -15,6 +32,22 @@
|
|||||||
|
|
||||||
// One reviewable surface; the dashboard issue lists everything pending.
|
// One reviewable surface; the dashboard issue lists everything pending.
|
||||||
dependencyDashboard: true,
|
dependencyDashboard: true,
|
||||||
|
|
||||||
|
// The cooling-off periods below are advisory, not a gate. "flexible" still
|
||||||
|
// prefers a version that has cleared its window, but when every candidate is
|
||||||
|
// too young it opens the PR at the newest one anyway, so merging early stays
|
||||||
|
// a judgement call. (The default, "strict", would suppress the PR entirely
|
||||||
|
// until a release aged in.) A still-young branch carries a yellow
|
||||||
|
// `renovate/stability-days` check so it's visible which side of the line
|
||||||
|
// it's on; with automerge off, nothing acts on that check by itself.
|
||||||
|
//
|
||||||
|
// NOT "none": that short-circuits the candidate loop in filter-checks.ts, and
|
||||||
|
// that loop is what calls postprocessRelease — the only thing that fetches a
|
||||||
|
// Maven artifact's Last-Modified header. Skipping it leaves releaseTimestamp
|
||||||
|
// unset, which empties the Age column and quietly makes minimumReleaseAge and
|
||||||
|
// the stability check no-ops, since both need that timestamp to compare.
|
||||||
|
internalChecksFilter: "flexible",
|
||||||
|
|
||||||
labels: ["dependencies"],
|
labels: ["dependencies"],
|
||||||
prConcurrentLimit: 5,
|
prConcurrentLimit: 5,
|
||||||
prHourlyLimit: 0,
|
prHourlyLimit: 0,
|
||||||
@@ -25,11 +58,28 @@
|
|||||||
|
|
||||||
// Gitea Actions workflows live under .gitea/workflows, not .github — extend
|
// Gitea Actions workflows live under .gitea/workflows, not .github — extend
|
||||||
// the github-actions manager (same syntax) to watch them too.
|
// the github-actions manager (same syntax) to watch them too.
|
||||||
|
// `fileMatch` is deprecated; the replacement takes the regex delimited, and
|
||||||
|
// Renovate's config migration was already rewriting this on every run.
|
||||||
"github-actions": {
|
"github-actions": {
|
||||||
fileMatch: ["^\\.gitea/workflows/[^/]+\\.ya?ml$"],
|
managerFilePatterns: ["/^\\.gitea/workflows/[^/]+\\.ya?ml$/"],
|
||||||
},
|
},
|
||||||
|
|
||||||
packageRules: [
|
packageRules: [
|
||||||
|
// Cooling-off period, scaled by blast radius: how long a release should
|
||||||
|
// have been out (and un-yanked, un-hotfixed) before it's considered
|
||||||
|
// settled. Advisory only — see `internalChecksFilter` above.
|
||||||
|
{
|
||||||
|
matchUpdateTypes: ["major"],
|
||||||
|
minimumReleaseAge: "30 days",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matchUpdateTypes: ["minor"],
|
||||||
|
minimumReleaseAge: "20 days",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matchUpdateTypes: ["patch", "digest", "pin", "rollback"],
|
||||||
|
minimumReleaseAge: "10 days",
|
||||||
|
},
|
||||||
// material3 is deliberately pinned to the 1.5 *alpha* line for the
|
// material3 is deliberately pinned to the 1.5 *alpha* line for the
|
||||||
// Expressive APIs (see gradle/libs.versions.toml). Follow the alpha train
|
// Expressive APIs (see gradle/libs.versions.toml). Follow the alpha train
|
||||||
// but keep it in its own PR, reviewed in isolation; revisit the pin when
|
// but keep it in its own PR, reviewed in isolation; revisit the pin when
|
||||||
@@ -52,5 +102,18 @@
|
|||||||
],
|
],
|
||||||
groupName: "test dependencies",
|
groupName: "test dependencies",
|
||||||
},
|
},
|
||||||
|
// Last word on the PR table. The merge-confidence preset sets prBodyColumns
|
||||||
|
// from inside a packageRule of its own, and only for the datasources Mend
|
||||||
|
// supports — so a plain top-level prBodyColumns would lose to it for maven
|
||||||
|
// deps, and the Gradle wrapper / Actions / container bumps would keep the
|
||||||
|
// default columns and show no age at all. A rule declared after it wins,
|
||||||
|
// and gives every PR the same table.
|
||||||
|
// "Pending" earns its place under a flexible filter: when the bump lands on
|
||||||
|
// a version that has cleared its window but a newer one hasn't, that newer
|
||||||
|
// version is named here rather than silently withheld.
|
||||||
|
{
|
||||||
|
matchPackageNames: ["*"],
|
||||||
|
prBodyColumns: ["Package", "Type", "Change", "Age", "Pending", "Confidence"],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user