added image url checking, removed redundant url type

This commit is contained in:
aj 2019-05-30 23:13:09 +01:00
parent 6904663e59
commit 73b74bcee3
2 changed files with 64 additions and 66 deletions

View File

@ -67,8 +67,8 @@ public class TopAlbumController {
for (int i = 1; i < 16; i++) { for (int i = 1; i < 16; i++) {
dropDownLimit.getItems().add(i); dropDownLimit.getItems().add(i);
} }
for (int i = 20; i < 110; i+=10) { for (int i = 20; i < 110; i += 10) {
dropDownLimit.getItems().add(i); dropDownLimit.getItems().add(i);
} }
@ -169,23 +169,26 @@ public class TopAlbumController {
Album album = (Album) obj; Album album = (Album) obj;
GetFXImageService service = new GetFXImageService(album.getImageURL().toString(), counter); if (album.getImageURL() != null) {
service.setOnSucceeded(new EventHandler<WorkerStateEvent>() { GetFXImageService service = new GetFXImageService(album.getImageURL(), counter);
@Override service.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
public void handle(WorkerStateEvent t) {
TiledImage image = (TiledImage) t.getSource().getValue(); @Override
public void handle(WorkerStateEvent t) {
images.add(image);
refreshImages();
}
});
service.start(); TiledImage image = (TiledImage) t.getSource().getValue();
counter++;
images.add(image);
refreshImages();
}
});
service.start();
counter++;
}
} }
} }
} }
@ -196,17 +199,17 @@ public class TopAlbumController {
ObservableList<Node> list = tilePane.getChildren(); ObservableList<Node> list = tilePane.getChildren();
list.clear(); list.clear();
Collections.sort(images, new Comparator<TiledImage>() { Collections.sort(images, new Comparator<TiledImage>() {
@Override @Override
public int compare(TiledImage arg0, TiledImage arg1) { public int compare(TiledImage arg0, TiledImage arg1) {
return arg0.getIndex() - arg1.getIndex(); return arg0.getIndex() - arg1.getIndex();
} }
}); });
for(TiledImage image: images) { for (TiledImage image : images) {
list.add(new ImageView(image)); list.add(new ImageView(image));
} }
} }

View File

@ -11,53 +11,53 @@ import javax.imageio.ImageIO;
import sarsoo.fmframework.cache.Cacheable; import sarsoo.fmframework.cache.Cacheable;
public class Album extends FMObj implements Serializable, Cacheable{ public class Album extends FMObj implements Serializable, Cacheable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
protected Artist artist; protected Artist artist;
protected ArrayList<Tag> tagList; protected ArrayList<Tag> tagList;
protected ArrayList<Track> trackList; protected ArrayList<Track> trackList;
protected URL imageUrl; protected String imageUrl;
protected BufferedImage image; protected BufferedImage image;
private Album(AlbumBuilder builder) { private Album(AlbumBuilder builder) {
this.name = builder.name; this.name = builder.name;
this.artist = builder.artist; this.artist = builder.artist;
this.url = builder.url; this.url = builder.url;
this.listeners = builder.listeners; this.listeners = builder.listeners;
this.playCount = builder.playCount; this.playCount = builder.playCount;
this.userPlayCount = builder.userPlayCount; this.userPlayCount = builder.userPlayCount;
this.wiki = builder.wiki; this.wiki = builder.wiki;
this.mbid = builder.mbid; this.mbid = builder.mbid;
this.tagList = builder.tagList; this.tagList = builder.tagList;
this.trackList = builder.trackList; this.trackList = builder.trackList;
this.imageUrl = builder.imageUrl; this.imageUrl = builder.imageUrl;
} }
public URL getImageURL() { public String getImageURL() {
return imageUrl; return imageUrl;
} }
public void loadImage() { public void loadImage() {
try { try {
image = ImageIO.read(imageUrl); image = ImageIO.read(new URL(imageUrl));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public BufferedImage getImage() { public BufferedImage getImage() {
return image; return image;
} }
public Artist getArtist() { public Artist getArtist() {
return artist; return artist;
} }
@ -94,83 +94,78 @@ public class Album extends FMObj implements Serializable, Cacheable{
return "Album: " + name + " - " + artist.getName(); return "Album: " + name + " - " + artist.getName();
} }
public static class AlbumBuilder{ public static class AlbumBuilder {
protected String name; protected String name;
protected Artist artist; protected Artist artist;
protected String url; protected String url;
protected int listeners; protected int listeners;
protected int playCount; protected int playCount;
protected int userPlayCount; protected int userPlayCount;
protected Wiki wiki; protected Wiki wiki;
protected String mbid; protected String mbid;
protected ArrayList<Tag> tagList; protected ArrayList<Tag> tagList;
protected ArrayList<Track> trackList; protected ArrayList<Track> trackList;
protected URL imageUrl; protected String imageUrl;
public AlbumBuilder(String name, Artist artist) { public AlbumBuilder(String name, Artist artist) {
this.name = name; this.name = name;
this.artist = artist; this.artist = artist;
} }
public AlbumBuilder setUrl(String url) { public AlbumBuilder setUrl(String url) {
this.url = url; this.url = url;
return this; return this;
} }
public AlbumBuilder setListeners(int listeners) { public AlbumBuilder setListeners(int listeners) {
this.listeners = listeners; this.listeners = listeners;
return this; return this;
} }
public AlbumBuilder setPlayCount(int playCount) { public AlbumBuilder setPlayCount(int playCount) {
this.playCount = playCount; this.playCount = playCount;
return this; return this;
} }
public AlbumBuilder setUserPlayCount(int userPlayCount) { public AlbumBuilder setUserPlayCount(int userPlayCount) {
this.userPlayCount = userPlayCount; this.userPlayCount = userPlayCount;
return this; return this;
} }
public AlbumBuilder setWiki(Wiki wiki) { public AlbumBuilder setWiki(Wiki wiki) {
this.wiki = wiki; this.wiki = wiki;
return this; return this;
} }
public AlbumBuilder setMbid(String Mbid) { public AlbumBuilder setMbid(String Mbid) {
this.mbid = Mbid; this.mbid = Mbid;
return this; return this;
} }
public AlbumBuilder setTagList(ArrayList<Tag> tagList) { public AlbumBuilder setTagList(ArrayList<Tag> tagList) {
this.tagList = tagList; this.tagList = tagList;
return this; return this;
} }
public AlbumBuilder setTrackList(ArrayList<Track> trackList) { public AlbumBuilder setTrackList(ArrayList<Track> trackList) {
this.trackList = trackList; this.trackList = trackList;
return this; return this;
} }
public AlbumBuilder setImageUrl(String url) { public AlbumBuilder setImageUrl(String url) {
try { this.imageUrl = url;
this.imageUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return this; return this;
} }
public Album build() { public Album build() {
return new Album(this); return new Album(this);
} }
@ -178,10 +173,10 @@ public class Album extends FMObj implements Serializable, Cacheable{
@Override @Override
public ArrayList<Scrobble> getScrobbles() { public ArrayList<Scrobble> getScrobbles() {
if(trackList != null) { if (trackList != null) {
if (trackList.size() > 0) { if (trackList.size() > 0) {
ArrayList<Scrobble> scrobbles = new ArrayList<Scrobble>(); ArrayList<Scrobble> scrobbles = new ArrayList<Scrobble>();
for (Track i: trackList) { for (Track i : trackList) {
scrobbles.addAll(i.getScrobbles()); scrobbles.addAll(i.getScrobbles());
} }
return scrobbles; return scrobbles;