From bf9834a155b94be28ae75710c7beb827b7f7ea39 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 10 Feb 2015 12:51:59 -0500 Subject: [PATCH] Added DefaultImage enum to GravatarUtils --- .../wordpress/android/util/GravatarUtils.java | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) 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 3d8890802f5a..78c46088e9ef 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/GravatarUtils.java @@ -1,22 +1,55 @@ package org.wordpress.android.util; public class GravatarUtils { + /* * see https://en.gravatar.com/site/implement/images/ */ + + public static enum DefaultImage { + MYSTERY_MAN, + STATUS_404, + IDENTICON, + MONSTER, + WAVATAR, + RETRO, + BLANK; + + @Override + public String toString() { + switch (this) { + case MYSTERY_MAN: + return "mm"; + case STATUS_404: + return "404"; + case IDENTICON: + return "identicon"; + case MONSTER: + return "monsterid"; + case WAVATAR: + return "wavatar"; + case RETRO: + return "retro"; + default: + return "blank"; + } + } + } + public static String gravatarFromEmail(final String email, int size) { + return gravatarFromEmail(email, size, DefaultImage.MYSTERY_MAN); + } + public static String gravatarFromEmail(final String email, int size, DefaultImage defaultImage) { return "http://gravatar.com/avatar/" + StringUtils.getMd5Hash(StringUtils.notNullStr(email)) - + "?d=mm&size=" + Integer.toString(size); + + "?d=" + defaultImage.toString() + + "&size=" + Integer.toString(size); } - /* - * important: the 404 default means the request will 404 if there is no blavatar - * for the passed site - so the caller needs to trap the 404 to provide a default - */ - public static String blavatarFromUrl(final String url, int size) { + public static String blavatarFromUrl(final String url, int size, DefaultImage defaultImage) { return "http://gravatar.com/blavatar/" + StringUtils.getMd5Hash(UrlUtils.getDomainFromUrl(url)) - + "?d=404&size=" + Integer.toString(size); + + "?d=" + defaultImage.toString() + + "&size=" + Integer.toString(size); } }