Skip to content

Instantly share code, notes, and snippets.

@lawloretienne
Created February 29, 2020 17:39
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/927095a4cf01e50ebf095da9761121f4 to your computer and use it in GitHub Desktop.
Save lawloretienne/927095a4cf01e50ebf095da9761121f4 to your computer and use it in GitHub Desktop.
FindVideosFirstFetchCallback
private Callback<VideosCollection> findVideosFirstFetchCallback = new Callback<VideosCollection>() {
@Override
public void onResponse(Call<VideosCollection> call, Response<VideosCollection> response) {
loadingImageView.setVisibility(View.GONE);
isLoading = false;
if (!response.isSuccessful()) {
int responseCode = response.code();
if(responseCode == 504) { // 504 Unsatisfiable Request (only-if-cached)
errorTextView.setText("Can't load data.\nCheck your network connection.");
errorLinearLayout.setVisibility(View.VISIBLE);
}
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()){
isLoading = false;
loadingImageView.setVisibility(View.GONE);
if(t instanceof ConnectException || t instanceof UnknownHostException){
errorTextView.setText("Can't load data.\nCheck your network connection.");
errorLinearLayout.setVisibility(View.VISIBLE);
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment