/** * Adds a new GeoQueryEventListener to this GeoQuery. * * @throws java.lang.IllegalArgumentException If this listener was already added * * @param listener The listener to add */ public void addGeoQueryEventListener(GeoQueryEventListener listener) { lock (Lock) { if (eventListeners.Contains(listener)) { throw new Exception("Added the same listener twice to a GeoQuery!"); } eventListeners.Add(listener); if (this.queries == null) { this.setupQueries(); } else { foreach (string key in locationInfos.Keys) { LocationInfo info = GeoUtils.getMapSafe(key, locationInfos); if (info.inGeoQuery) { geoFire.raiseEvent(() => { listener.onKeyEntered(key, info.location); }); } } if (canFireReady()) { geoFire.raiseEvent(() => { listener.onGeoQueryReady(); }); } } } }
/** * Removes an event listener. * * @throws java.lang.IllegalArgumentException If the listener was removed already or never added * * @param listener The listener to remove */ public void removeGeoQueryEventListener(GeoQueryEventListener listener) { lock (Lock) { if (!eventListeners.Contains(listener)) { throw new Exception("Trying to remove listener that was removed or not added!"); } eventListeners.Remove(listener); if (!this.hasListeners()) { reset(); } } }