From: David ‘Bombe’ Roden Date: Thu, 14 Oct 2010 08:34:20 +0000 (+0200) Subject: Show posts of Sone and friends on index page. X-Git-Tag: 0.1-RC1~421 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=92fadc4bbfacfcfc8b639961b35c2dc873cf21fa Show posts of Sone and friends on index page. --- diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java index 0e72938..3965aee 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -17,6 +17,13 @@ package net.pterodactylus.sone.web; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.template.Template; /** @@ -45,6 +52,33 @@ public class IndexPage extends SoneTemplatePage { * {@inheritDoc} */ @Override + protected void processTemplate(Request request, Template template) throws RedirectException { + super.processTemplate(request, template); + Sone sone = getCurrentSone(request.getToadletContext()); + List allPosts = new ArrayList(); + allPosts.addAll(sone.getPosts()); + for (Sone friendSone : sone.getFriendSones()) { + allPosts.addAll(friendSone.getPosts()); + } + Collections.sort(allPosts, new Comparator() { + + @Override + public int compare(Post leftPost, Post rightPost) { + return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime())); + } + + }); + template.set("posts", allPosts); + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override protected boolean requiresLogin() { return true; } diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 4bde225..d56627f 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -46,6 +46,8 @@ Page.Index.Title=Your Sone - Sone Page.Index.Page.Title=Your Sone Page.Index.Label.Text=Post text: Page.Index.Button.Post=Post! +Page.Index.PostList.Title=Posts by you and your friends +Page.Index.PostList.Text.NoPostYet=Nobody has written any posts yet. You should probably start it right now! Page.EditProfile.Title=Edit Profile - Sone Page.EditProfile.Page.Title=Edit Profile diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 154ff3e..7aa558b 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -14,4 +14,18 @@ +

<%= Page.Index.PostList.Title|l10n|html>

+ +
+ <%foreach posts post> +
+
<% post.sone.name|html>
+
<% post.text|html>
+
<% post.time|date format="MMM d, yyyy, HH:mm:ss">
+
+ <%foreachelse> +
<%= Page.Index.PostList.Text.NoPostYet|l10n|html>
+ <%/foreach> +
+ \ No newline at end of file