Last active
July 9, 2018 05:32
-
-
Save raviyadav4875/546c3ba441f9452d210841e369c53e1c to your computer and use it in GitHub Desktop.
Handle Api call success and error listener.
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
/** | |
* 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