Skip to content
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

Support loading images from AssetManager #10

Closed
ianhanniballake opened this issue Aug 13, 2019 · 4 comments · Fixed by #12
Closed

Support loading images from AssetManager #10

ianhanniballake opened this issue Aug 13, 2019 · 4 comments · Fixed by #12
Labels
enhancement New feature or request

Comments

@ianhanniballake
Copy link
Contributor

Is your feature request related to a problem? Please describe.
There's a very specific type of Uri on Android in the form of file:///android_asset/your_asset.jpg which, despite its file:// prefix, cannot be opened with ContentResolver.openInputStream() but instead must be opened using AssetManager.

This is true for all Uris in the form of ContentResolver.SCHEME_FILE + ":///android_asset/".

Describe the solution you'd like
I'd like to be able to use:

imageView.load("file:///android_asset/starrynight.jpg")

And have it automatically use AssetManager. I'd also be fine with using the load(Uri) version, although that would be a difference from Picasso and Glide (see examples below).

Additional context
Assets are already supported by Picasso:

 Picasso.get().load("file:///android_asset/starrynight.png").into(imageView)

and Glide

Glide.with(this).load("file:///android_asset/starrynight.jpg").into(imageView)
@ianhanniballake ianhanniballake added the enhancement New feature or request label Aug 13, 2019
@colinrtwhite
Copy link
Member

colinrtwhite commented Aug 13, 2019

Interesting! imageView.load(String) is currently reserved for HTTP URLs, but we should at least support imageView.load(Uri.parse("file:///android_asset/starrynight.jpg")). I think we could make the necessary changes in UriFetcher. I'll make a quick PR.

@ianhanniballake
Copy link
Contributor Author

load(Uri) support would be great, thanks!

It seems like in other image loading libraries, load(uri: String) = load(Uri.parse(uri)) in all cases and they share the same underlying processing. This ensures that no matter if developers use a String or Uri, the same rules apply, avoiding all cases where developers need to remember to htmlUri.toString() or Uri.parse(contentUriString). Probably worth a separate FR than this as that would be a wider issue than this particular case.

@colinrtwhite
Copy link
Member

colinrtwhite commented Aug 13, 2019

Good point. Currently, Coil uses url as the named param for load(String) so we'd have to change that to something more general (but hopefully not too general like data; let me know if you have suggestions), but I like the idea of supporting Uris and Urls via load(String).

We could support this by writing a new Mapper or modifying HttpUrlMapper.

@colinrtwhite
Copy link
Member

Created a new issue to support parsing Strings as Uris here: #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants