X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FBookmarksPage.java;h=b273bdb727552c0fe2fa3bfa5d6149ae8e291bae;hb=87d9d82c6f671d69cba305b5ddf3cd81ecedc115;hp=dda4cac600e6d2139481f5e1916925aa4d4807b7;hpb=d5efb086bee8f103cbe90c7a953ffbb7ff27b689;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java index dda4cac..b273bdb 100644 --- a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java +++ b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java @@ -1,5 +1,5 @@ /* - * Sone - BookmarksPage.java - Copyright © 2011–2013 David Roden + * Sone - BookmarksPage.java - Copyright © 2011–2016 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 @@ -17,6 +17,8 @@ package net.pterodactylus.sone.web; +import static net.pterodactylus.sone.utils.NumberParsers.parseInt; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -29,10 +31,8 @@ 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.base.Predicate; import com.google.common.collect.Collections2; -import com.google.common.primitives.Ints; /** * Page that lets the user browse all his bookmarked posts. @@ -61,19 +61,18 @@ public class BookmarksPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { - super.processTemplate(request, templateContext); + protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException { Set allPosts = webInterface.getCore().getBookmarkedPosts(); Collection loadedPosts = Collections2.filter(allPosts, new Predicate() { @Override public boolean apply(Post post) { - return post.getSone() != null; + return post.isLoaded(); } }); List sortedPosts = new ArrayList(loadedPosts); - Collections.sort(sortedPosts, Post.TIME_COMPARATOR); - Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("page"))).or(0)); + Collections.sort(sortedPosts, Post.NEWEST_FIRST); + Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", pagination); templateContext.set("posts", pagination.getItems()); templateContext.set("postsNotLoaded", allPosts.size() != loadedPosts.size());