Created
August 5, 2016 14:51
-
-
Save moagrius/744e886144247c2b0bd405b7caabd4d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CompositeCallback<T> implements Callback<T> { | |
private List<Callback<T>> mCallbacks = new LinkedList<>(); | |
public CompositeCallback(Callback<T> callback) { | |
add(callback); | |
} | |
public CompositeCallback<T> add(Callback<T> callback) { | |
if (callback != null) { | |
mCallbacks.add(callback); | |
} | |
return this; | |
} | |
@Override | |
public void onResponse(Call<T> call, Response<T> response) { | |
for (Callback<T> callback : mCallbacks) { | |
callback.onResponse(call, response); | |
} | |
} | |
@Override | |
public void onFailure(Call<T> call, Throwable throwable) { | |
for (Callback<T> callback : mCallbacks) { | |
callback.onFailure(call, throwable); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment