import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
import net.pterodactylus.sone.core.event.PostRemovedEvent;
import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertedEvent;
import net.pterodactylus.sone.core.event.SoneInsertingEvent;
import net.pterodactylus.sone.core.event.SoneLockedEvent;
import net.pterodactylus.sone.core.event.SoneRemovedEvent;
*/
@Override
public void insertFinished(Sone sone, long insertDuration) {
- coreListenerManager.fireSoneInserted(sone, insertDuration);
+ eventBus.post(new SoneInsertedEvent(sone, insertDuration));
}
/**
public interface CoreListener extends EventListener {
/**
- * Notifies a listener that the insert of the given Sone has finished
- * successfully.
- *
- * @see SoneInsertListener#insertFinished(Sone, long)
- * @param sone
- * The Sone that has been inserted
- * @param insertDuration
- * The insert duration (in milliseconds)
- */
- public void soneInserted(Sone sone, long insertDuration);
-
- /**
* Notifies a listener that the insert of the given Sone was aborted.
*
* @see SoneInsertListener#insertAborted(Sone, Throwable)
//
/**
- * Notifies all listeners that the insert of the given Sone has finished
- * successfully.
- *
- * @see SoneInsertListener#insertFinished(Sone, long)
- * @param sone
- * The Sone that was inserted
- * @param insertDuration
- * The insert duration (in milliseconds)
- */
- void fireSoneInserted(Sone sone, long insertDuration) {
- for (CoreListener coreListener : getListeners()) {
- coreListener.soneInserted(sone, insertDuration);
- }
- }
-
- /**
* Notifies all listeners that the insert of the given Sone was aborted.
*
* @see SoneInsertListener#insertStarted(Sone)
--- /dev/null
+/*
+ * Sone - SoneInsertedEvent.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.Sone;
+
+/**
+ * Event that signals that a {@link Sone} was inserted.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneInsertedEvent extends SoneEvent {
+
+ /** The duration of the insert. */
+ private final long insertDuration;
+
+ /**
+ * Creates a new “Sone was inserted” event.
+ *
+ * @param sone
+ * The Sone that was inserted
+ * @param insertDuration
+ * The duration of the insert (in milliseconds)
+ */
+ public SoneInsertedEvent(Sone sone, long insertDuration) {
+ super(sone);
+ this.insertDuration = insertDuration;
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the duration of the insert.
+ *
+ * @return The duration of the insert (in milliseconds)
+ */
+ public long insertDuration() {
+ return insertDuration;
+ }
+
+}
import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
import net.pterodactylus.sone.core.event.PostRemovedEvent;
import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertedEvent;
import net.pterodactylus.sone.core.event.SoneInsertingEvent;
import net.pterodactylus.sone.core.event.SoneLockedEvent;
import net.pterodactylus.sone.core.event.SoneRemovedEvent;
}
}
- //
- // CORELISTENER METHODS
- //
-
/**
- * {@inheritDoc}
+ * Notifies the web interface that a {@link Sone} was inserted.
+ *
+ * @param soneInsertedEvent
+ * The event
*/
- @Override
- public void soneInserted(Sone sone, long insertDuration) {
- TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
+ @Subscribe
+ public void soneInserted(SoneInsertedEvent soneInsertedEvent) {
+ TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertedEvent.sone());
soneInsertNotification.set("soneStatus", "inserted");
- soneInsertNotification.set("insertDuration", insertDuration / 1000);
- if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+ soneInsertNotification.set("insertDuration", soneInsertedEvent.insertDuration() / 1000);
+ if (soneInsertedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
notificationManager.addNotification(soneInsertNotification);
}
}
+ //
+ // CORELISTENER METHODS
+ //
+
/**
* {@inheritDoc}
*/