Created
November 26, 2014 12:22
-
-
Save Krishan14sharma/6a116632a6cd2bbf55cd to your computer and use it in GitHub Desktop.
Helper class for retrofit callback
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
package krishan.dhancha.api.helper; | |
import retrofit.Callback; | |
import retrofit.RetrofitError; | |
import retrofit.client.Response; | |
public class CancelableCallback<T> implements Callback<T> { | |
private final Callback callback; | |
private boolean canceled; | |
public CancelableCallback(Callback callback) { | |
this.callback = callback; | |
canceled = false; | |
} | |
public void cancel() { | |
canceled = true; | |
} | |
@Override | |
public void success(T t, Response response) { | |
if (!canceled) { | |
callback.success(t, response); | |
} | |
} | |
@Override | |
public void failure(RetrofitError retrofitError) | |
{ if (!canceled) { | |
callback.failure(retrofitError); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment