Skip to content

Take screen density into account when requesting thumbnails #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2023

Conversation

jmartinesp
Copy link
Member

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Have CoilMediaFetcher calculate the right size to ask for thumbnails using the screen density.

Motivation and context

Fixes issues seen with blurry avatars on some homeservers.

Screenshots / GIFs

Before After
image image

Tests

  • Log in to element.io.
  • Check avatar images.

They should look a lot shaper.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 11

Checklist

Otherwise, we could be asking for images with N size while we needed images for N@2x or N@3x size i.e.
@jmartinesp jmartinesp requested a review from a team as a code owner September 8, 2023 12:23
@jmartinesp jmartinesp requested review from bmarty and removed request for a team September 8, 2023 12:23
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2023

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/FS8iLq

@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.02% ⚠️

Comparison is base (5a0e0a8) 57.65% compared to head (e7e41b0) 57.64%.
Report is 23 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1262      +/-   ##
===========================================
- Coverage    57.65%   57.64%   -0.02%     
===========================================
  Files         1081     1081              
  Lines        28041    28046       +5     
  Branches      5777     5777              
===========================================
  Hits         16167    16167              
- Misses        9350     9355       +5     
  Partials      2524     2524              
Files Changed Coverage Δ
...roid/libraries/matrix/ui/media/CoilMediaFetcher.kt 0.00% <0.00%> (ø)
.../libraries/matrix/ui/media/ImageLoaderFactories.kt 0.00% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Thanks for looking at this.

Don't you think the fix should be located at the call site?

For instance here: https://github.com/vector-im/element-x-android/blob/develop/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/AvatatarDataExt.kt#L26

We should pass a pixel size instead of a DP size. Maybe more complicated though...

@jmartinesp
Copy link
Member Author

Yes, that was my first idea, but to add it there we'd either have to make that function @Composable or pass either a context or a density value. And if instead of storing the dp size in AvatarSize we wanted the pixel one we'd have to do it when those are created, and given it's an enum class that would be quite convoluted to make it work.

Placing this calculation in the fetcher seemed like the best compromise.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

OK, thanks for explanation!

add(CoilMediaFetcher.AvatarFactory(matrixClient))
add(CoilMediaFetcher.MediaRequestDataFactory(matrixClient))
add(CoilMediaFetcher.AvatarFactory(context, matrixClient))
add(CoilMediaFetcher.MediaRequestDataFactory(context, matrixClient))
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but instead of passing the whole context, can we just pass the screen density here?
Not sure that this can change over time, but maybe (with battery saver mode which simulate low density screen).

Or maybe just context.resources.displayMetrics.

I am definitely thinking out loud ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I'm wondering about what would happen if we passed it here and then changed the settings for display element scaling in the OS. Maybe we should pass a lambda or a wrapper DensityProvider class that hides the context?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in e7e41b0.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

OK, thanks!

@jmartinesp jmartinesp merged commit e6ecedf into develop Sep 11, 2023
@jmartinesp jmartinesp deleted the fix/jme/use-density-when-fetching-thumbnails branch September 11, 2023 13:24
@bmarty bmarty mentioned this pull request Sep 12, 2023
14 tasks
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