Skip to content

Instantly share code, notes, and snippets.

@hassanabidpk
Created August 1, 2017 07:33
Show Gist options
  • Save hassanabidpk/10ee22e17e017e8feea593d2b0473fb6 to your computer and use it in GitHub Desktop.
Save hassanabidpk/10ee22e17e017e8feea593d2b0473fb6 to your computer and use it in GitHub Desktop.
private void initiateRestaurantApi(String place, String query,final View recyclerView) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
SearchRestaurantApi api = retrofit.create(SearchRestaurantApi.class);
Call<SearchRestaurantResponse[]> call = api.getRestaurantsList("json",place,query);
progessBar.setVisibility(View.VISIBLE);
call.enqueue(new Callback<SearchRestaurantResponse[]>() {
@Override
public void onResponse(Response<SearchRestaurantResponse[]> response) {
if(response.isSuccess()) {
Log.d(LOG_TAG, "success - response is " + response.body());
restaurants = Arrays.asList(response.body());
setupRecyclerView((RecyclerView) recyclerView);
progessBar.setVisibility(View.GONE);
} else {
progessBar.setVisibility(View.GONE);
Log.d(LOG_TAG, "failure response is " + response.raw().toString());
}
}
@Override
public void onFailure(Throwable t) {
Log.d(LOG_TAG, " Error : " + t.getMessage());
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment