Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RestServiceBuilder.getApiService().getAllProductByCatId(TOKEN, Constants.KEY_ROUTE_PRODUCTS_BY_CAT_ID,
- Constants.LIST_VIEW_LIMIT, page, CATEGORY_ID).enqueue(new Callback<ProductListBaseModel>() {
- @Override
- public void onResponse(Call<ProductListBaseModel> call, Response<ProductListBaseModel> response) {
- if (response.code() == 400 || response.code() == 500) {
- ErrorPojoClass errorPojoClass = ErrorUtils.parseApiError(response);
- CustomPopup.displayErrorPopup(a, errorPojoClass);
- } else {
- try {
- if (response.body().getData().isEmpty()) {
- pullToLoadView.setComplete();
- isLoading = false;
- if (page == 1) {
- OnProductListResponse listResponse = (OnProductListResponse) a;
- listResponse.onEmptyProductListFound(true); // produts not found
- } else {
- }
- } else {
- setupAdapterView(page, response);
- OnProductListResponse listResponse = (OnProductListResponse) a;
- listResponse.onEmptyProductListFound(false); // produts found
- }
- isSingleProduct = false;
- } catch (Exception e) {
- Log.e( "found",""+e);
- }
- }
- }
- @Override
- public void onFailure(@NonNull Call<ProductListBaseModel> call, Throwable t) {
- isLoading = false;
- Log.e( "found",""+t);
- }
- });
- public static <S> S createService(Class<S> serviceClass) {
- Gson gson = new GsonBuilder()
- .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
- .setLenient()
- .create();
- HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
- interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
- OkHttpClient client = new OkHttpClient.Builder()
- .addInterceptor(interceptor).build();
- Retrofit retrofit = new Retrofit.Builder()
- .client(client)
- .baseUrl(OPENCART_BASEURL)
- .addConverterFactory(GsonConverterFactory.create(gson))
- .build();
- return retrofit.create(serviceClass);
- }
- public class ProductListBaseModel {
- @SerializedName("success")
- @Expose
- private Integer success;
- @SerializedName("error")
- @Expose
- private List<Object> error = null;
- @SerializedName("data")
- @Expose
- private List<ProductListDataModel> data = null;
- public Integer getSuccess() {
- return success;
- }
- public void setSuccess(Integer success) {
- this.success = success;
- }
- public List<Object> getError() {
- return error;
- }
- public void setError(List<Object> error) {
- this.error = error;
- }
- public List<ProductListDataModel> getData() {
- return data;
- }
- public void setData(List<ProductListDataModel> data) {
- this.data = data;
- }
- private String unknown_error;
- public ProductListBaseModel(int statusCode, String message) {
- this.success = statusCode;
- this.unknown_error = message;
- }
Add Comment
Please, Sign In to add comment