Use new pagination instead of the one from utils
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 May 2017 20:48:43 +0000 (22:48 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 May 2017 20:52:14 +0000 (22:52 +0200)
src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java
src/main/java/net/pterodactylus/sone/web/pages/NewPage.java
src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java
src/main/java/net/pterodactylus/sone/web/pages/ViewSonePage.java
src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt

index 8864257..af5a7ec 100644 (file)
@@ -25,9 +25,9 @@ import java.util.Collections;
 import java.util.List;
 
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.utils.Pagination;
 import net.pterodactylus.sone.web.WebInterface;
 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;
 
@@ -144,7 +144,8 @@ public class KnownSonesPage extends SoneTemplatePage {
                                Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR);
                        }
                }
-               Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
+               Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25);
+               sonePagination.setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
                templateContext.set("pagination", sonePagination);
                templateContext.set("knownSones", sonePagination.getItems());
        }
index b5c6e11..a00f96c 100644 (file)
@@ -29,9 +29,9 @@ import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.notify.PostVisibilityFilter;
+import net.pterodactylus.sone.utils.Pagination;
 import net.pterodactylus.sone.web.WebInterface;
 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;
 
@@ -75,7 +75,8 @@ public class NewPage extends SoneTemplatePage {
                Collections.sort(sortedPosts, Post.NEWEST_FIRST);
 
                /* paginate them. */
-               Pagination<Post> pagination = new Pagination<>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
+               Pagination<Post> pagination = new Pagination<>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage());
+               pagination.setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
                templateContext.set("pagination", pagination);
                templateContext.set("posts", pagination.getItems());
        }
index ed6c507..534499e 100644 (file)
@@ -38,9 +38,9 @@ import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Profile.Field;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.utils.Pagination;
 import net.pterodactylus.sone.web.WebInterface;
 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 net.pterodactylus.util.text.StringEscaper;
@@ -151,8 +151,10 @@ public class SearchPage extends SoneTemplatePage {
                List<Post> resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper<Post>()).toList();
 
                /* pagination. */
-               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("sonePage"))).or(0));
-               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("postPage"))).or(0));
+               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage());
+               sonePagination.setPage(fromNullable(tryParse(request.getHttpRequest().getParam("sonePage"))).or(0));
+               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage());
+               postPagination.setPage(fromNullable(tryParse(request.getHttpRequest().getParam("postPage"))).or(0));
 
                templateContext.set("sonePagination", sonePagination);
                templateContext.set("soneHits", sonePagination.getItems());
index 257d2b2..f540ba2 100644 (file)
@@ -32,9 +32,9 @@ import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.template.SoneAccessor;
+import net.pterodactylus.sone.utils.Pagination;
 import net.pterodactylus.sone.web.WebInterface;
 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;
 
@@ -92,7 +92,8 @@ public class ViewSonePage extends SoneTemplatePage {
                List<Post> sonePosts = sone.get().getPosts();
                sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.get().getId()));
                Collections.sort(sonePosts, Post.NEWEST_FIRST);
-               Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("postPage"), 0));
+               Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage());
+               postPagination.setPage(parseInt(request.getHttpRequest().getParam("postPage"), 0));
                templateContext.set("postPagination", postPagination);
                templateContext.set("posts", postPagination.getItems());
                Set<PostReply> replies = sone.get().getReplies();
@@ -114,7 +115,8 @@ public class ViewSonePage extends SoneTemplatePage {
 
                });
 
-               Pagination<Post> repliedPostPagination = new Pagination<Post>(posts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("repliedPostPage"), 0));
+               Pagination<Post> repliedPostPagination = new Pagination<Post>(posts, webInterface.getCore().getPreferences().getPostsPerPage());
+               repliedPostPagination.setPage(parseInt(request.getHttpRequest().getParam("repliedPostPage"), 0));
                templateContext.set("repliedPostPagination", repliedPostPagination);
                templateContext.set("repliedPosts", repliedPostPagination.getItems());
        }
index 757ae75..82278f5 100644 (file)
@@ -1,10 +1,10 @@
 package net.pterodactylus.sone.web.pages
 
 import net.pterodactylus.sone.data.Post
+import net.pterodactylus.sone.utils.Pagination
 import net.pterodactylus.sone.web.pages.SoneTemplatePage
 import net.pterodactylus.sone.web.WebInterface
 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
 
index 6189429..2f165fc 100644 (file)
@@ -2,10 +2,10 @@ package net.pterodactylus.sone.web.pages
 
 import net.pterodactylus.sone.data.Album
 import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.utils.Pagination
 import net.pterodactylus.sone.utils.parameters
 import net.pterodactylus.sone.web.WebInterface
 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 java.net.URI
@@ -34,7 +34,7 @@ class ImageBrowserPage(template: Template, webInterface: WebInterface):
                                        .sortedBy(Album::getTitle)
                                        .also { albums ->
                                                templateContext["albums"] = albums
-                                               templateContext["albumPagination"] = Pagination(albums, 12).setPage(request.parameters["page"]?.toIntOrNull() ?: 0)
+                                               templateContext["albumPagination"] = Pagination(albums, 12).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }
                                        }
                } else {
                        templateContext["soneRequested"] = true
index 7753b40..35f0f75 100644 (file)
@@ -1,10 +1,10 @@
 package net.pterodactylus.sone.web.pages
 
 import net.pterodactylus.sone.notify.PostVisibilityFilter
+import net.pterodactylus.sone.utils.Pagination
 import net.pterodactylus.sone.utils.parameters
 import net.pterodactylus.sone.web.WebInterface
 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
 
@@ -28,8 +28,9 @@ class IndexPage(template: Template, webInterface: WebInterface, private val post
                                        .filter { postVisibilityFilter.isVisible(currentSone).apply(it) }
                                        .sortedByDescending { it.time }
                                        .let { posts ->
-                                               Pagination(posts, webInterface.core.preferences.postsPerPage)
-                                                               .setPage(request.parameters["page"]?.toIntOrNull() ?: 0).let { pagination ->
+                                               Pagination(posts, webInterface.core.preferences.postsPerPage).apply {
+                                                       page = request.parameters["page"]?.toIntOrNull() ?: 0
+                                               }.let { pagination ->
                                                        templateContext["pagination"] = pagination
                                                        templateContext["posts"] = pagination.items
                                                }
index 6b4bbae..327c3be 100644 (file)
@@ -3,9 +3,9 @@ package net.pterodactylus.sone.web.pages
 import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.utils.Pagination
 import net.pterodactylus.sone.web.pages.WebPageTest
 import net.pterodactylus.sone.web.pages.BookmarksPage
-import net.pterodactylus.util.collection.Pagination
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.contains
 import org.hamcrest.Matchers.equalTo
index 243e597..990aacf 100644 (file)
@@ -7,7 +7,7 @@ import net.pterodactylus.sone.data.Sone
 import net.pterodactylus.sone.notify.PostVisibilityFilter
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.util.collection.Pagination
+import net.pterodactylus.sone.utils.Pagination
 import net.pterodactylus.util.web.Method.GET
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.contains