X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FImageBrowserPage.java;h=1e881cf2abc8b5ef4774601bb4cd37ad24b3a2d0;hb=414ee1b03f7155ccb5049ede303dd01020ddcd94;hp=d0a446f1eb30c484aeebd5c7442deb09322a6455;hpb=8f02544d31f323ae9053dd9a11a99eacd8cf5bcd;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java index d0a446f..1e881cf 100644 --- a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java @@ -17,6 +17,11 @@ package net.pterodactylus.sone.web; +import static com.google.common.collect.FluentIterable.from; +import static net.pterodactylus.sone.data.Album.FLATTENER; +import static net.pterodactylus.sone.data.Album.NOT_EMPTY; +import static net.pterodactylus.sone.data.Album.TITLE_COMPARATOR; + import java.net.URI; import java.util.ArrayList; import java.util.Collections; @@ -31,6 +36,8 @@ import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.base.Optional; + /** * The image browser page is the entry page for the image management. * @@ -62,24 +69,24 @@ public class ImageBrowserPage extends SoneTemplatePage { super.processTemplate(request, templateContext); String albumId = request.getHttpRequest().getParam("album", null); if (albumId != null) { - Album album = webInterface.getCore().getAlbum(albumId, false); + Optional album = webInterface.getCore().getAlbum(albumId); templateContext.set("albumRequested", true); - templateContext.set("album", album); + templateContext.set("album", album.orNull()); templateContext.set("page", request.getHttpRequest().getParam("page")); return; } String imageId = request.getHttpRequest().getParam("image", null); if (imageId != null) { - Image image = webInterface.getCore().getImage(imageId, false); + Optional image = webInterface.getCore().getImage(imageId); templateContext.set("imageRequested", true); - templateContext.set("image", image); + templateContext.set("image", image.orNull()); return; } String soneId = request.getHttpRequest().getParam("sone", null); if (soneId != null) { - Sone sone = webInterface.getCore().getSone(soneId); + Optional sone = webInterface.getCore().getSone(soneId); templateContext.set("soneRequested", true); - templateContext.set("sone", sone); + templateContext.set("sone", sone.orNull()); return; } String mode = request.getHttpRequest().getParam("mode", null); @@ -87,9 +94,9 @@ public class ImageBrowserPage extends SoneTemplatePage { templateContext.set("galleryRequested", true); List albums = new ArrayList(); for (Sone sone : webInterface.getCore().getSones()) { - albums.addAll(sone.getAllAlbums()); + albums.addAll(from(sone.getRootAlbum().getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY).toList()); } - Collections.sort(albums, Album.TITLE_COMPARATOR); + Collections.sort(albums, TITLE_COMPARATOR); Pagination albumPagination = new Pagination(albums, 12).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("albumPagination", albumPagination); templateContext.set("albums", albumPagination.getItems());