import net.pterodactylus.sone.core.event.SoneLockedEvent;
import net.pterodactylus.sone.core.event.SoneRemovedEvent;
import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
+import net.pterodactylus.sone.core.event.UpdateFoundEvent;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
*/
@Override
public void updateFound(Version version, long releaseTime, long latestEdition) {
- coreListenerManager.fireUpdateFound(version, releaseTime, latestEdition);
+ eventBus.post(new UpdateFoundEvent(version, releaseTime, latestEdition));
}
//
import java.util.EventListener;
import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.util.version.Version;
/**
* Listener interface for objects that want to be notified on certain
public interface CoreListener extends EventListener {
/**
- * Notifies a listener that a new version has been found.
- *
- * @param version
- * The version that was found
- * @param releaseTime
- * The release time of the new version
- * @param latestEdition
- * The latest edition of the Sone homepage
- */
- public void updateFound(Version version, long releaseTime, long latestEdition);
-
- /**
* Notifies a listener that an image has started being inserted.
*
* @param image
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.util.event.AbstractListenerManager;
-import net.pterodactylus.util.version.Version;
/**
* Manager for {@link CoreListener}s.
//
/**
- * Notifies all listeners that a new version was found.
- *
- * @see CoreListener#updateFound(Version, long, long)
- * @param version
- * The new version
- * @param releaseTime
- * The release time of the new version
- * @param latestEdition
- * The latest edition of the Sone homepage
- */
- void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
- for (CoreListener coreListener : getListeners()) {
- coreListener.updateFound(version, releaseTime, latestEdition);
- }
- }
-
- /**
* Notifies all listeners that an image has started being inserted.
*
* @see CoreListener#imageInsertStarted(Image)
--- /dev/null
+/*
+ * Sone - UpdateFoundEvent.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.util.version.Version;
+
+/**
+ * Event that signals that an update for Sone was found.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class UpdateFoundEvent {
+
+ /** The version that was found. */
+ private final Version version;
+
+ /** The time the update was released. */
+ private final long releaseTime;
+
+ /** The latest edition of the update page. */
+ private final long latestEdition;
+
+ /**
+ * Creates a new “update found” event.
+ *
+ * @param version
+ * The version of the update
+ * @param releaseTime
+ * The release time of the update
+ * @param latestEdition
+ * The latest edition of the update page
+ */
+ public UpdateFoundEvent(Version version, long releaseTime, long latestEdition) {
+ this.version = version;
+ this.releaseTime = releaseTime;
+ this.latestEdition = latestEdition;
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the version of the update.
+ *
+ * @return The version of the update
+ */
+ public Version version() {
+ return version;
+ }
+
+ /**
+ * Returns the release time of the update.
+ *
+ * @return The releae time of the update (in milliseconds since Jan 1, 1970
+ * UTC)
+ */
+ public long releaseTime() {
+ return releaseTime;
+ }
+
+ /**
+ * Returns the latest edition of the update page.
+ *
+ * @return The latest edition of the update page
+ */
+ public long latestEdition() {
+ return latestEdition;
+ }
+
+}
import net.pterodactylus.sone.core.event.SoneLockedEvent;
import net.pterodactylus.sone.core.event.SoneRemovedEvent;
import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
+import net.pterodactylus.sone.core.event.UpdateFoundEvent;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.template.XmlFilter;
import net.pterodactylus.util.thread.Ticker;
-import net.pterodactylus.util.version.Version;
import net.pterodactylus.util.web.RedirectPage;
import net.pterodactylus.util.web.StaticPage;
import net.pterodactylus.util.web.TemplatePage;
}
}
- //
- // CORELISTENER METHODS
- //
-
/**
- * {@inheritDoc}
+ * Notifies the web interface that a new Sone version was found.
+ *
+ * @param updateFoundEvent
+ * The event
*/
- @Override
- public void updateFound(Version version, long releaseTime, long latestEdition) {
- newVersionNotification.getTemplateContext().set("latestVersion", version);
- newVersionNotification.getTemplateContext().set("latestEdition", latestEdition);
- newVersionNotification.getTemplateContext().set("releaseTime", releaseTime);
+ @Subscribe
+ public void updateFound(UpdateFoundEvent updateFoundEvent) {
+ newVersionNotification.getTemplateContext().set("latestVersion", updateFoundEvent.version());
+ newVersionNotification.getTemplateContext().set("latestEdition", updateFoundEvent.latestEdition());
+ newVersionNotification.getTemplateContext().set("releaseTime", updateFoundEvent.releaseTime());
notificationManager.addNotification(newVersionNotification);
}
+ //
+ // CORELISTENER METHODS
+ //
+
/**
* {@inheritDoc}
*/