Fixed low res artist and album images from last.fm due to a slight api change from them. New implementation should be safe upon future api changes like this.
This commit is contained in:
parent
73f3214b23
commit
3e8e34a95c
4 changed files with 106 additions and 14 deletions
|
|
@ -7,8 +7,6 @@ import android.graphics.Matrix;
|
|||
import android.graphics.Point;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
|
|
@ -93,9 +91,7 @@ public class ImageUtil {
|
|||
}
|
||||
|
||||
private static int getSmallerScreenSize(@NonNull Context c) {
|
||||
Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
Point size = Util.getScreenSize(c);
|
||||
return Math.min(size.x, size.y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
package com.kabouzeid.gramophone.util;
|
||||
|
||||
import com.kabouzeid.gramophone.lastfm.rest.model.artistinfo.Image;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class LastFMUtil {
|
||||
public enum ImageSize {
|
||||
SMALL, MEDIUM, LARGE, EXTRALARGE, MEGA, UNKNOWN
|
||||
}
|
||||
|
||||
public static String getLargestArtistImageUrl(List<Image> images) {
|
||||
Map<ImageSize, String> imageUrls = new HashMap<>();
|
||||
for (Image image : images) {
|
||||
ImageSize size = null;
|
||||
final String attribute = image.getSize();
|
||||
if (attribute == null) {
|
||||
size = ImageSize.UNKNOWN;
|
||||
} else {
|
||||
try {
|
||||
size = ImageSize.valueOf(attribute.toUpperCase(Locale.ENGLISH));
|
||||
} catch (final IllegalArgumentException e) {
|
||||
// if they suddenly again introduce a new image size
|
||||
}
|
||||
}
|
||||
if (size != null) {
|
||||
imageUrls.put(size, image.getText());
|
||||
}
|
||||
}
|
||||
return getLargestImageUrl(imageUrls);
|
||||
}
|
||||
|
||||
public static String getLargestAlbumImageUrl(List<com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.Image> images) {
|
||||
Map<ImageSize, String> imageUrls = new HashMap<>();
|
||||
for (com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.Image image : images) {
|
||||
ImageSize size = null;
|
||||
final String attribute = image.getSize();
|
||||
if (attribute == null) {
|
||||
size = ImageSize.UNKNOWN;
|
||||
} else {
|
||||
try {
|
||||
size = ImageSize.valueOf(attribute.toUpperCase(Locale.ENGLISH));
|
||||
} catch (final IllegalArgumentException e) {
|
||||
// if they suddenly again introduce a new image size
|
||||
}
|
||||
}
|
||||
if (size != null) {
|
||||
imageUrls.put(size, image.getText());
|
||||
}
|
||||
}
|
||||
return getLargestImageUrl(imageUrls);
|
||||
}
|
||||
|
||||
private static String getLargestImageUrl(Map<ImageSize, String> imageUrls) {
|
||||
if (imageUrls.containsKey(ImageSize.MEGA)) {
|
||||
return imageUrls.get(ImageSize.MEGA);
|
||||
}
|
||||
if (imageUrls.containsKey(ImageSize.EXTRALARGE)) {
|
||||
return imageUrls.get(ImageSize.EXTRALARGE);
|
||||
}
|
||||
if (imageUrls.containsKey(ImageSize.LARGE)) {
|
||||
return imageUrls.get(ImageSize.LARGE);
|
||||
}
|
||||
if (imageUrls.containsKey(ImageSize.MEDIUM)) {
|
||||
return imageUrls.get(ImageSize.MEDIUM);
|
||||
}
|
||||
if (imageUrls.containsKey(ImageSize.SMALL)) {
|
||||
return imageUrls.get(ImageSize.SMALL);
|
||||
}
|
||||
if (imageUrls.containsKey(ImageSize.UNKNOWN)) {
|
||||
return imageUrls.get(ImageSize.UNKNOWN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue