Convert “image insert finished” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 20:58:49 +0000 (21:58 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 20:58:49 +0000 (21:58 +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/ImageInsertFinishedEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index 51a831c..c40fd0f 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.ImageInsertAbortedEvent;
+import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertStartedEvent;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
 import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
@@ -2518,7 +2519,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                image.setKey(key.toString());
                deleteTemporaryImage(image.getId());
                touchConfiguration();
-               coreListenerManager.fireImageInsertFinished(image);
+               eventBus.post(new ImageInsertFinishedEvent(image));
        }
 
        /**
index 55833c0..a449293 100644 (file)
@@ -30,14 +30,6 @@ import net.pterodactylus.sone.data.Image;
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that an image was successfully inserted.
-        *
-        * @param image
-        *            The image that was inserted
-        */
-       public void imageInsertFinished(Image image);
-
-       /**
         * Notifies a listener that an image failed to be inserted.
         *
         * @param image
index d409dac..47738b3 100644 (file)
@@ -42,19 +42,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
-        * Notifies all listeners that an image was successfully inserted.
-        *
-        * @see CoreListener#imageInsertFinished(Image)
-        * @param image
-        *            The image that was inserted
-        */
-       void fireImageInsertFinished(Image image) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.imageInsertFinished(image);
-               }
-       }
-
-       /**
         * Notifies all listeners that an image failed to be inserted.
         *
         * @see CoreListener#imageInsertFailed(Image, Throwable)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java
new file mode 100644 (file)
index 0000000..0da0c82
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Sone - ImageInsertFinishedEvent.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.Image;
+
+/**
+ * Event that signals that an {@link Image} insert is finished.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ImageInsertFinishedEvent extends ImageEvent {
+
+       /**
+        * Creates a new “image insert finished” event.
+        *
+        * @param image
+        *            The image whose insert finished
+        */
+       public ImageInsertFinishedEvent(Image image) {
+               super(image);
+       }
+
+}
index dfc0b25..9f0e8d9 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.ImageInsertAbortedEvent;
+import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertStartedEvent;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
 import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
@@ -1061,20 +1062,23 @@ public class WebInterface implements CoreListener {
                insertingImagesNotification.remove(imageInsertAbortedEvent.image());
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that an {@link Image} insert is finished.
+        *
+        * @param imageInsertFinishedEvent
+        *            The event
         */
-       @Override
-       public void imageInsertFinished(Image image) {
-               insertingImagesNotification.remove(image);
-               insertedImagesNotification.add(image);
+       @Subscribe
+       public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
+               insertingImagesNotification.remove(imageInsertFinishedEvent.image());
+               insertedImagesNotification.add(imageInsertFinishedEvent.image());
                notificationManager.addNotification(insertedImagesNotification);
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */