MainActivity: auto-refresh on system contact changes (ContentObserver)#555
Open
dsremo wants to merge 1 commit into
Open
MainActivity: auto-refresh on system contact changes (ContentObserver)#555dsremo wants to merge 1 commit into
dsremo wants to merge 1 commit into
Conversation
When a contact is added/edited/deleted by another app (e.g., system contact picker, sync adapter, contact-import tools), Fossify Contacts currently only re-reads the contact list on next onResume(). If the user is already on the contact list when the change happens, the stale list stays on screen until they navigate away and back. This registers a ContentObserver on ContactsContract.Contacts.CONTENT_URI in onResume() and unregisters in onPause(). When the observer fires, refreshContacts(ALL_TABS_MASK) is debounced by 500ms (to coalesce multi-row bulk operations) and executed on the main thread handler. Behaviour outside of registered visibility (i.e., when the activity is paused/destroyed) is unchanged - no work happens off-screen. The observer runs only while the activity is visible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a contact is added, edited, or deleted by another app — system contact picker, a sync adapter (Google/Nextcloud/etc.), CSV importer, or any third-party tool that writes to
ContactsContract.Contacts— Fossify Contacts currently only re-reads the contact list on the nextonResume(). If the user is already on the contact list while the change happens, the stale list stays on screen until they manually navigate away and back.Fix
Register a
ContentObserveronContactsContract.Contacts.CONTENT_URIinonResume(), unregister inonPause(). When the observer fires, callrefreshContacts(ALL_TABS_MASK)debounced by 500 ms so a bulk row-by-row update (e.g., a sync of 200 contacts) coalesces into a single refresh rather than firing 200 times.Files touched
app/src/main/kotlin/org/fossify/contacts/activities/MainActivity.kt(+38)Lifecycle correctness
onPause()always unregisters before the activity becomes paused — no observer leaks across configuration changes or process death.runCatchingwraps both register and unregister to swallow the rareIllegalStateExceptionfrom the framework when the resolver state is invalid (Android 11 occasionally throws on rapid pause/resume cycles).Tested
Manual: open Fossify Contacts → keep it foreground → from a separate app (
adb shell content insert) add and delete contacts → list refreshes within ~500 ms each time without user input.Notes
If you'd prefer a different debounce window or want this gated behind a preference, happy to adjust.