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=d0d078b4422b72a18c4bd7caaad4dc4ff10161cd;hpb=17da32be452acc7e110801fb04bf155bf0587224;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 d0d078b..89823a8 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -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(); + } + } } /** @@ -196,6 +206,18 @@ public class Album implements Fingerprintable { } /** + * 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