Created
December 15, 2017 15:27
-
-
Save communikein/0f419801cf9514ab35ec368480728077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class ProfilePictureLoader extends ImageLoader { | |
private User mUser; | |
public ProfilePictureLoader(User user, RequestQueue queue, ImageCache imageCache) { | |
super(queue, imageCache); | |
this.mUser = user; | |
} | |
@Override | |
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, | |
int maxHeight, ImageView.ScaleType scaleType, | |
final String cacheKey) { | |
ProfilePictureRequest request = new ProfilePictureRequest(mUser, new Response.Listener<Bitmap>() { | |
@Override | |
public void onResponse(Bitmap response) { | |
onGetImageSuccess(cacheKey, response); | |
} | |
}, maxWidth, maxHeight, scaleType, Bitmap.Config.RGB_565, new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
onGetImageError(cacheKey, error); | |
String cookie = error.networkResponse.headers.get("Set-Cookie"); | |
if (cookie != null && cookie.contains("sessionid")) { | |
// Save it | |
cookie = cookie.substring(cookie.indexOf("sessionid=") + 11); | |
cookie = cookie.substring(0, cookie.indexOf(";")); | |
mUser.setSessionID(cookie); | |
} | |
} | |
}); | |
request.setRetryPolicy(new DefaultRetryPolicy( | |
0, | |
1, | |
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); | |
return request; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment