X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FAlbumAccessor.java;h=f7b6f62890094943f8e141f2582ab7fbf7ad749c;hb=62573c314957b1851f4fbe693b8746686caa940a;hp=e19a89aa8dc70b925871a27d1d102cb9c681e52c;hpb=76ed638264e531a26e35647d13702db865a52321;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 e19a89a..f7b6f62 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â2015 David Roden
+ * Sone - AlbumAccessor.java - Copyright © 2011â2016 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}
*/
@@ -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 {