Skip to content

Instantly share code, notes, and snippets.

@shakdwipeea
Created January 3, 2017 07:13
Show Gist options
  • Save shakdwipeea/558e64d6c707d9f9176d735df5300fd7 to your computer and use it in GitHub Desktop.
Save shakdwipeea/558e64d6c707d9f9176d735df5300fd7 to your computer and use it in GitHub Desktop.
get high res picture from social profiles
/**
* used for fb AuthService provides Observables with gives the profile pic,
* this function uses that observable to display the profile pic
* @param profilePicObservable Observable that provides url for high res profile pic
*/
private void displayPic(Observable<String> profilePicObservable) {
profilePicObservable
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(
url -> {
//saveProfilePicture(url);
profileView.displayProfilePic(url);
},
Throwable::printStackTrace
);
}
/**
* the profile pic url in case of twitter is sth like
* http://pbs.twimg.com/profile_images/463646119960920064/_lMH5iFt_normal.jpeg
*
* Omit the underscore and variant to retrieve the original image.
* NOTE THE IMAGE CAN BE VERY LARGE
* todo use cloudinary stuff instead
*
* @param lowResUrl the default low res image
* @return highResUrl
*/
private String parseTwitterUrl(String lowResUrl) {
return lowResUrl.replace("_normal", "");
}
/**
* google returns the profile url as
* https://lh5.googleusercontent.com/-GoXxObG2mVE/AAAAAAAAAAI/AAAAAAAABFY/PzVrrZdkQYQ/s96-c/photo.jpg
* here 96 is the width and height, to get a full res we can put our required dimensions
* and request
* todo use cloudinary stuff instead
*
* @param lowResUrl The default low res url
*/
private String parseGoogleUrl(String lowResUrl) {
// find the dimension and change it to 400dp
String[] urlParts = lowResUrl.split("/");
String dimPart = urlParts[urlParts.length - 2];
String[] dimValue = dimPart.split("-");
dimValue[0] = "s400";
// recreate the url
urlParts[urlParts.length - 2] = TextUtils.join("-", dimValue);
return TextUtils.join("/", urlParts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment