X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbum.java;h=89823a81786f4158e8bc0eff21a411f3fa06217a;hb=e71cce762443757a193067b13a82fb7ae92b28b2;hp=7d22858ea63b38f207c4ea5c319058ae29cdaaae;hpb=69296993e8d1e34f03057399e30ffdd7cfb126f7;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 7d22858..89823a8 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -53,8 +53,8 @@ public class Album implements Fingerprintable { /** The description of this album. */ private String description; - /** The index of the album picture. */ - private int albumImage = -1; + /** The ID of the album picture. */ + private String albumImage; /** * Creates a new album with a random ID. @@ -166,6 +166,9 @@ public class Album implements Fingerprintable { image.getAlbum().removeImage(image); } image.setAlbum(this); + if (images.isEmpty()) { + albumImage = image.getId(); + } if (!images.containsKey(image.getId())) { images.put(image.getId(), image); } @@ -180,6 +183,13 @@ public class Album implements Fingerprintable { public void removeImage(Image image) { Validation.begin().isNotNull("Image", image).check().isEqual("Image Owner", image.getSone(), sone).check(); images.remove(image); + if (image.getId().equals(albumImage)) { + if (images.isEmpty()) { + albumImage = null; + } else { + albumImage = images.values().iterator().next().getId(); + } + } } /** @@ -189,13 +199,25 @@ public class Album implements Fingerprintable { * @return The image to show when this album is listed */ public Image getAlbumImage() { - if (albumImage == -1) { + if (albumImage == null) { return null; } return images.get(albumImage); } /** + * Sets the ID of the album image. + * + * @param id + * The ID of the album image + * @return This album + */ + public Album setAlbumImage(String id) { + this.albumImage = id; + return this; + } + + /** * Returns whether this album contains any other albums or images. * * @return {@code true} if this album is empty, {@code false} otherwise