2018-07-27 13:07:33 +00:00
|
|
|
package code.name.monkey.retromusic.util;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
import code.name.monkey.retromusic.rest.model.LastFmAlbum.Album.Image;
|
|
|
|
import code.name.monkey.retromusic.rest.model.LastFmArtist;
|
|
|
|
|
2018-07-27 13:07:33 +00:00
|
|
|
public class LastFMUtil {
|
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
public static String getLargestAlbumImageUrl(List<Image> list) {
|
|
|
|
Map hashMap = new HashMap();
|
|
|
|
for (Image image : list) {
|
|
|
|
Object obj = null;
|
|
|
|
String size = image.getSize();
|
|
|
|
if (size == null) {
|
|
|
|
obj = ImageSize.UNKNOWN;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
obj = ImageSize.valueOf(size.toUpperCase(Locale.ENGLISH));
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (obj != null) {
|
|
|
|
hashMap.put(obj, image.getText());
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
}
|
2018-08-22 17:54:07 +00:00
|
|
|
return getLargestImageUrl(hashMap);
|
2018-07-27 13:07:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
public static String getLargestArtistImageUrl(List<LastFmArtist.Artist.Image> list) {
|
|
|
|
Map hashMap = new HashMap();
|
|
|
|
for (LastFmArtist.Artist.Image image : list) {
|
|
|
|
Object obj = null;
|
|
|
|
String size = image.getSize();
|
|
|
|
if (size == null) {
|
|
|
|
obj = ImageSize.UNKNOWN;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
obj = ImageSize.valueOf(size.toUpperCase(Locale.ENGLISH));
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (obj != null) {
|
|
|
|
hashMap.put(obj, image.getText());
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
}
|
2018-08-22 17:54:07 +00:00
|
|
|
return getLargestImageUrl(hashMap);
|
2018-07-27 13:07:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
private static String getLargestImageUrl(Map<ImageSize, String> map) {
|
|
|
|
return map.containsKey(ImageSize.MEGA) ? map.get(ImageSize.MEGA)
|
|
|
|
: map.containsKey(ImageSize.EXTRALARGE) ? map.get(ImageSize.EXTRALARGE)
|
|
|
|
: map.containsKey(ImageSize.LARGE) ? map.get(ImageSize.LARGE)
|
2018-07-27 13:07:33 +00:00
|
|
|
: map.containsKey(ImageSize.MEDIUM) ? map.get(ImageSize.MEDIUM)
|
2018-08-22 17:54:07 +00:00
|
|
|
: map.containsKey(ImageSize.SMALL) ? map.get(ImageSize.SMALL)
|
|
|
|
: map.containsKey(ImageSize.UNKNOWN) ? map.get(ImageSize.UNKNOWN) : null;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
private enum ImageSize {
|
|
|
|
SMALL,
|
|
|
|
MEDIUM,
|
|
|
|
LARGE,
|
|
|
|
EXTRALARGE,
|
|
|
|
MEGA,
|
|
|
|
UNKNOWN
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
}
|