Showing
4 changed files
with
130 additions
and
223 deletions
| ... | @@ -50,8 +50,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation | ... | @@ -50,8 +50,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation |
| 50 | mBottomNavigationView = findViewById(R.id.bt_tabs); | 50 | mBottomNavigationView = findViewById(R.id.bt_tabs); |
| 51 | 51 | ||
| 52 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); | 52 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); |
| 53 | -// WarplyManager.getCampaigns(mCampaignsCallback); | 53 | + WarplyManager.getCampaigns(mCampaignsCallback); |
| 54 | -// WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); | 54 | + WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | @Override | 57 | @Override | ... | ... |
| ... | @@ -96,6 +96,7 @@ public class Coupon implements Parcelable, Serializable { | ... | @@ -96,6 +96,7 @@ public class Coupon implements Parcelable, Serializable { |
| 96 | private String short_description = ""; | 96 | private String short_description = ""; |
| 97 | private String terms = ""; | 97 | private String terms = ""; |
| 98 | private Couponset couponsetDetails = new Couponset(true); | 98 | private Couponset couponsetDetails = new Couponset(true); |
| 99 | + private Merchant merchantDetails = new Merchant(true); | ||
| 99 | 100 | ||
| 100 | public Coupon() { | 101 | public Coupon() { |
| 101 | this.barcode = ""; | 102 | this.barcode = ""; |
| ... | @@ -133,6 +134,7 @@ public class Coupon implements Parcelable, Serializable { | ... | @@ -133,6 +134,7 @@ public class Coupon implements Parcelable, Serializable { |
| 133 | this.merchantUuid = ""; | 134 | this.merchantUuid = ""; |
| 134 | this.redeemDate = new Date(); | 135 | this.redeemDate = new Date(); |
| 135 | this.couponsetDetails = new Couponset(isUniversal); | 136 | this.couponsetDetails = new Couponset(isUniversal); |
| 137 | + this.merchantDetails = new Merchant(isUniversal); | ||
| 136 | } | 138 | } |
| 137 | 139 | ||
| 138 | /** | 140 | /** |
| ... | @@ -218,6 +220,10 @@ public class Coupon implements Parcelable, Serializable { | ... | @@ -218,6 +220,10 @@ public class Coupon implements Parcelable, Serializable { |
| 218 | if (tempCouponsetDetails != null) { | 220 | if (tempCouponsetDetails != null) { |
| 219 | this.couponsetDetails = new Couponset(tempCouponsetDetails, isUniversal); | 221 | this.couponsetDetails = new Couponset(tempCouponsetDetails, isUniversal); |
| 220 | } | 222 | } |
| 223 | + JSONObject tempMerchantDetails = json.optJSONObject("merchant_details"); | ||
| 224 | + if (tempMerchantDetails != null) { | ||
| 225 | + this.merchantDetails = new Merchant(tempMerchantDetails, isUniversal); | ||
| 226 | + } | ||
| 221 | 227 | ||
| 222 | // this.category = json.optString(CATEGORY); | 228 | // this.category = json.optString(CATEGORY); |
| 223 | // this.created = json.optString(CREATED); | 229 | // this.created = json.optString(CREATED); |
| ... | @@ -522,6 +528,22 @@ public class Coupon implements Parcelable, Serializable { | ... | @@ -522,6 +528,22 @@ public class Coupon implements Parcelable, Serializable { |
| 522 | this.terms = terms; | 528 | this.terms = terms; |
| 523 | } | 529 | } |
| 524 | 530 | ||
| 531 | + public Couponset getCouponsetDetails() { | ||
| 532 | + return couponsetDetails; | ||
| 533 | + } | ||
| 534 | + | ||
| 535 | + public void setCouponsetDetails(Couponset couponsetDetails) { | ||
| 536 | + this.couponsetDetails = couponsetDetails; | ||
| 537 | + } | ||
| 538 | + | ||
| 539 | + public Merchant getMerchantDetails() { | ||
| 540 | + return merchantDetails; | ||
| 541 | + } | ||
| 542 | + | ||
| 543 | + public void setMerchantDetails(Merchant merchantDetails) { | ||
| 544 | + this.merchantDetails = merchantDetails; | ||
| 545 | + } | ||
| 546 | + | ||
| 525 | @Override | 547 | @Override |
| 526 | public int describeContents() { | 548 | public int describeContents() { |
| 527 | return 0; | 549 | return 0; | ... | ... |
| ... | @@ -180,6 +180,19 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { | ... | @@ -180,6 +180,19 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { |
| 180 | coordinates = new LatLng(this.latitude, this.longitude); | 180 | coordinates = new LatLng(this.latitude, this.longitude); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | + public Merchant(boolean isUniversal) { | ||
| 184 | + this.address = ""; | ||
| 185 | + this.city = ""; | ||
| 186 | + this.body = ""; | ||
| 187 | + this.logo = ""; | ||
| 188 | + this.country = ""; | ||
| 189 | + this.name = ""; | ||
| 190 | + this.postal_code = ""; | ||
| 191 | + this.region = ""; | ||
| 192 | + this.telephone = ""; | ||
| 193 | + this.merchant_metadata = new JSONObject(); | ||
| 194 | + } | ||
| 195 | + | ||
| 183 | /** | 196 | /** |
| 184 | * Basic constructor used to create an object from a String, representing a | 197 | * Basic constructor used to create an object from a String, representing a |
| 185 | * JSON Object | 198 | * JSON Object |
| ... | @@ -242,6 +255,53 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { | ... | @@ -242,6 +255,53 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { |
| 242 | } | 255 | } |
| 243 | } | 256 | } |
| 244 | 257 | ||
| 258 | + public Merchant(JSONObject json, boolean isUniversal) { | ||
| 259 | + if (json != null) { | ||
| 260 | + this.address = json.isNull(ADDRESS) ? "" : json.optString(ADDRESS); | ||
| 261 | + this.body = json.optString(BODY); | ||
| 262 | + this.city = json.optString(CITY); | ||
| 263 | + this.logo = json.optString(LOGO); | ||
| 264 | + this.country = json.optString(COUNTRY); | ||
| 265 | + this.name = json.isNull(NAME) ? "" : json.optString(NAME); | ||
| 266 | + this.postal_code = json.optString(POSTAL_CODE); | ||
| 267 | + this.region = json.optString(REGION); | ||
| 268 | + this.telephone = json.isNull(TELEPHONE) ? "" : json.optString(TELEPHONE); | ||
| 269 | + this.merchant_metadata = json.optJSONObject(MERCHANT_METADATA); | ||
| 270 | + | ||
| 271 | +// this.id = json.optString(ID); | ||
| 272 | +// this.store_id = json.optString(STORE_ID); | ||
| 273 | +// this.website = json.optString(WEBSITE); | ||
| 274 | +// this.email = json.optString(EMAIL); | ||
| 275 | +// this.category = json.optString(CATEGORY); | ||
| 276 | +// this.description = json.optString(DESCRIPTION); | ||
| 277 | +// this.short_description = json.optString(SHORT_DESCRIPTION); | ||
| 278 | +// this.latitude = json.isNull(LAT) ? 0.0 : json.optDouble(LAT); | ||
| 279 | +// this.longitude = json.isNull(LON) ? 0.0 : json.optDouble(LON); | ||
| 280 | +// this.image = json.optString(IMAGE); | ||
| 281 | +// this.extra_fields = json.optJSONObject(EXTRA_FIELDS); | ||
| 282 | +// this.active = json.optBoolean(ACTIVE); | ||
| 283 | +// this.vat = json.optString(VAT); | ||
| 284 | +// this.uuid = json.optString(UUID); | ||
| 285 | +// this.category_uuid = json.optString(CATEGORY_UUID); | ||
| 286 | +// this.created = json.optString(CREATED); | ||
| 287 | +// this.parent = json.optString(PARENT); | ||
| 288 | +// this.img = json.optJSONArray(IMG); | ||
| 289 | +// this.img_preview = json.optString(IMG_PREVIEW); | ||
| 290 | +// this.admin_name = json.optString(ADMIN_NAME); | ||
| 291 | +// this.sorting = json.optInt(SORTING); | ||
| 292 | +// this.owner_name = json.optString(OWNER_NAME); | ||
| 293 | +// this.preview = json.optString(PREVIEW); | ||
| 294 | +// this.promoted = json.optBoolean(PROMOTED); | ||
| 295 | +// this.distance = json.optInt(DISTANCE); | ||
| 296 | +// this.default_shown = json.optBoolean(DEFAULT_SHOWN); | ||
| 297 | +// this.hidden = json.optBoolean(HIDDEN); | ||
| 298 | +// this.working_hours = json.optJSONObject(WORKING_HOURS); | ||
| 299 | +// this.tags = json.optJSONArray(TAGS); | ||
| 300 | +// this.product = json.optJSONObject(PRODUCT); | ||
| 301 | +// coordinates = new LatLng(this.latitude, this.longitude); | ||
| 302 | + } | ||
| 303 | + } | ||
| 304 | + | ||
| 245 | public Merchant(Parcel source) { | 305 | public Merchant(Parcel source) { |
| 246 | this.address = source.readString(); | 306 | this.address = source.readString(); |
| 247 | this.id = source.readString(); | 307 | this.id = source.readString(); | ... | ... |
| ... | @@ -1570,222 +1570,28 @@ public class WarplyManager { | ... | @@ -1570,222 +1570,28 @@ public class WarplyManager { |
| 1570 | ListenableFuture<CouponsetsList> futureCouponsets = getCouponsetsRetro(service); | 1570 | ListenableFuture<CouponsetsList> futureCouponsets = getCouponsetsRetro(service); |
| 1571 | ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service); | 1571 | ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service); |
| 1572 | 1572 | ||
| 1573 | -// getMerchantsRetro(service, new Callback<ResponseBody>() { | 1573 | + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMerchants, futureCouponsets, futureCoupons); |
| 1574 | -// @Override | 1574 | + ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync( |
| 1575 | -// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) { | 1575 | + allResultsFuture, |
| 1576 | -// if (responseMerchants.code() == 200 && responseMerchants.body() != null) { | 1576 | + results -> { |
| 1577 | -// JSONObject jobjMerchantsResponse = null; | 1577 | + CouponList resultCoupons = (CouponList) results.get(2); |
| 1578 | -// try { | 1578 | + return executorService.submit(() -> resultCoupons); |
| 1579 | -// jobjMerchantsResponse = new JSONObject(responseMerchants.body().string()); | 1579 | + }, |
| 1580 | -// } catch (Exception e) { | 1580 | + executorService |
| 1581 | -// e.printStackTrace(); | 1581 | + ); |
| 1582 | -// } | 1582 | + |
| 1583 | -// | 1583 | + Futures.addCallback(mergedResultFuture, new FutureCallback<CouponList>() { |
| 1584 | -// if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) { | 1584 | + @Override |
| 1585 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 1585 | + public void onSuccess(CouponList mergedResult) { |
| 1586 | -// dynatraceEvent.setEventName("custom_success_shops_loyalty"); | 1586 | + executorService.shutdownNow(); |
| 1587 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 1587 | + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult)); |
| 1588 | -// | 1588 | + } |
| 1589 | -// JSONArray jMerchantsBody = null; | 1589 | + |
| 1590 | -// try { | 1590 | + @Override |
| 1591 | -// jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result"); | 1591 | + public void onFailure(Throwable throwable) { |
| 1592 | -// } catch (Exception e) { | 1592 | + receiver.onFailure(2); |
| 1593 | -// e.printStackTrace(); | 1593 | + } |
| 1594 | -// } | 1594 | + }, executorService); |
| 1595 | -// | ||
| 1596 | -// if (jMerchantsBody != null) { | ||
| 1597 | -// MerchantList mMerchantList = new MerchantList(); | ||
| 1598 | -// | ||
| 1599 | -// final ExecutorService executorShops = Executors.newFixedThreadPool(1); | ||
| 1600 | -// JSONArray finalMerchantsJBody = jMerchantsBody; | ||
| 1601 | -// executorShops.submit(() -> { | ||
| 1602 | -// for (int i = 0; i < finalMerchantsJBody.length(); ++i) { | ||
| 1603 | -// mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i))); | ||
| 1604 | -// } | ||
| 1605 | -// WarplyManagerHelper.setMerchantList(mMerchantList); | ||
| 1606 | -// executorShops.shutdownNow(); | ||
| 1607 | -// }); | ||
| 1608 | -// | ||
| 1609 | -// getCouponsetsRetro(service, new Callback<ResponseBody>() { | ||
| 1610 | -// @Override | ||
| 1611 | -// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) { | ||
| 1612 | -// if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) { | ||
| 1613 | -// JSONObject jobjCouponsetsResponse = null; | ||
| 1614 | -// try { | ||
| 1615 | -// jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string()); | ||
| 1616 | -// } catch (Exception e) { | ||
| 1617 | -// e.printStackTrace(); | ||
| 1618 | -// } | ||
| 1619 | -// | ||
| 1620 | -// if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) { | ||
| 1621 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1622 | -// dynatraceEvent.setEventName("custom_success_couponsets_loyalty"); | ||
| 1623 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1624 | -// | ||
| 1625 | -// JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse; | ||
| 1626 | -// getUserCouponsRetro(service, new Callback<ResponseBody>() { | ||
| 1627 | -// @Override | ||
| 1628 | -// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) { | ||
| 1629 | -// if (responseCoupons.code() == 200 && responseCoupons.body() != null) { | ||
| 1630 | -// JSONObject jobjCouponsResponse = null; | ||
| 1631 | -// try { | ||
| 1632 | -// jobjCouponsResponse = new JSONObject(responseCoupons.body().string()); | ||
| 1633 | -// } catch (Exception e) { | ||
| 1634 | -// e.printStackTrace(); | ||
| 1635 | -// } | ||
| 1636 | -// | ||
| 1637 | -// if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) { | ||
| 1638 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1639 | -// dynatraceEvent.setEventName("custom_success_user_coupons_loyalty"); | ||
| 1640 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1641 | -// | ||
| 1642 | -// JSONObject finalJobjCouponsResponse = jobjCouponsResponse; | ||
| 1643 | -// final ExecutorService executor = Executors.newFixedThreadPool(1); | ||
| 1644 | -// executor.submit(() -> { | ||
| 1645 | -// // COUPONS START // | ||
| 1646 | -// JSONArray jCouponsBody = null; | ||
| 1647 | -// try { | ||
| 1648 | -// jCouponsBody = finalJobjCouponsResponse.optJSONArray("result"); | ||
| 1649 | -// } catch (Exception e) { | ||
| 1650 | -// e.printStackTrace(); | ||
| 1651 | -// } | ||
| 1652 | -// // COUPONS END // | ||
| 1653 | -// | ||
| 1654 | -// // COUPONSETS START // | ||
| 1655 | -// JSONArray jCouponsetsBody = null; | ||
| 1656 | -// try { | ||
| 1657 | -// jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON"); | ||
| 1658 | -// } catch (Exception e) { | ||
| 1659 | -// e.printStackTrace(); | ||
| 1660 | -// } | ||
| 1661 | -// // COUPONSETS END // | ||
| 1662 | -// | ||
| 1663 | -// if (jCouponsetsBody != null && jCouponsBody != null) { | ||
| 1664 | -// CouponList mCouponList = new CouponList(); | ||
| 1665 | -// CouponList mCouponRedeemedList = new CouponList(); | ||
| 1666 | -// CouponsetsList mCouponsetList = new CouponsetsList(); | ||
| 1667 | -// for (int i = 0; i < jCouponsetsBody.length(); ++i) { | ||
| 1668 | -// Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i)); | ||
| 1669 | -// mCouponsetList.add(tempCouponset); | ||
| 1670 | -// for (int j = 0; j < jCouponsBody.length(); ++j) { | ||
| 1671 | -// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); | ||
| 1672 | -// if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) { | ||
| 1673 | -// tempCoupon.setDescription(tempCouponset.getShortDescription()); | ||
| 1674 | -// tempCoupon.setImage(tempCouponset.getImgPreview()); | ||
| 1675 | -// tempCoupon.setName(tempCouponset.getName()); | ||
| 1676 | -// tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid()); | ||
| 1677 | -// tempCoupon.setInnerText(tempCouponset.getInnerText()); | ||
| 1678 | -// tempCoupon.setDiscount_type(tempCouponset.getDiscount_type()); | ||
| 1679 | -// tempCoupon.setFinal_price(tempCouponset.getFinal_price()); | ||
| 1680 | -// mCouponList.add(tempCoupon); | ||
| 1681 | -// } | ||
| 1682 | -// } | ||
| 1683 | -// } | ||
| 1684 | -// | ||
| 1685 | -// for (int j = 0; j < jCouponsBody.length(); ++j) { | ||
| 1686 | -// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j)); | ||
| 1687 | -// if (tempCoupon.getStatus() == 0) { | ||
| 1688 | -// mCouponRedeemedList.add(tempCoupon); | ||
| 1689 | -// } | ||
| 1690 | -// } | ||
| 1691 | -// WarplyManagerHelper.setCouponsets(mCouponsetList); | ||
| 1692 | -// WarplyManagerHelper.setCouponList(mCouponList); | ||
| 1693 | -// WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList); | ||
| 1694 | -// | ||
| 1695 | -// CouponList mActiveCouponList = new CouponList(); | ||
| 1696 | -// for (Coupon coupon : mCouponList) { | ||
| 1697 | -// if (coupon.getStatus() == 1) { | ||
| 1698 | -// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); | ||
| 1699 | -// Date newDate = new Date(); | ||
| 1700 | -// try { | ||
| 1701 | -// newDate = simpleDateFormat.parse(coupon.getExpiration()); | ||
| 1702 | -// } catch ( | ||
| 1703 | -// ParseException e) { | ||
| 1704 | -// e.printStackTrace(); | ||
| 1705 | -// } | ||
| 1706 | -// coupon.setExpirationDate(newDate); | ||
| 1707 | -// mActiveCouponList.add(coupon); | ||
| 1708 | -// } | ||
| 1709 | -// } | ||
| 1710 | -// | ||
| 1711 | -// Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate())); | ||
| 1712 | -// | ||
| 1713 | -// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList)); | ||
| 1714 | -// executor.shutdownNow(); | ||
| 1715 | -// } | ||
| 1716 | -// }); | ||
| 1717 | -// } else { | ||
| 1718 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1719 | -// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 1720 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1721 | -// receiver.onFailure(2); | ||
| 1722 | -// } | ||
| 1723 | -// } else { | ||
| 1724 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1725 | -// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 1726 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1727 | -// receiver.onFailure(responseCoupons.code()); | ||
| 1728 | -// } | ||
| 1729 | -// } | ||
| 1730 | -// | ||
| 1731 | -// @Override | ||
| 1732 | -// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 1733 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1734 | -// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ||
| 1735 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1736 | -// receiver.onFailure(2); | ||
| 1737 | -// } | ||
| 1738 | -// }); | ||
| 1739 | -// | ||
| 1740 | -// } else { | ||
| 1741 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1742 | -// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 1743 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1744 | -// receiver.onFailure(2); | ||
| 1745 | -// } | ||
| 1746 | -// | ||
| 1747 | -// } else { | ||
| 1748 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1749 | -// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 1750 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1751 | -// receiver.onFailure(responseCouponsets.code()); | ||
| 1752 | -// } | ||
| 1753 | -// } | ||
| 1754 | -// | ||
| 1755 | -// @Override | ||
| 1756 | -// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 1757 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1758 | -// dynatraceEvent.setEventName("custom_error_couponsets_loyalty"); | ||
| 1759 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1760 | -// receiver.onFailure(2); | ||
| 1761 | -// } | ||
| 1762 | -// }); | ||
| 1763 | -// } | ||
| 1764 | -// } else { | ||
| 1765 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1766 | -// dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 1767 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1768 | -// | ||
| 1769 | -// receiver.onFailure(2); | ||
| 1770 | -// } | ||
| 1771 | -// } else { | ||
| 1772 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1773 | -// dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 1774 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1775 | -// | ||
| 1776 | -// receiver.onFailure(responseMerchants.code()); | ||
| 1777 | -// } | ||
| 1778 | -// } | ||
| 1779 | -// | ||
| 1780 | -// @Override | ||
| 1781 | -// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 1782 | -// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 1783 | -// dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 1784 | -// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 1785 | -// | ||
| 1786 | -// receiver.onFailure(2); | ||
| 1787 | -// } | ||
| 1788 | -// }); | ||
| 1789 | } | 1595 | } |
| 1790 | 1596 | ||
| 1791 | public static void getCampaigns(final CallbackReceiver<ArrayList<Campaign>> receiver) { | 1597 | public static void getCampaigns(final CallbackReceiver<ArrayList<Campaign>> receiver) { |
| ... | @@ -4538,19 +4344,40 @@ public class WarplyManager { | ... | @@ -4538,19 +4344,40 @@ public class WarplyManager { |
| 4538 | 4344 | ||
| 4539 | if (jCouponsBody != null) { | 4345 | if (jCouponsBody != null) { |
| 4540 | CouponList mCouponsList = new CouponList(); | 4346 | CouponList mCouponsList = new CouponList(); |
| 4541 | -// | 4347 | + CouponList mCouponRedeemedList = new CouponList(); |
| 4348 | + CouponList mActiveCouponList = new CouponList(); | ||
| 4349 | + | ||
| 4542 | final ExecutorService executorCoupons = Executors.newFixedThreadPool(1); | 4350 | final ExecutorService executorCoupons = Executors.newFixedThreadPool(1); |
| 4543 | JSONArray finalJCouponsBody = jCouponsBody; | 4351 | JSONArray finalJCouponsBody = jCouponsBody; |
| 4544 | executorCoupons.submit(() -> { | 4352 | executorCoupons.submit(() -> { |
| 4545 | for (int i = 0; i < finalJCouponsBody.length(); ++i) { | 4353 | for (int i = 0; i < finalJCouponsBody.length(); ++i) { |
| 4546 | Coupon tempCoupon = new Coupon(finalJCouponsBody.optJSONObject(i), true); | 4354 | Coupon tempCoupon = new Coupon(finalJCouponsBody.optJSONObject(i), true); |
| 4547 | mCouponsList.add(tempCoupon); | 4355 | mCouponsList.add(tempCoupon); |
| 4356 | + | ||
| 4357 | + if (tempCoupon.getStatus() == 0) { | ||
| 4358 | + mCouponRedeemedList.add(tempCoupon); | ||
| 4359 | + } else if (tempCoupon.getStatus() == 1) { | ||
| 4360 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); | ||
| 4361 | + Date newDate = new Date(); | ||
| 4362 | + try { | ||
| 4363 | + newDate = simpleDateFormat.parse(tempCoupon.getExpiration()); | ||
| 4364 | + } catch ( | ||
| 4365 | + ParseException e) { | ||
| 4366 | + e.printStackTrace(); | ||
| 4367 | + } | ||
| 4368 | + tempCoupon.setExpirationDate(newDate); | ||
| 4369 | + mActiveCouponList.add(tempCoupon); | ||
| 4370 | + } | ||
| 4548 | } | 4371 | } |
| 4549 | 4372 | ||
| 4550 | -// WarplyManagerHelper.setCouponsets(mCouponsetList); | 4373 | + WarplyManagerHelper.setCouponList(mCouponsList); |
| 4374 | + WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList); | ||
| 4375 | + | ||
| 4376 | + Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate())); | ||
| 4377 | + | ||
| 4551 | executorCoupons.shutdownNow(); | 4378 | executorCoupons.shutdownNow(); |
| 4552 | 4379 | ||
| 4553 | - future.set(mCouponsList); | 4380 | + future.set(mActiveCouponList); |
| 4554 | }); | 4381 | }); |
| 4555 | } | 4382 | } |
| 4556 | } else { | 4383 | } else { |
| ... | @@ -4581,8 +4408,6 @@ public class WarplyManager { | ... | @@ -4581,8 +4408,6 @@ public class WarplyManager { |
| 4581 | EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | 4408 | EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); |
| 4582 | future.set(new CouponList()); | 4409 | future.set(new CouponList()); |
| 4583 | } | 4410 | } |
| 4584 | - | ||
| 4585 | - future.set(new CouponList()); | ||
| 4586 | } | 4411 | } |
| 4587 | 4412 | ||
| 4588 | @Override | 4413 | @Override | ... | ... |
-
Please register or login to post a comment