Replace utils’ Numbers by Guava’s Optional and Ints/Longs.tryParse.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ImageBrowserPage.java
index 5bb75d1..ea039ca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - ImageBrowserPage.java - Copyright © 2011 David Roden
+ * Sone - ImageBrowserPage.java - Copyright © 2011–2013 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
@@ -26,9 +26,13 @@ import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.collection.Pagination;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 
+import com.google.common.base.Optional;
+import com.google.common.primitives.Ints;
+
 /**
  * The image browser page is the entry page for the image management.
  *
@@ -63,6 +67,7 @@ public class ImageBrowserPage extends SoneTemplatePage {
                        Album album = webInterface.getCore().getAlbum(albumId, false);
                        templateContext.set("albumRequested", true);
                        templateContext.set("album", album);
+                       templateContext.set("page", request.getHttpRequest().getParam("page"));
                        return;
                }
                String imageId = request.getHttpRequest().getParam("image", null);
@@ -87,7 +92,9 @@ public class ImageBrowserPage extends SoneTemplatePage {
                                albums.addAll(sone.getAllAlbums());
                        }
                        Collections.sort(albums, Album.TITLE_COMPARATOR);
-                       templateContext.set("albums", albums);
+                       Pagination<Album> albumPagination = new Pagination<Album>(albums, 12).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("page"))).or(0));
+                       templateContext.set("albumPagination", albumPagination);
+                       templateContext.set("albums", albumPagination.getItems());
                        return;
                }
                Sone sone = getCurrentSone(request.getToadletContext(), false);