Skip to content

Instantly share code, notes, and snippets.

@lawloretienne
Created February 29, 2020 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawloretienne/5451c8c29d15ea7f3f3248c0c2db1dbc to your computer and use it in GitHub Desktop.
Save lawloretienne/5451c8c29d15ea7f3f3248c0c2db1dbc to your computer and use it in GitHub Desktop.
FindVideosNextFetchCallback
private Callback<VideosCollection> findVideosNextFetchCallback = new Callback<VideosCollection>() {
@Override
public void onResponse(Call<VideosCollection> call, Response<VideosCollection> response) {
videosAdapter.removeFooter();
isLoading = false;
if (!response.isSuccessful()) {
int responseCode = response.code();
switch (responseCode){
case 504: // 504 Unsatisfiable Request (only-if-cached)
break;
case 400:
isLastPage = true;
break;
}
return;
}
VideosCollection videosCollection = response.body();
if (videosCollection != null) {
List<Video> videos = videosCollection.getVideos();
if (videos != null) {
videosAdapter.addAll(videos);
if(videos.size() >= PAGE_SIZE){
videosAdapter.addFooter();
} else {
isLastPage = true;
}
}
}
}
@Override
public void onFailure(Call<VideosCollection> call, Throwable t) {
NetworkLogUtility.logFailure(call, t);
if (!call.isCanceled()){
if(t instanceof ConnectException || t instanceof UnknownHostException){
videosAdapter.updateFooter(VideosAdapter.FooterType.ERROR);
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment