Skip to content

Enhance MediaRepository with reactive flow and update ImageWell animation#531

Open
temcguir wants to merge 13 commits into
mainfrom
temcguir/imagewell_uistate_refactor
Open

Enhance MediaRepository with reactive flow and update ImageWell animation#531
temcguir wants to merge 13 commits into
mainfrom
temcguir/imagewell_uistate_refactor

Conversation

@temcguir

@temcguir temcguir commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

This PR refactors the media data layer to support a reactive unidirectional data flow, enhances the capture UI with improved animations, and addresses b/522926012 by supporting dynamic file prefixes.

Core Changes:

  • Reactive MediaRepository: Updated LocalMediaRepository to expose a lastCapturedMedia StateFlow. It now automatically initializes with the latest app-captured media and reacts to MediaStore changes.
  • Thread Safety: Added a Mutex to LocalMediaRepository to synchronize access to the media cache and prevent race conditions during concurrent MediaStore updates.
  • Dynamic File Prefix (Fixes b/522926012): Exposed a prefix property in FilePathGenerator. LocalMediaRepository now uses this prefix dynamically when querying the MediaStore, allowing it to correctly identify app-captured media even when a custom generator (e.g., for Google Photos) is used.
  • Refined Ownership Check: Updated the repository to strictly use OWNER_PACKAGE_NAME on Android Q+ for identifying app-specific media, falling back to the filename prefix only on older versions.
  • Enhanced ImageWell UI: Replaced the static thumbnail display with an AnimatedContent transition that performs a "vertical push" animation whenever the last captured media updates.
  • Simplified Testing: Refactored FakeMediaRepository to use a direct StateFlow, avoiding unmanaged coroutine scopes and potential leaks in tests.

Verified:

  • Built :data:media and :ui:components:capture successfully.
  • Formatting verified with spotlessApply.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the media repository to expose the last captured media as a continuous StateFlow (lastCapturedMedia) instead of a suspend function, and updates the ImageWell UI component to observe this flow with smoother transition animations. It also enhances the testing infrastructure, including FakeContentProvider and LocalMediaRepositoryTest. The review feedback identifies a potential race condition in LocalMediaRepository due to unsynchronized cache access, suggests a more robust package ownership check on Android Q+, and recommends simplifying the flow implementation in FakeMediaRepository to prevent coroutine leaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant