diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java index 78c46088e9ef..765084b1748a 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java @@ -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/ */ @@ -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); } diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/PhotonUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/PhotonUtils.java index fec275791741..aa02d4c9deea 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/PhotonUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/PhotonUtils.java @@ -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 */