From 159131865e2e1ce07f8dcb5c9a5c21e8cc8b8942 Mon Sep 17 00:00:00 2001 From: Florens Douwes Date: Wed, 2 Apr 2014 23:17:29 +0200 Subject: [PATCH] What am I doing lol --- Chan/src/org/floens/chan/core/model/Post.java | 1 + .../floens/chan/core/watch/PinWatcher.java | 40 ------------------- .../floens/chan/core/watch/WatchNotifier.java | 37 ++++++++++++++--- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/Chan/src/org/floens/chan/core/model/Post.java b/Chan/src/org/floens/chan/core/model/Post.java index 439bacca..30fcdd4e 100644 --- a/Chan/src/org/floens/chan/core/model/Post.java +++ b/Chan/src/org/floens/chan/core/model/Post.java @@ -52,6 +52,7 @@ public class Post { public long time = 0; public String email = ""; public boolean isSavedReply = false; + public String title = ""; /** * This post replies to the these ids diff --git a/Chan/src/org/floens/chan/core/watch/PinWatcher.java b/Chan/src/org/floens/chan/core/watch/PinWatcher.java index 8a441aae..573cd1dd 100644 --- a/Chan/src/org/floens/chan/core/watch/PinWatcher.java +++ b/Chan/src/org/floens/chan/core/watch/PinWatcher.java @@ -21,12 +21,6 @@ public class PinWatcher implements Loader.LoaderListener { private final List posts = new ArrayList(); - private boolean wereNewPosts = false; - private boolean wereNewQuotes = false; - - private int postLastLoad; - private int quoteLastLoad; - public PinWatcher(Pin pin) { this.pin = pin; @@ -67,15 +61,6 @@ public class PinWatcher implements Loader.LoaderListener { } } - public boolean getWereNewPosts() { - if (wereNewPosts) { - wereNewPosts = false; - return true; - } else { - return false; - } - } - public List getNewQuotes() { if (posts.size() == 0) { return posts; @@ -92,15 +77,6 @@ public class PinWatcher implements Loader.LoaderListener { } } - public boolean getWereNewQuotes() { - if (wereNewQuotes) { - wereNewQuotes = false; - return true; - } else { - return false; - } - } - public boolean isError() { return isError; } @@ -130,14 +106,6 @@ public class PinWatcher implements Loader.LoaderListener { pin.watchNewCount = result.size(); - if (postLastLoad == 0) - postLastLoad = pin.watchNewCount; - - if (pin.watchNewCount > postLastLoad) { - wereNewPosts = true; - postLastLoad = pin.watchNewCount; - } - // Get list of saved posts List savedPosts = new ArrayList(); for (Post saved : result) { @@ -157,14 +125,6 @@ public class PinWatcher implements Loader.LoaderListener { } } - if (quoteLastLoad == 0) - quoteLastLoad = pin.quoteNewCount; - - if (pin.quoteNewCount > quoteLastLoad) { - wereNewQuotes = true; - quoteLastLoad = pin.quoteNewCount; - } - WatchService.onPinWatcherResult(); } } diff --git a/Chan/src/org/floens/chan/core/watch/WatchNotifier.java b/Chan/src/org/floens/chan/core/watch/WatchNotifier.java index 7f9366cf..dd7fa690 100644 --- a/Chan/src/org/floens/chan/core/watch/WatchNotifier.java +++ b/Chan/src/org/floens/chan/core/watch/WatchNotifier.java @@ -1,6 +1,8 @@ package org.floens.chan.core.watch; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import org.floens.chan.ChanApplication; @@ -64,7 +66,7 @@ public class WatchNotifier { List pins = new ArrayList(); int newPostsCount = 0; int newQuotesCount = 0; - List newPosts = new ArrayList(); + List posts = new ArrayList(); boolean makeSound = false; boolean show = false; @@ -75,14 +77,18 @@ public class WatchNotifier { boolean add = false; - if (watcher.getWereNewPosts()) { + if (watcher.getNewPostsCount() > 0) { newPostsCount += watcher.getNewPostsCount(); - newPosts.addAll(watcher.getNewPosts()); + for (Post p : watcher.getNewPosts()) { + p.title = pin.loadable.title; + posts.add(p); + } + show = true; add = true; } - if (watcher.getWereNewQuotes()) { + if (watcher.getNewQuoteCount() > 0) { newQuotesCount += watcher.getNewQuoteCount(); show = true; makeSound = true; @@ -112,9 +118,15 @@ public class WatchNotifier { String content = newPostsCount + " new posts in " + descriptor; + Collections.sort(posts, new PostAgeComparer()); + List lines = new ArrayList(); - for (int i = newPosts.size() - 1; i >= 0; i--) { - lines.add(newPosts.get(i).comment); + for (Post post : posts) { + if (pins.size() > 1) { + lines.add(post.title + ": " + post.comment); + } else { + lines.add(post.comment); + } } showNotification(content, title, content, Integer.toString(newPostsCount), lines, makeSound); @@ -164,4 +176,17 @@ public class WatchNotifier { Logger.test("SHOWING NOTIFICATION!"); nm.notify(NOTIFICATION_ID, builder.getNotification()); } + + private static class PostAgeComparer implements Comparator { + @Override + public int compare(Post lhs, Post rhs) { + if (lhs.time < rhs.time) { + return 1; + } else if (lhs.time > rhs.time) { + return -1; + } else { + return 0; + } + } + } }