Guest User

Untitled

a guest
Dec 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. RestServiceBuilder.getApiService().getAllProductByCatId(TOKEN, Constants.KEY_ROUTE_PRODUCTS_BY_CAT_ID,
  2. Constants.LIST_VIEW_LIMIT, page, CATEGORY_ID).enqueue(new Callback<ProductListBaseModel>() {
  3. @Override
  4. public void onResponse(Call<ProductListBaseModel> call, Response<ProductListBaseModel> response) {
  5. if (response.code() == 400 || response.code() == 500) {
  6. ErrorPojoClass errorPojoClass = ErrorUtils.parseApiError(response);
  7. CustomPopup.displayErrorPopup(a, errorPojoClass);
  8.  
  9. } else {
  10. try {
  11. if (response.body().getData().isEmpty()) {
  12.  
  13. pullToLoadView.setComplete();
  14. isLoading = false;
  15.  
  16. if (page == 1) {
  17. OnProductListResponse listResponse = (OnProductListResponse) a;
  18. listResponse.onEmptyProductListFound(true); // produts not found
  19. } else {
  20. }
  21.  
  22. } else {
  23. setupAdapterView(page, response);
  24. OnProductListResponse listResponse = (OnProductListResponse) a;
  25. listResponse.onEmptyProductListFound(false); // produts found
  26. }
  27. isSingleProduct = false;
  28. } catch (Exception e) {
  29. Log.e( "found",""+e);
  30. }
  31. }
  32. }
  33.  
  34. @Override
  35. public void onFailure(@NonNull Call<ProductListBaseModel> call, Throwable t) {
  36. isLoading = false;
  37. Log.e( "found",""+t);
  38. }
  39. });
  40.  
  41. public static <S> S createService(Class<S> serviceClass) {
  42.  
  43. Gson gson = new GsonBuilder()
  44. .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
  45. .setLenient()
  46. .create();
  47.  
  48. HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  49. interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  50. OkHttpClient client = new OkHttpClient.Builder()
  51. .addInterceptor(interceptor).build();
  52.  
  53.  
  54. Retrofit retrofit = new Retrofit.Builder()
  55. .client(client)
  56. .baseUrl(OPENCART_BASEURL)
  57. .addConverterFactory(GsonConverterFactory.create(gson))
  58. .build();
  59.  
  60.  
  61. return retrofit.create(serviceClass);
  62. }
  63.  
  64. public class ProductListBaseModel {
  65.  
  66. @SerializedName("success")
  67. @Expose
  68. private Integer success;
  69. @SerializedName("error")
  70. @Expose
  71. private List<Object> error = null;
  72. @SerializedName("data")
  73. @Expose
  74. private List<ProductListDataModel> data = null;
  75.  
  76. public Integer getSuccess() {
  77. return success;
  78. }
  79.  
  80. public void setSuccess(Integer success) {
  81. this.success = success;
  82. }
  83.  
  84. public List<Object> getError() {
  85. return error;
  86. }
  87.  
  88. public void setError(List<Object> error) {
  89. this.error = error;
  90. }
  91.  
  92. public List<ProductListDataModel> getData() {
  93. return data;
  94. }
  95.  
  96. public void setData(List<ProductListDataModel> data) {
  97. this.data = data;
  98. }
  99.  
  100. private String unknown_error;
  101.  
  102. public ProductListBaseModel(int statusCode, String message) {
  103. this.success = statusCode;
  104. this.unknown_error = message;
  105. }
Add Comment
Please, Sign In to add comment