Skip to content
This repository
Browse code

Added removeListener method in DokuwikiManager.Listener

  • Loading branch information...
commit db2ec4414da80a037f3a2842731013d938db89e2 1 parent 6248962
Tim Roes timroes authored

Showing 1 changed file with 19 additions and 6 deletions. Show diff stats Hide diff stats

  1. +19 6 src/org/dokuwikimobile/manager/DokuwikiManager.java
25 src/org/dokuwikimobile/manager/DokuwikiManager.java
@@ -207,8 +207,7 @@ public void put(long id, CancelableListener listener) {
207 207
208 208 /**
209 209 * Gets the listener for a specific callback. This will take the callback id,
210   - * the type of the listener expected to be returned and whether the listener
211   - * should be removed from listener map.
  210 + * the type of the listener expected to be returned.
212 211 *
213 212 * @param id The id of the callback.
214 213 * @param listenerType The type of listener expected for that id.
@@ -216,7 +215,21 @@ public void put(long id, CancelableListener listener) {
216 215 * or had the wrong type.
217 216 */
218 217 private <T> T getListener(long id, Class<T> listenerType) {
219   - return getListener(id, listenerType, false);
  218 + return getOrRemoveListener(id, listenerType, false);
  219 + }
  220 +
  221 + /**
  222 + * Remove the Listener for a specific callback. This will take the callback id,
  223 + * the type of the listener expected to be returned. The listener will be removed
  224 + * from the list and returned.
  225 + *
  226 + * @param id The id of the callback.
  227 + * @param listenerType The type of listener expected for that id.
  228 + * @return The listener with the given type or null if none has been found,
  229 + * or had the wrong type.
  230 + */
  231 + private <T> T removeListener(long id, Class<T> listenerType) {
  232 + return getOrRemoveListener(id, listenerType, true);
220 233 }
221 234
222 235 /**
@@ -230,7 +243,7 @@ public void put(long id, CancelableListener listener) {
230 243 * @return The listener with the given type or null if none has been found,
231 244 * or had the wrong type.
232 245 */
233   - private <T> T getListener(long id, Class<T> listenerType, boolean removeListener) {
  246 + private <T> T getOrRemoveListener(long id, Class<T> listenerType, boolean removeListener) {
234 247
235 248 CancelableListener listener = listeners.get(id);
236 249
@@ -263,7 +276,7 @@ public void onLogin(boolean succeeded, long id) {
263 276
264 277 // Notify original listener
265 278 LoginListener l;
266   - if((l = getListener(id, LoginListener.class, true)) != null) {
  279 + if((l = removeListener(id, LoginListener.class)) != null) {
267 280 l.onLogin(succeeded, id);
268 281 }
269 282
@@ -287,7 +300,7 @@ public void onEndLoading(long id) {
287 300 * @param id The id of the call.
288 301 */
289 302 public void onError(ErrorCode error, long id) {
290   - getListener(id, CancelableListener.class, true).onError(error, id);
  303 + removeListener(id, CancelableListener.class).onError(error, id);
291 304 }
292 305
293 306 }

0 comments on commit db2ec44

Please sign in to comment.
Something went wrong with that request. Please try again.