package net.pterodactylus.sone.web;
+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;
import java.util.List;
+import com.google.common.base.Optional;
+import com.google.common.collect.FluentIterable;
+
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Sone;
}
String soneId = request.getHttpRequest().getParam("sone", null);
if (soneId != null) {
- Sone sone = webInterface.getCore().getSone(soneId);
+ Optional<Sone> 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);
templateContext.set("galleryRequested", true);
List<Album> albums = new ArrayList<Album>();
for (Sone sone : webInterface.getCore().getSones()) {
- albums.addAll(sone.getAllAlbums());
+ albums.addAll(FluentIterable.from(sone.getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY).toList());
}
- Collections.sort(albums, Album.TITLE_COMPARATOR);
+ Collections.sort(albums, TITLE_COMPARATOR);
Pagination<Album> albumPagination = new Pagination<Album>(albums, 12).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
templateContext.set("albumPagination", albumPagination);
templateContext.set("albums", albumPagination.getItems());