-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Support contact Uri #394 #1119
Conversation
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've signed it! |
CLAs look good, thanks! |
private InputStream loadResourceFromContactUri(Uri uri, ContentResolver contentResolver) | ||
throws FileNotFoundException { | ||
Uri contactUri = uri; | ||
int matchedUri = URI_MATCHER.match(contactUri); |
There was a problem hiding this comment.
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.
Nice, thank you! See my comments, treat them as idea-sparking ones, not as sacred texts = feel free to argue them ;) |
@sjudd is there any point doing this for |
Thanks a lot for your comments, it was really helpful! |
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
@@ -0,0 +1,69 @@ | |||
package com.bumptech.glide.samples.contacturi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two space indents please.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup good point, disregard.
@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. |
Also thanks for putting this up! Other than one or two minor comments looks good. |
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? |
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 :) |
Thanks! |
(minor cosmetic changes were applied and more examples added)
Forward port PR #1119: Support contact Uri
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