Skip to content

Commit

Permalink
Moved fixAvatar routine to GravatarUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Feb 10, 2015
1 parent d132f67 commit 06e9f21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.wordpress.android.util;

public class GravatarUtils {
import android.text.TextUtils;

public class GravatarUtils {
/*
* see https://en.gravatar.com/site/implement/images/
*/
Expand Down Expand Up @@ -36,6 +37,24 @@ public String toString() {
}
}

/*
* gravatars often contain the ?s= parameter which determines their size - detect this and
* replace it with a new ?s= parameter which requests the avatar at the exact size needed
*/
public static String fixGravatarUrl(final String imageUrl, int avatarSz) {
if (TextUtils.isEmpty(imageUrl)) {
return "";
}

// if this isn't a gravatar image, return as resized photon image url
if (!imageUrl.contains("gravatar.com")) {
return PhotonUtils.getPhotonImageUrl(imageUrl, avatarSz, avatarSz);
}

// remove all other params, then add query string for size and "mystery man" default
return UrlUtils.removeQuery(imageUrl) + "?s=" + avatarSz + "&d=mm";
}

public static String gravatarFromEmail(final String email, int size) {
return gravatarFromEmail(email, size, DefaultImage.MYSTERY_MAN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@ private PhotonUtils() {
throw new AssertionError();
}

/*
* gravatars often contain the ?s= parameter which determines their size - detect this and
* replace it with a new ?s= parameter which requests the avatar at the exact size needed
*/
public static String fixAvatar(final String imageUrl, int avatarSz) {
if (TextUtils.isEmpty(imageUrl))
return "";

// if this isn't a gravatar image, return as resized photon image url
if (!imageUrl.contains("gravatar.com")) {
return getPhotonImageUrl(imageUrl, avatarSz, avatarSz);
}

// remove all other params, then add query string for size and "mystery man" default
return UrlUtils.removeQuery(imageUrl) + "?s=" + avatarSz + "&d=mm";
}

/*
* returns true if the passed url is an obvious "mshots" url
*/
Expand Down

0 comments on commit 06e9f21

Please sign in to comment.