Skip to content

Commit 06e9f21

Browse files
committed
Moved fixAvatar routine to GravatarUtils
1 parent d132f67 commit 06e9f21

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.wordpress.android.util;
22

3-
public class GravatarUtils {
3+
import android.text.TextUtils;
44

5+
public class GravatarUtils {
56
/*
67
* see https://en.gravatar.com/site/implement/images/
78
*/
@@ -36,6 +37,24 @@ public String toString() {
3637
}
3738
}
3839

40+
/*
41+
* gravatars often contain the ?s= parameter which determines their size - detect this and
42+
* replace it with a new ?s= parameter which requests the avatar at the exact size needed
43+
*/
44+
public static String fixGravatarUrl(final String imageUrl, int avatarSz) {
45+
if (TextUtils.isEmpty(imageUrl)) {
46+
return "";
47+
}
48+
49+
// if this isn't a gravatar image, return as resized photon image url
50+
if (!imageUrl.contains("gravatar.com")) {
51+
return PhotonUtils.getPhotonImageUrl(imageUrl, avatarSz, avatarSz);
52+
}
53+
54+
// remove all other params, then add query string for size and "mystery man" default
55+
return UrlUtils.removeQuery(imageUrl) + "?s=" + avatarSz + "&d=mm";
56+
}
57+
3958
public static String gravatarFromEmail(final String email, int size) {
4059
return gravatarFromEmail(email, size, DefaultImage.MYSTERY_MAN);
4160
}

WordPressUtils/src/main/java/org/wordpress/android/util/PhotonUtils.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,6 @@ private PhotonUtils() {
1212
throw new AssertionError();
1313
}
1414

15-
/*
16-
* gravatars often contain the ?s= parameter which determines their size - detect this and
17-
* replace it with a new ?s= parameter which requests the avatar at the exact size needed
18-
*/
19-
public static String fixAvatar(final String imageUrl, int avatarSz) {
20-
if (TextUtils.isEmpty(imageUrl))
21-
return "";
22-
23-
// if this isn't a gravatar image, return as resized photon image url
24-
if (!imageUrl.contains("gravatar.com")) {
25-
return getPhotonImageUrl(imageUrl, avatarSz, avatarSz);
26-
}
27-
28-
// remove all other params, then add query string for size and "mystery man" default
29-
return UrlUtils.removeQuery(imageUrl) + "?s=" + avatarSz + "&d=mm";
30-
}
31-
3215
/*
3316
* returns true if the passed url is an obvious "mshots" url
3417
*/

0 commit comments

Comments
 (0)