From 227e3e5aa520354a7744844f9345bf20920519e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 16 Jan 2013 16:35:35 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9Cnew=20post=20reply=20found?= =?utf8?q?=E2=80=9D=20into=20EventBus-based=20event.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 5 +-- .../net/pterodactylus/sone/core/CoreListener.java | 8 ----- .../sone/core/CoreListenerManager.java | 13 -------- .../sone/core/event/NewPostReplyFoundEvent.java | 39 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 14 ++++---- 5 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/event/NewPostReplyFoundEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index a6acb05..0a2c534 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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(); diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index e641be3..854af8a 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListener.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListener.java @@ -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 diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java index eb577f5..289be50 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java @@ -46,19 +46,6 @@ public class CoreListenerManager extends AbstractListenerManager. + */ + +package net.pterodactylus.sone.core.event; + +import net.pterodactylus.sone.data.PostReply; + +/** + * Event that signals that a new {@link PostReply} was found. + * + * @author David ‘Bombe’ Roden + */ +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); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 42fd355..7432e5f 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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} */ -- 2.7.4