Convert “new post reply found” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 15:35:35 +0000 (16:35 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 18:04:11 +0000 (19:04 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/CoreListener.java
src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java
src/main/java/net/pterodactylus/sone/core/event/NewPostReplyFoundEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index a6acb05..0a2c534 100644 (file)
@@ -36,6 +36,7 @@ import net.pterodactylus.sone.core.Options.DefaultOption;
 import net.pterodactylus.sone.core.Options.Option;
 import net.pterodactylus.sone.core.Options.OptionWatcher;
 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
+import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
@@ -1140,7 +1141,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                                                knownReplies.add(reply.getId());
                                                                reply.setKnown(true);
                                                        } else if (!knownReplies.contains(reply.getId())) {
-                                                               coreListenerManager.fireNewReplyFound(reply);
+                                                               eventBus.post(new NewPostReplyFoundEvent(reply));
                                                        }
                                                }
                                                replies.put(reply.getId(), reply);
@@ -1683,7 +1684,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        replies.put(reply.getId(), reply);
                }
                synchronized (knownReplies) {
-                       coreListenerManager.fireNewReplyFound(reply);
+                       eventBus.post(new NewPostReplyFoundEvent(reply));
                }
                sone.addReply(reply);
                touchConfiguration();
index e641be3..854af8a 100644 (file)
@@ -34,14 +34,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that a new reply has been found.
-        *
-        * @param reply
-        *            The new reply
-        */
-       public void newReplyFound(PostReply reply);
-
-       /**
         * Notifies a listener that the given Sone is now marked as known.
         *
         * @param sone
index eb577f5..289be50 100644 (file)
@@ -46,19 +46,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
-        * Notifies all listeners that a new reply has been found.
-        *
-        * @see CoreListener#newReplyFound(PostReply)
-        * @param reply
-        *            The new reply
-        */
-       void fireNewReplyFound(PostReply reply) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.newReplyFound(reply);
-               }
-       }
-
-       /**
         * Notifies all listeners that the given Sone is now marked as known.
         *
         * @see CoreListener#markSoneKnown(Sone)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/NewPostReplyFoundEvent.java b/src/main/java/net/pterodactylus/sone/core/event/NewPostReplyFoundEvent.java
new file mode 100644 (file)
index 0000000..622a83e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Sone - NewPostFoundEvent.java - Copyright © 2013 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event;
+
+import net.pterodactylus.sone.data.PostReply;
+
+/**
+ * Event that signals that a new {@link PostReply} was found.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class NewPostReplyFoundEvent extends PostReplyEvent {
+
+       /**
+        * Creates a new “new post found” event.
+        *
+        * @param postReply
+        *            The post reply that was found
+        */
+       public NewPostReplyFoundEvent(PostReply postReply) {
+               super(postReply);
+       }
+
+}
index 42fd355..7432e5f 100644 (file)
@@ -38,6 +38,7 @@ import java.util.logging.Logger;
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.core.CoreListener;
 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
+import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
@@ -814,15 +815,12 @@ public class WebInterface implements CoreListener {
                }
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
         * {@inheritDoc}
         */
-       @Override
-       public void newReplyFound(PostReply reply) {
+       @Subscribe
+       public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
+               PostReply reply = newPostReplyFoundEvent.postReply();
                boolean isLocal = reply.getSone().isLocal();
                if (isLocal) {
                        localReplyNotification.add(reply);
@@ -840,6 +838,10 @@ public class WebInterface implements CoreListener {
                }
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */