From: David ‘Bombe’ Roden Date: Fri, 5 May 2017 20:48:43 +0000 (+0200) Subject: Use new pagination instead of the one from utils X-Git-Tag: 0.9.7^2~223 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=107af8767f5dce8c27fa4c91b3ff3bc951140cca;p=Sone.git Use new pagination instead of the one from utils --- diff --git a/src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java index 8864257..af5a7ec 100644 --- a/src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java +++ b/src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java @@ -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 sonePagination = new Pagination(sortedSones, 25).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); + Pagination sonePagination = new Pagination(sortedSones, 25); + sonePagination.setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", sonePagination); templateContext.set("knownSones", sonePagination.getItems()); } diff --git a/src/main/java/net/pterodactylus/sone/web/pages/NewPage.java b/src/main/java/net/pterodactylus/sone/web/pages/NewPage.java index b5c6e11..a00f96c 100644 --- a/src/main/java/net/pterodactylus/sone/web/pages/NewPage.java +++ b/src/main/java/net/pterodactylus/sone/web/pages/NewPage.java @@ -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 pagination = new Pagination<>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); + Pagination 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()); } diff --git a/src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java index ed6c507..534499e 100644 --- a/src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java @@ -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 resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper()).toList(); /* pagination. */ - Pagination sonePagination = new Pagination(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("sonePage"))).or(0)); - Pagination postPagination = new Pagination(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("postPage"))).or(0)); + Pagination sonePagination = new Pagination(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()); + sonePagination.setPage(fromNullable(tryParse(request.getHttpRequest().getParam("sonePage"))).or(0)); + Pagination postPagination = new Pagination(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()); + postPagination.setPage(fromNullable(tryParse(request.getHttpRequest().getParam("postPage"))).or(0)); templateContext.set("sonePagination", sonePagination); templateContext.set("soneHits", sonePagination.getItems()); diff --git a/src/main/java/net/pterodactylus/sone/web/pages/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/pages/ViewSonePage.java index 257d2b2..f540ba2 100644 --- a/src/main/java/net/pterodactylus/sone/web/pages/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/pages/ViewSonePage.java @@ -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 sonePosts = sone.get().getPosts(); sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.get().getId())); Collections.sort(sonePosts, Post.NEWEST_FIRST); - Pagination postPagination = new Pagination(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("postPage"), 0)); + Pagination postPagination = new Pagination(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()); + postPagination.setPage(parseInt(request.getHttpRequest().getParam("postPage"), 0)); templateContext.set("postPagination", postPagination); templateContext.set("posts", postPagination.getItems()); Set replies = sone.get().getReplies(); @@ -114,7 +115,8 @@ public class ViewSonePage extends SoneTemplatePage { }); - Pagination repliedPostPagination = new Pagination(posts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("repliedPostPage"), 0)); + Pagination repliedPostPagination = new Pagination(posts, webInterface.getCore().getPreferences().getPostsPerPage()); + repliedPostPagination.setPage(parseInt(request.getHttpRequest().getParam("repliedPostPage"), 0)); templateContext.set("repliedPostPagination", repliedPostPagination); templateContext.set("repliedPosts", repliedPostPagination.getItems()); } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt index 757ae75..82278f5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt @@ -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 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt index 6189429..2f165fc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt @@ -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 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt index 7753b40..35f0f75 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt @@ -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 } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt index 6b4bbae..327c3be 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt @@ -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 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt index 243e597..990aacf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt @@ -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