Created
February 29, 2020 17:39
-
-
Save lawloretienne/927095a4cf01e50ebf095da9761121f4 to your computer and use it in GitHub Desktop.
FindVideosFirstFetchCallback
This file contains hidden or 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> 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