Skip to content

Add UriImage component for displaying images from URIs#3563

Merged
andreia-ferreira merged 1 commit intomasterfrom
uri-image-compose
Feb 18, 2026
Merged

Add UriImage component for displaying images from URIs#3563
andreia-ferreira merged 1 commit intomasterfrom
uri-image-compose

Conversation

@shobhitagarwal1612
Copy link
Copy Markdown
Member

Towards #3545

  • Implement UriImage using Coil's AsyncImage
  • Optimize image loading by calculating target dimensions based on available constraints or display metrics, capped at 2048px to prevent memory issues. This is similar to current implementation in PhotoTaskFragment

Split from #3548

@andreia-ferreira PTAL?

- Implement `UriImage` using Coil's `AsyncImage` with support for placeholders, error states, and crossfade transitions.
- Optimize image loading by calculating target dimensions based on available constraints or display metrics, capped at 2048px to prevent memory issues.
- Add `UriImageTest` to verify image loading behavior, including null URI handling, dimension scaling, and constraint coercion.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shobhitagarwal1612, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a dedicated UriImage Composable component to standardize and optimize the display of images loaded from URIs within the application. It ensures that images are loaded efficiently by intelligently determining appropriate dimensions, thereby improving performance and reducing memory consumption, especially for large images.

Highlights

  • New UriImage Component: Introduced a new UriImage Composable function that leverages Coil's AsyncImage for efficient display of images from URIs.
  • Image Loading Optimization: Implemented logic to calculate optimal image target dimensions based on available constraints or display metrics, with a maximum size of 2048px to prevent out-of-memory errors.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/src/main/java/org/groundplatform/android/ui/datacollection/components/UriImage.kt
    • Added a new UriImage Composable for displaying images from URIs.
    • Implemented image loading optimization by calculating target dimensions and capping them at MAX_IMAGE_SIZE.
    • Included placeholder and error drawable resources for image loading states.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/components/UriImageTest.kt
    • Added unit tests for UriImage to verify its behavior with null URIs, bounded sizes, large bounded sizes, and unbounded sizes.
    • Configured a custom Coil ImageLoader to capture and assert image requests.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

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 introduces a new UriImage composable for displaying images from a URI, along with corresponding tests. The implementation is sound, using Coil for image loading and optimizing for memory by resizing images. My review includes a few suggestions to improve maintainability and reusability, such as removing redundant code and making the component more flexible for accessibility purposes. I've also noted a minor issue with the copyright year in the new files, which violates the repository's style guide.

Comment on lines +57 to +64
ImageRequest.Builder(context)
.data(uri)
.size(width = targetW, height = targetH)
.scale(Scale.FIT)
.placeholder(R.drawable.ic_photo_grey_600_24dp)
.error(R.drawable.outline_error_outline_24)
.crossfade(true)
.build(),
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.

medium

The .scale(Scale.FIT) on line 60 is redundant because AsyncImage's contentScale = ContentScale.Fit (line 66) will automatically set the equivalent scale on the image request. Removing this line simplifies the code and avoids duplication.

        ImageRequest.Builder(context)
          .data(uri)
          .size(width = targetW, height = targetH)
          .placeholder(R.drawable.ic_photo_grey_600_24dp)
          .error(R.drawable.outline_error_outline_24)
          .crossfade(true)
          .build(),

.error(R.drawable.outline_error_outline_24)
.crossfade(true)
.build(),
contentDescription = stringResource(id = R.string.photo_preview),
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.

medium

The content description is currently hardcoded. This limits the component's reusability and can be problematic for accessibility in different contexts. It would be better to pass the content description as a parameter to the UriImage composable, perhaps with the current string resource used as a default.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.60%. Comparing base (fadfe47) to head (db1a3c2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...m/android/ui/datacollection/components/UriImage.kt 91.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3563      +/-   ##
============================================
+ Coverage     70.54%   70.60%   +0.05%     
  Complexity     1622     1622              
============================================
  Files           328      329       +1     
  Lines          8912     8936      +24     
  Branches        989      992       +3     
============================================
+ Hits           6287     6309      +22     
- Misses         2032     2033       +1     
- Partials        593      594       +1     
Files with missing lines Coverage Δ
...m/android/ui/datacollection/components/UriImage.kt 91.66% <91.66%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andreia-ferreira andreia-ferreira merged commit c04e0bd into master Feb 18, 2026
9 checks passed
@andreia-ferreira andreia-ferreira deleted the uri-image-compose branch February 18, 2026 17:02
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.

2 participants