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 contact Uri #394 #1119

Merged
merged 1 commit into from
Apr 18, 2016
Merged

Support contact Uri #394 #1119

merged 1 commit into from
Apr 18, 2016

Conversation

R4md4c
Copy link

@R4md4c R4md4c commented Apr 7, 2016

So I've supported these kind of Uris for issue #394 , also wrote a simple sample for this feature.

content://com.android.contacts/contacts/5/display_photo
content://com.android.contacts/contacts/lookup/3570i61d948d30808e537
content://com.android.contacts/contacts/38
content://com.android.contacts/contacts/lookup/3570i61d948d30808e537

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@R4md4c
Copy link
Author

R4md4c commented Apr 7, 2016

I've signed it!

@googlebot
Copy link

CLAs look good, thanks!

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 83.137% when pulling 696f86c on R4md4c:3.0 into cb47a64 on bumptech:3.0.

private InputStream loadResourceFromContactUri(Uri uri, ContentResolver contentResolver)
throws FileNotFoundException {
Uri contactUri = uri;
int matchedUri = URI_MATCHER.match(contactUri);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think match() result could be passed in, it's enough to parse the Uri once.

@TWiStErRob TWiStErRob added this to the 3.8.0 milestone Apr 7, 2016
@TWiStErRob
Copy link
Collaborator

Nice, thank you!

See my comments, treat them as idea-sparking ones, not as sacred texts = feel free to argue them ;)

@TWiStErRob
Copy link
Collaborator

@sjudd is there any point doing this for FileDescriptorLocalUriFetcher too?

@R4md4c
Copy link
Author

R4md4c commented Apr 8, 2016

@TWiStErRob

Thanks a lot for your comments, it was really helpful!
I changed the code so that the .match() call happens only once, instead of several times.

public StreamLocalUriFetcher(Context context, Uri uri) {
super(context, uri);
}

@Override
protected InputStream loadResource(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
final int matchedUri = URI_MATCHER.match(uri);
if (matchedUri != UriMatcher.NO_MATCH) {
return loadResourceFromContactUri(uri, contentResolver, matchedUri);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about inlining this call to simplify?
matchedUri == UriMatcher.NO_MATCH is the same as the default in the switch.

Copy link
Author

Choose a reason for hiding this comment

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

I'm thinking of doing something like

return matchedUri != UriMatcher.NO_MATCH ? loadResourceFromContactUri(uri, contentResolver, matchedUri)  : contentResolver.openInputStream(uri);

What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not nice to read, consider:

switch (URI_MATCHER.match(uri)) {
    case ID_LOOKUP:
    case ID_CONTACT: {
        Uri contactUri = uri;
        ...
        return openContactPhotoInputStream(contentResolver, contactUri);
    }
    case ID_THUMBNAIL:
    case ID_DISPLAY_PHOTO:
    case UriMatcher.NO_MATCH:
    default:
        return contentResolver.openInputStream(uri);
}

this is what happens anyway, just with bigger cyclomatic complexity and duplicated call to openInputStream.

Copy link
Author

Choose a reason for hiding this comment

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

I've updated the PR, into to your more simplified version.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 83.229% when pulling 89454c6 on R4md4c:3.0 into cb47a64 on bumptech:3.0.

@@ -0,0 +1,69 @@
package com.bumptech.glide.samples.contacturi;
Copy link
Collaborator

Choose a reason for hiding this comment

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

two space indents please.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is v3, didn't you introduce Google style in v4?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup good point, disregard.

@sjudd
Copy link
Collaborator

sjudd commented Apr 9, 2016

@TWiStErRob No need to do this for file descriptors, at least not right now. They're currently only used for loading videos. That said, I actually think they'd be more efficient than InputStreams for local content retrieved via a a ContentResolver, so we may revisit that in the future.

@sjudd
Copy link
Collaborator

sjudd commented Apr 9, 2016

Also thanks for putting this up! Other than one or two minor comments looks good.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 83.229% when pulling 4f633ec on R4md4c:3.0 into cb47a64 on bumptech:3.0.

@R4md4c
Copy link
Author

R4md4c commented Apr 13, 2016

Hi @TWiStErRob,

It is been 4 days since the last patch, but I haven't heard any feedback from you, is there something missing from my side?

@TWiStErRob
Copy link
Collaborator

Oh, sorry, I'm ok with it, but @sjudd has the final word (=presses the merge button). He said those two nits, which you fixed, but we don't get notifications for force push commits (nor normal commits for that matter), you have to comment manually, which you've done now :)

@sjudd
Copy link
Collaborator

sjudd commented Apr 18, 2016

Thanks!

@sjudd sjudd merged commit 77c3101 into bumptech:3.0 Apr 18, 2016
@TWiStErRob TWiStErRob mentioned this pull request May 20, 2016
TWiStErRob added a commit to TWiStErRob/glide that referenced this pull request Jul 10, 2016
(minor cosmetic changes were applied and more examples added)
sjudd added a commit that referenced this pull request Jul 11, 2016
Forward port PR #1119: Support contact Uri
@R4md4c R4md4c deleted the 3.0 branch February 16, 2019 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants