What am I doing lol

captchafix
Florens Douwes 11 years ago
parent 2ab9c1ea4d
commit 159131865e
  1. 1
      Chan/src/org/floens/chan/core/model/Post.java
  2. 40
      Chan/src/org/floens/chan/core/watch/PinWatcher.java
  3. 37
      Chan/src/org/floens/chan/core/watch/WatchNotifier.java

@ -52,6 +52,7 @@ public class Post {
public long time = 0; public long time = 0;
public String email = ""; public String email = "";
public boolean isSavedReply = false; public boolean isSavedReply = false;
public String title = "";
/** /**
* This post replies to the these ids * This post replies to the these ids

@ -21,12 +21,6 @@ public class PinWatcher implements Loader.LoaderListener {
private final List<Post> posts = new ArrayList<Post>(); private final List<Post> posts = new ArrayList<Post>();
private boolean wereNewPosts = false;
private boolean wereNewQuotes = false;
private int postLastLoad;
private int quoteLastLoad;
public PinWatcher(Pin pin) { public PinWatcher(Pin pin) {
this.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<Post> getNewQuotes() { public List<Post> getNewQuotes() {
if (posts.size() == 0) { if (posts.size() == 0) {
return posts; 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() { public boolean isError() {
return isError; return isError;
} }
@ -130,14 +106,6 @@ public class PinWatcher implements Loader.LoaderListener {
pin.watchNewCount = result.size(); pin.watchNewCount = result.size();
if (postLastLoad == 0)
postLastLoad = pin.watchNewCount;
if (pin.watchNewCount > postLastLoad) {
wereNewPosts = true;
postLastLoad = pin.watchNewCount;
}
// Get list of saved posts // Get list of saved posts
List<Post> savedPosts = new ArrayList<Post>(); List<Post> savedPosts = new ArrayList<Post>();
for (Post saved : result) { 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(); WatchService.onPinWatcherResult();
} }
} }

@ -1,6 +1,8 @@
package org.floens.chan.core.watch; package org.floens.chan.core.watch;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import org.floens.chan.ChanApplication; import org.floens.chan.ChanApplication;
@ -64,7 +66,7 @@ public class WatchNotifier {
List<Pin> pins = new ArrayList<Pin>(); List<Pin> pins = new ArrayList<Pin>();
int newPostsCount = 0; int newPostsCount = 0;
int newQuotesCount = 0; int newQuotesCount = 0;
List<Post> newPosts = new ArrayList<Post>(); List<Post> posts = new ArrayList<Post>();
boolean makeSound = false; boolean makeSound = false;
boolean show = false; boolean show = false;
@ -75,14 +77,18 @@ public class WatchNotifier {
boolean add = false; boolean add = false;
if (watcher.getWereNewPosts()) { if (watcher.getNewPostsCount() > 0) {
newPostsCount += watcher.getNewPostsCount(); newPostsCount += watcher.getNewPostsCount();
newPosts.addAll(watcher.getNewPosts()); for (Post p : watcher.getNewPosts()) {
p.title = pin.loadable.title;
posts.add(p);
}
show = true; show = true;
add = true; add = true;
} }
if (watcher.getWereNewQuotes()) { if (watcher.getNewQuoteCount() > 0) {
newQuotesCount += watcher.getNewQuoteCount(); newQuotesCount += watcher.getNewQuoteCount();
show = true; show = true;
makeSound = true; makeSound = true;
@ -112,9 +118,15 @@ public class WatchNotifier {
String content = newPostsCount + " new posts in " + descriptor; String content = newPostsCount + " new posts in " + descriptor;
Collections.sort(posts, new PostAgeComparer());
List<CharSequence> lines = new ArrayList<CharSequence>(); List<CharSequence> lines = new ArrayList<CharSequence>();
for (int i = newPosts.size() - 1; i >= 0; i--) { for (Post post : posts) {
lines.add(newPosts.get(i).comment); if (pins.size() > 1) {
lines.add(post.title + ": " + post.comment);
} else {
lines.add(post.comment);
}
} }
showNotification(content, title, content, Integer.toString(newPostsCount), lines, makeSound); showNotification(content, title, content, Integer.toString(newPostsCount), lines, makeSound);
@ -164,4 +176,17 @@ public class WatchNotifier {
Logger.test("SHOWING NOTIFICATION!"); Logger.test("SHOWING NOTIFICATION!");
nm.notify(NOTIFICATION_ID, builder.getNotification()); nm.notify(NOTIFICATION_ID, builder.getNotification());
} }
private static class PostAgeComparer implements Comparator<Post> {
@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;
}
}
}
} }

Loading…
Cancel
Save