Created
February 29, 2020 17:38
-
-
Save lawloretienne/5451c8c29d15ea7f3f3248c0c2db1dbc to your computer and use it in GitHub Desktop.
FindVideosNextFetchCallback
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
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