Skip to content

Instantly share code, notes, and snippets.

@raviyadav4875
Last active July 9, 2018 05:32
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 raviyadav4875/546c3ba441f9452d210841e369c53e1c to your computer and use it in GitHub Desktop.
Save raviyadav4875/546c3ba441f9452d210841e369c53e1c to your computer and use it in GitHub Desktop.
Handle Api call success and error listener.
/**
* Success listener to handle the movie listing
* process after api returns the movie list
*
* @return
*/
private Response.Listener<String> ReqSuccessListener() {
return new Response.Listener<String>() {
public void onResponse(String response) {
Log.e("movie list_response", response);
try {
hideProgress();
pageNumber++;
MovieList movieListModel = (MovieList) Utils.jsonToPojo(response, MovieList.class);
if (movieListModel.getResults() != null &&
movieListModel.getResults().size() > 0) {
moviesRecyclerAdapter.addMovies(movieListModel.getResults());
} else {
Log.e(TAG, "list empty==");
}
} catch (Exception e) {
Log.e(TAG,"Exception=="+e.getLocalizedMessage());
}
}
};
}
/**
* To Handle the error
*
* @return
*/
private Response.ErrorListener ReqErrorListener() {
return new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Log.e("volley error", "volley error");
Toast.makeText(MovieListingActivity.this, "" +
"Server Error..Please try again after sometime", Toast.LENGTH_SHORT).show();
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment