X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FAlbumAccessor.java;h=19b600e56b539d016baedd7fbad4304c63fb0ef2;hb=b4d2d68b5ea4f4edc7337f380cfe078756678126;hp=9ef168a04c159d8fb1070579539c38c4af7f570a;hpb=32b480995d93941cd6ba7b3f0889141d3f610d84;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java
index 9ef168a..19b600e 100644
--- a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java
+++ b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java
@@ -1,5 +1,5 @@
/*
- * Sone - AlbumAccessor.java - Copyright © 2011â2013 David Roden
+ * Sone - AlbumAccessor.java - Copyright © 2011â2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,8 +19,10 @@ package net.pterodactylus.sone.template;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Image;
import net.pterodactylus.util.template.Accessor;
import net.pterodactylus.util.template.ReflectionAccessor;
import net.pterodactylus.util.template.TemplateContext;
@@ -29,11 +31,11 @@ import net.pterodactylus.util.template.TemplateContext;
* {@link Accessor} implementation for {@link Album}s. A property named
* âbacklinksâ is added, it returns links to all parents and the owner Sone of
* an album.
- *
- * @author David âBombeâ Roden
*/
public class AlbumAccessor extends ReflectionAccessor {
+ private final Random random = new Random();
+
/**
* {@inheritDoc}
*/
@@ -41,7 +43,7 @@ public class AlbumAccessor extends ReflectionAccessor {
public Object get(TemplateContext templateContext, Object object, String member) {
Album album = (Album) object;
if ("backlinks".equals(member)) {
- List backlinks = new ArrayList();
+ List backlinks = new ArrayList<>();
Album currentAlbum = album;
while (!currentAlbum.isRoot()) {
backlinks.add(0, new Link("imageBrowser.html?album=" + currentAlbum.getId(), currentAlbum.getTitle()));
@@ -49,14 +51,15 @@ public class AlbumAccessor extends ReflectionAccessor {
}
backlinks.add(0, new Link("imageBrowser.html?sone=" + album.getSone().getId(), SoneAccessor.getNiceName(album.getSone())));
return backlinks;
+ } else if ("albumImage".equals(member)) {
+ List images = album.getImages();
+ return images.isEmpty() ? null : images.get(random.nextInt(images.size()));
}
return super.get(templateContext, object, member);
}
/**
* Container for links.
- *
- * @author David âBombeâ Roden
*/
private static class Link {