new coupons request for sm inside getUnifiedCouponsDeals and new static variable for this list
Showing
3 changed files
with
200 additions
and
287 deletions
.idea/other.xml
deleted
100644 → 0
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<project version="4"> | ||
3 | - <component name="direct_access_persist.xml"> | ||
4 | - <option name="deviceSelectionList"> | ||
5 | - <list> | ||
6 | - <PersistentDeviceSelectionData> | ||
7 | - <option name="api" value="27" /> | ||
8 | - <option name="brand" value="DOCOMO" /> | ||
9 | - <option name="codename" value="F01L" /> | ||
10 | - <option name="id" value="F01L" /> | ||
11 | - <option name="manufacturer" value="FUJITSU" /> | ||
12 | - <option name="name" value="F-01L" /> | ||
13 | - <option name="screenDensity" value="360" /> | ||
14 | - <option name="screenX" value="720" /> | ||
15 | - <option name="screenY" value="1280" /> | ||
16 | - </PersistentDeviceSelectionData> | ||
17 | - <PersistentDeviceSelectionData> | ||
18 | - <option name="api" value="28" /> | ||
19 | - <option name="brand" value="DOCOMO" /> | ||
20 | - <option name="codename" value="SH-01L" /> | ||
21 | - <option name="id" value="SH-01L" /> | ||
22 | - <option name="manufacturer" value="SHARP" /> | ||
23 | - <option name="name" value="AQUOS sense2 SH-01L" /> | ||
24 | - <option name="screenDensity" value="480" /> | ||
25 | - <option name="screenX" value="1080" /> | ||
26 | - <option name="screenY" value="2160" /> | ||
27 | - </PersistentDeviceSelectionData> | ||
28 | - <PersistentDeviceSelectionData> | ||
29 | - <option name="api" value="31" /> | ||
30 | - <option name="brand" value="samsung" /> | ||
31 | - <option name="codename" value="a51" /> | ||
32 | - <option name="id" value="a51" /> | ||
33 | - <option name="manufacturer" value="Samsung" /> | ||
34 | - <option name="name" value="Galaxy A51" /> | ||
35 | - <option name="screenDensity" value="420" /> | ||
36 | - <option name="screenX" value="1080" /> | ||
37 | - <option name="screenY" value="2400" /> | ||
38 | - </PersistentDeviceSelectionData> | ||
39 | - <PersistentDeviceSelectionData> | ||
40 | - <option name="api" value="34" /> | ||
41 | - <option name="brand" value="google" /> | ||
42 | - <option name="codename" value="akita" /> | ||
43 | - <option name="id" value="akita" /> | ||
44 | - <option name="manufacturer" value="Google" /> | ||
45 | - <option name="name" value="Pixel 8a" /> | ||
46 | - <option name="screenDensity" value="420" /> | ||
47 | - <option name="screenX" value="1080" /> | ||
48 | - <option name="screenY" value="2400" /> | ||
49 | - </PersistentDeviceSelectionData> | ||
50 | - <PersistentDeviceSelectionData> | ||
51 | - <option name="api" value="33" /> | ||
52 | - <option name="brand" value="samsung" /> | ||
53 | - <option name="codename" value="b0q" /> | ||
54 | - <option name="id" value="b0q" /> | ||
55 | - <option name="manufacturer" value="Samsung" /> | ||
56 | - <option name="name" value="Galaxy S22 Ultra" /> | ||
57 | - <option name="screenDensity" value="600" /> | ||
58 | - <option name="screenX" value="1440" /> | ||
59 | - <option name="screenY" value="3088" /> | ||
60 | - </PersistentDeviceSelectionData> | ||
61 | - <PersistentDeviceSelectionData> | ||
62 | - <option name="api" value="32" /> | ||
63 | - <option name="brand" value="google" /> | ||
64 | - <option name="codename" value="bluejay" /> | ||
65 | - <option name="id" value="bluejay" /> | ||
66 | - <option name="manufacturer" value="Google" /> | ||
67 | - <option name="name" value="Pixel 6a" /> | ||
68 | - <option name="screenDensity" value="420" /> | ||
69 | - <option name="screenX" value="1080" /> | ||
70 | - <option name="screenY" value="2400" /> | ||
71 | - </PersistentDeviceSelectionData> | ||
72 | - <PersistentDeviceSelectionData> | ||
73 | - <option name="api" value="29" /> | ||
74 | - <option name="brand" value="samsung" /> | ||
75 | - <option name="codename" value="crownqlteue" /> | ||
76 | - <option name="id" value="crownqlteue" /> | ||
77 | - <option name="manufacturer" value="Samsung" /> | ||
78 | - <option name="name" value="Galaxy Note9" /> | ||
79 | - <option name="screenDensity" value="420" /> | ||
80 | - <option name="screenX" value="2220" /> | ||
81 | - <option name="screenY" value="1080" /> | ||
82 | - </PersistentDeviceSelectionData> | ||
83 | - <PersistentDeviceSelectionData> | ||
84 | - <option name="api" value="34" /> | ||
85 | - <option name="brand" value="samsung" /> | ||
86 | - <option name="codename" value="dm3q" /> | ||
87 | - <option name="id" value="dm3q" /> | ||
88 | - <option name="manufacturer" value="Samsung" /> | ||
89 | - <option name="name" value="Galaxy S23 Ultra" /> | ||
90 | - <option name="screenDensity" value="600" /> | ||
91 | - <option name="screenX" value="1440" /> | ||
92 | - <option name="screenY" value="3088" /> | ||
93 | - </PersistentDeviceSelectionData> | ||
94 | - <PersistentDeviceSelectionData> | ||
95 | - <option name="api" value="33" /> | ||
96 | - <option name="brand" value="google" /> | ||
97 | - <option name="codename" value="felix" /> | ||
98 | - <option name="id" value="felix" /> | ||
99 | - <option name="manufacturer" value="Google" /> | ||
100 | - <option name="name" value="Pixel Fold" /> | ||
101 | - <option name="screenDensity" value="420" /> | ||
102 | - <option name="screenX" value="2208" /> | ||
103 | - <option name="screenY" value="1840" /> | ||
104 | - </PersistentDeviceSelectionData> | ||
105 | - <PersistentDeviceSelectionData> | ||
106 | - <option name="api" value="33" /> | ||
107 | - <option name="brand" value="google" /> | ||
108 | - <option name="codename" value="felix_camera" /> | ||
109 | - <option name="id" value="felix_camera" /> | ||
110 | - <option name="manufacturer" value="Google" /> | ||
111 | - <option name="name" value="Pixel Fold (Camera-enabled)" /> | ||
112 | - <option name="screenDensity" value="420" /> | ||
113 | - <option name="screenX" value="2208" /> | ||
114 | - <option name="screenY" value="1840" /> | ||
115 | - </PersistentDeviceSelectionData> | ||
116 | - <PersistentDeviceSelectionData> | ||
117 | - <option name="api" value="33" /> | ||
118 | - <option name="brand" value="samsung" /> | ||
119 | - <option name="codename" value="gts8uwifi" /> | ||
120 | - <option name="id" value="gts8uwifi" /> | ||
121 | - <option name="manufacturer" value="Samsung" /> | ||
122 | - <option name="name" value="Galaxy Tab S8 Ultra" /> | ||
123 | - <option name="screenDensity" value="320" /> | ||
124 | - <option name="screenX" value="1848" /> | ||
125 | - <option name="screenY" value="2960" /> | ||
126 | - </PersistentDeviceSelectionData> | ||
127 | - <PersistentDeviceSelectionData> | ||
128 | - <option name="api" value="34" /> | ||
129 | - <option name="brand" value="google" /> | ||
130 | - <option name="codename" value="husky" /> | ||
131 | - <option name="id" value="husky" /> | ||
132 | - <option name="manufacturer" value="Google" /> | ||
133 | - <option name="name" value="Pixel 8 Pro" /> | ||
134 | - <option name="screenDensity" value="390" /> | ||
135 | - <option name="screenX" value="1008" /> | ||
136 | - <option name="screenY" value="2244" /> | ||
137 | - </PersistentDeviceSelectionData> | ||
138 | - <PersistentDeviceSelectionData> | ||
139 | - <option name="api" value="30" /> | ||
140 | - <option name="brand" value="motorola" /> | ||
141 | - <option name="codename" value="java" /> | ||
142 | - <option name="id" value="java" /> | ||
143 | - <option name="manufacturer" value="Motorola" /> | ||
144 | - <option name="name" value="G20" /> | ||
145 | - <option name="screenDensity" value="280" /> | ||
146 | - <option name="screenX" value="720" /> | ||
147 | - <option name="screenY" value="1600" /> | ||
148 | - </PersistentDeviceSelectionData> | ||
149 | - <PersistentDeviceSelectionData> | ||
150 | - <option name="api" value="33" /> | ||
151 | - <option name="brand" value="google" /> | ||
152 | - <option name="codename" value="lynx" /> | ||
153 | - <option name="id" value="lynx" /> | ||
154 | - <option name="manufacturer" value="Google" /> | ||
155 | - <option name="name" value="Pixel 7a" /> | ||
156 | - <option name="screenDensity" value="420" /> | ||
157 | - <option name="screenX" value="1080" /> | ||
158 | - <option name="screenY" value="2400" /> | ||
159 | - </PersistentDeviceSelectionData> | ||
160 | - <PersistentDeviceSelectionData> | ||
161 | - <option name="api" value="31" /> | ||
162 | - <option name="brand" value="google" /> | ||
163 | - <option name="codename" value="oriole" /> | ||
164 | - <option name="id" value="oriole" /> | ||
165 | - <option name="manufacturer" value="Google" /> | ||
166 | - <option name="name" value="Pixel 6" /> | ||
167 | - <option name="screenDensity" value="420" /> | ||
168 | - <option name="screenX" value="1080" /> | ||
169 | - <option name="screenY" value="2400" /> | ||
170 | - </PersistentDeviceSelectionData> | ||
171 | - <PersistentDeviceSelectionData> | ||
172 | - <option name="api" value="33" /> | ||
173 | - <option name="brand" value="google" /> | ||
174 | - <option name="codename" value="panther" /> | ||
175 | - <option name="id" value="panther" /> | ||
176 | - <option name="manufacturer" value="Google" /> | ||
177 | - <option name="name" value="Pixel 7" /> | ||
178 | - <option name="screenDensity" value="420" /> | ||
179 | - <option name="screenX" value="1080" /> | ||
180 | - <option name="screenY" value="2400" /> | ||
181 | - </PersistentDeviceSelectionData> | ||
182 | - <PersistentDeviceSelectionData> | ||
183 | - <option name="api" value="31" /> | ||
184 | - <option name="brand" value="samsung" /> | ||
185 | - <option name="codename" value="q2q" /> | ||
186 | - <option name="id" value="q2q" /> | ||
187 | - <option name="manufacturer" value="Samsung" /> | ||
188 | - <option name="name" value="Galaxy Z Fold3" /> | ||
189 | - <option name="screenDensity" value="420" /> | ||
190 | - <option name="screenX" value="1768" /> | ||
191 | - <option name="screenY" value="2208" /> | ||
192 | - </PersistentDeviceSelectionData> | ||
193 | - <PersistentDeviceSelectionData> | ||
194 | - <option name="api" value="34" /> | ||
195 | - <option name="brand" value="samsung" /> | ||
196 | - <option name="codename" value="q5q" /> | ||
197 | - <option name="id" value="q5q" /> | ||
198 | - <option name="manufacturer" value="Samsung" /> | ||
199 | - <option name="name" value="Galaxy Z Fold5" /> | ||
200 | - <option name="screenDensity" value="420" /> | ||
201 | - <option name="screenX" value="1812" /> | ||
202 | - <option name="screenY" value="2176" /> | ||
203 | - </PersistentDeviceSelectionData> | ||
204 | - <PersistentDeviceSelectionData> | ||
205 | - <option name="api" value="30" /> | ||
206 | - <option name="brand" value="google" /> | ||
207 | - <option name="codename" value="r11" /> | ||
208 | - <option name="id" value="r11" /> | ||
209 | - <option name="manufacturer" value="Google" /> | ||
210 | - <option name="name" value="Pixel Watch" /> | ||
211 | - <option name="screenDensity" value="320" /> | ||
212 | - <option name="screenX" value="384" /> | ||
213 | - <option name="screenY" value="384" /> | ||
214 | - <option name="type" value="WEAR_OS" /> | ||
215 | - </PersistentDeviceSelectionData> | ||
216 | - <PersistentDeviceSelectionData> | ||
217 | - <option name="api" value="30" /> | ||
218 | - <option name="brand" value="google" /> | ||
219 | - <option name="codename" value="redfin" /> | ||
220 | - <option name="id" value="redfin" /> | ||
221 | - <option name="manufacturer" value="Google" /> | ||
222 | - <option name="name" value="Pixel 5" /> | ||
223 | - <option name="screenDensity" value="440" /> | ||
224 | - <option name="screenX" value="1080" /> | ||
225 | - <option name="screenY" value="2340" /> | ||
226 | - </PersistentDeviceSelectionData> | ||
227 | - <PersistentDeviceSelectionData> | ||
228 | - <option name="api" value="34" /> | ||
229 | - <option name="brand" value="google" /> | ||
230 | - <option name="codename" value="shiba" /> | ||
231 | - <option name="id" value="shiba" /> | ||
232 | - <option name="manufacturer" value="Google" /> | ||
233 | - <option name="name" value="Pixel 8" /> | ||
234 | - <option name="screenDensity" value="420" /> | ||
235 | - <option name="screenX" value="1080" /> | ||
236 | - <option name="screenY" value="2400" /> | ||
237 | - </PersistentDeviceSelectionData> | ||
238 | - <PersistentDeviceSelectionData> | ||
239 | - <option name="api" value="33" /> | ||
240 | - <option name="brand" value="google" /> | ||
241 | - <option name="codename" value="tangorpro" /> | ||
242 | - <option name="id" value="tangorpro" /> | ||
243 | - <option name="manufacturer" value="Google" /> | ||
244 | - <option name="name" value="Pixel Tablet" /> | ||
245 | - <option name="screenDensity" value="320" /> | ||
246 | - <option name="screenX" value="1600" /> | ||
247 | - <option name="screenY" value="2560" /> | ||
248 | - </PersistentDeviceSelectionData> | ||
249 | - <PersistentDeviceSelectionData> | ||
250 | - <option name="api" value="29" /> | ||
251 | - <option name="brand" value="samsung" /> | ||
252 | - <option name="codename" value="x1q" /> | ||
253 | - <option name="id" value="x1q" /> | ||
254 | - <option name="manufacturer" value="Samsung" /> | ||
255 | - <option name="name" value="Galaxy S20" /> | ||
256 | - <option name="screenDensity" value="480" /> | ||
257 | - <option name="screenX" value="1440" /> | ||
258 | - <option name="screenY" value="3200" /> | ||
259 | - </PersistentDeviceSelectionData> | ||
260 | - </list> | ||
261 | - </option> | ||
262 | - </component> | ||
263 | -</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -105,6 +105,7 @@ public class WarplyManagerHelper { | ... | @@ -105,6 +105,7 @@ public class WarplyManagerHelper { |
105 | private static HashMap<String, CampaignList> mUniqueCampaignList = new HashMap<String, CampaignList>(); | 105 | private static HashMap<String, CampaignList> mUniqueCampaignList = new HashMap<String, CampaignList>(); |
106 | private static CouponList mCouponList = new CouponList(); | 106 | private static CouponList mCouponList = new CouponList(); |
107 | private static CouponList mCouponRedeemedList = new CouponList(); | 107 | private static CouponList mCouponRedeemedList = new CouponList(); |
108 | + private static CouponList mSmCouponsList = new CouponList(); | ||
108 | private static CouponList mCouponListExpired = new CouponList(); | 109 | private static CouponList mCouponListExpired = new CouponList(); |
109 | private static CouponsetsList mCouponsetsList = new CouponsetsList(); | 110 | private static CouponsetsList mCouponsetsList = new CouponsetsList(); |
110 | private static CouponsetsList mCouponsetsDealsList = new CouponsetsList(); | 111 | private static CouponsetsList mCouponsetsDealsList = new CouponsetsList(); |
... | @@ -1368,10 +1369,19 @@ public class WarplyManagerHelper { | ... | @@ -1368,10 +1369,19 @@ public class WarplyManagerHelper { |
1368 | mCouponRedeemedList.addAll(couponRedeemedList); | 1369 | mCouponRedeemedList.addAll(couponRedeemedList); |
1369 | } | 1370 | } |
1370 | 1371 | ||
1372 | + public static void setSmCouponsList(CouponList couponRedeemedList) { | ||
1373 | + mSmCouponsList.clear(); | ||
1374 | + mSmCouponsList.addAll(couponRedeemedList); | ||
1375 | + } | ||
1376 | + | ||
1371 | public static CouponList getCouponRedeemedList() { | 1377 | public static CouponList getCouponRedeemedList() { |
1372 | return mCouponRedeemedList; | 1378 | return mCouponRedeemedList; |
1373 | } | 1379 | } |
1374 | 1380 | ||
1381 | + public static CouponList getSmCouponsList() { | ||
1382 | + return mSmCouponsList; | ||
1383 | + } | ||
1384 | + | ||
1375 | public static LoyaltyBadgeModel getLoyaltyBadge() { | 1385 | public static LoyaltyBadgeModel getLoyaltyBadge() { |
1376 | return mLoyaltyBadge; | 1386 | return mLoyaltyBadge; |
1377 | } | 1387 | } | ... | ... |
... | @@ -3123,30 +3123,60 @@ public class WarplyManager { | ... | @@ -3123,30 +3123,60 @@ public class WarplyManager { |
3123 | e.printStackTrace(); | 3123 | e.printStackTrace(); |
3124 | } | 3124 | } |
3125 | 3125 | ||
3126 | -// if (allCouponList != null && allCouponList.size() > 0) { | 3126 | + CouponList mTempActiveSMCoupons = new CouponList(); |
3127 | -// float countValue = 0.0f; | 3127 | + for (UnifiedCoupon uni : couponList) { |
3128 | -// if (WarplyManagerHelper.getCouponRedeemedList().size() > 0) { | 3128 | + if (!uni.getCoupons().isEmpty()) { |
3129 | -// if (WarplyManagerHelper.getCouponsetsDeals().size() > 0) { | 3129 | + for (Coupon coupon : uni.getCoupons()) { |
3130 | -// for (Couponset couset : WarplyManagerHelper.getCouponsetsDeals()) { | 3130 | + if (coupon.getStatus() == 1) { |
3131 | -// for (Coupon cou : WarplyManagerHelper.getCouponRedeemedList()) { | 3131 | + Coupon tempCoupon = coupon; |
3132 | -// if (cou.getCouponsetUuid().equals(couset.getUuid())) { | 3132 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); |
3133 | -// countValue += Float.parseFloat(cou.getDiscount()); | 3133 | + Date newDate = new Date(); |
3134 | -// cou.setDescription(couset.getShortDescription()); | 3134 | + try { |
3135 | -// cou.setImage(couset.getImgPreview()); | 3135 | + newDate = simpleDateFormat.parse(tempCoupon.getExpiration()); |
3136 | -// cou.setName(couset.getName()); | 3136 | + } catch ( |
3137 | -// cou.setMerchantUuid(couset.getMerchantUuid()); | 3137 | + ParseException e) { |
3138 | -// cou.setInnerText(couset.getInnerText()); | 3138 | + e.printStackTrace(); |
3139 | -// cou.setDiscount_type(couset.getDiscount_type()); | 3139 | + } |
3140 | -// cou.setFinal_price(couset.getFinal_price()); | 3140 | + tempCoupon.setExpirationDate(newDate); |
3141 | -// break; | 3141 | + mTempActiveSMCoupons.add(tempCoupon); |
3142 | -// } | 3142 | + } |
3143 | -// } | 3143 | + } |
3144 | -// } | 3144 | + } |
3145 | -// } | 3145 | + } |
3146 | -// } | 3146 | + |
3147 | -// | 3147 | + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)); |
3148 | -// WarplyManagerHelper.setUnifiedCouponsDiscount(countValue); | 3148 | + SettableFuture<CouponList> futureUniversal = SettableFuture.create(); |
3149 | -// } | 3149 | + ListenableFuture<CouponList> futureCoupons = getSMCouponsUniversalRetro(service, 0, futureUniversal); |
3150 | + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCoupons); | ||
3151 | + ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync( | ||
3152 | + allResultsFuture, | ||
3153 | + results -> { | ||
3154 | + CouponList resultCoupons = (CouponList) results.get(0); | ||
3155 | + return executorService.submit(() -> resultCoupons); | ||
3156 | + }, | ||
3157 | + executorService | ||
3158 | + ); | ||
3159 | + | ||
3160 | + Futures.addCallback(mergedResultFuture, new FutureCallback<CouponList>() { | ||
3161 | + @Override | ||
3162 | + public void onSuccess(CouponList mergedResult) { | ||
3163 | + CouponList mfinalActiveSMCoupons = new CouponList(); | ||
3164 | + for (Coupon mergedItem : mergedResult) { | ||
3165 | + for (Coupon tempItem : mTempActiveSMCoupons) { | ||
3166 | + if (!mergedItem.getCoupon().equals(tempItem.getCoupon())) { | ||
3167 | + mfinalActiveSMCoupons.add(mergedItem); | ||
3168 | + } | ||
3169 | + } | ||
3170 | + } | ||
3171 | + WarplyManagerHelper.setSmCouponsList(mfinalActiveSMCoupons); | ||
3172 | + executorService.shutdownNow(); | ||
3173 | + } | ||
3174 | + | ||
3175 | + @Override | ||
3176 | + public void onFailure(Throwable throwable) { | ||
3177 | + executorService.shutdownNow(); | ||
3178 | + } | ||
3179 | + }, executorService); | ||
3150 | 3180 | ||
3151 | OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventUnifiedCouponsService.class).build(); | 3181 | OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventUnifiedCouponsService.class).build(); |
3152 | WorkManager.getInstance(Warply.getWarplyContext()).enqueue(mywork); | 3182 | WorkManager.getInstance(Warply.getWarplyContext()).enqueue(mywork); |
... | @@ -3201,6 +3231,142 @@ public class WarplyManager { | ... | @@ -3201,6 +3231,142 @@ public class WarplyManager { |
3201 | }); | 3231 | }); |
3202 | } | 3232 | } |
3203 | 3233 | ||
3234 | + private static ListenableFuture<CouponList> getSMCouponsUniversalRetro(ApiService service, int tries, SettableFuture<CouponList> future) { | ||
3235 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
3236 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
3237 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
3238 | + | ||
3239 | + Map<String, Object> jsonParamsCoupons = new ArrayMap<>(); | ||
3240 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
3241 | + jsonParams.put("action", "user_coupons"); | ||
3242 | + JSONArray jArr = new JSONArray(); | ||
3243 | + jArr.put("merchant"); | ||
3244 | + jsonParams.put("details", jArr); | ||
3245 | + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); | ||
3246 | + jsonParams.put("couponset_types", new JSONArray().put("supermarket")); | ||
3247 | + | ||
3248 | + jsonParamsCoupons.put("coupon", jsonParams); | ||
3249 | + RequestBody couponsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCoupons)).toString()); | ||
3250 | + | ||
3251 | + Call<ResponseBody> couponsCall = service.getUserCoupons( | ||
3252 | + WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
3253 | + couponsRequest, | ||
3254 | + timeStamp, | ||
3255 | + "android:" + Warply.getWarplyContext().getPackageName(), | ||
3256 | + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
3257 | + "mobile", | ||
3258 | + webId, | ||
3259 | + WarpUtils.produceSignature(apiKey + timeStamp), | ||
3260 | + "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
3261 | + ); | ||
3262 | + | ||
3263 | + couponsCall.enqueue(new Callback<ResponseBody>() { | ||
3264 | + @Override | ||
3265 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
3266 | + if (response.code() == 200 && response.body() != null) { | ||
3267 | + JSONObject jobjCouponsResponse = null; | ||
3268 | + try { | ||
3269 | + jobjCouponsResponse = new JSONObject(response.body().string()); | ||
3270 | + } catch (Exception e) { | ||
3271 | + e.printStackTrace(); | ||
3272 | + } | ||
3273 | + | ||
3274 | + if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optString("status", "2").equals("1")) { | ||
3275 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
3276 | + dynatraceEvent.setEventName("custom_success_user_sm_coupons_loyalty"); | ||
3277 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
3278 | + | ||
3279 | + JSONArray jCouponsBody = null; | ||
3280 | + try { | ||
3281 | + jCouponsBody = jobjCouponsResponse.optJSONArray("result"); | ||
3282 | + } catch (Exception e) { | ||
3283 | + e.printStackTrace(); | ||
3284 | + } | ||
3285 | + | ||
3286 | + if (jCouponsBody != null) { | ||
3287 | + CouponList mActiveCouponList = new CouponList(); | ||
3288 | + | ||
3289 | + final ExecutorService executorCoupons = Executors.newFixedThreadPool(1); | ||
3290 | + JSONArray finalJCouponsBody = jCouponsBody; | ||
3291 | + executorCoupons.submit(() -> { | ||
3292 | + for (int i = 0; i < finalJCouponsBody.length(); ++i) { | ||
3293 | + Coupon tempCoupon = new Coupon(finalJCouponsBody.optJSONObject(i), true); | ||
3294 | + if (tempCoupon.getStatus() == 1) { | ||
3295 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); | ||
3296 | + Date newDate = new Date(); | ||
3297 | + try { | ||
3298 | + newDate = simpleDateFormat.parse(tempCoupon.getExpiration()); | ||
3299 | + } catch ( | ||
3300 | + ParseException e) { | ||
3301 | + e.printStackTrace(); | ||
3302 | + } | ||
3303 | + tempCoupon.setExpirationDate(newDate); | ||
3304 | + mActiveCouponList.add(tempCoupon); | ||
3305 | + } | ||
3306 | + } | ||
3307 | + | ||
3308 | + Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate())); | ||
3309 | + executorCoupons.shutdownNow(); | ||
3310 | + future.set(mActiveCouponList); | ||
3311 | + }); | ||
3312 | + } | ||
3313 | + } else { | ||
3314 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
3315 | + dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty"); | ||
3316 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
3317 | + future.set(new CouponList()); | ||
3318 | + } | ||
3319 | + } else if (response.code() == 401) { | ||
3320 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
3321 | + @Override | ||
3322 | + public void onSuccess(JSONObject result) { | ||
3323 | + int status = result.optInt("status", 2); | ||
3324 | + if (status == 1) | ||
3325 | + getSMCouponsUniversalRetro(service, tries/*, receiver*/, future); | ||
3326 | + else { | ||
3327 | +// receiver.onFailure(status); | ||
3328 | + if (tries < MAX_RETRIES) { | ||
3329 | + getSMCouponsUniversalRetro(service, (tries + 1), future); | ||
3330 | + } else { | ||
3331 | +// future.set(new CouponList()); | ||
3332 | + future.setException(new Throwable()); | ||
3333 | + } | ||
3334 | + } | ||
3335 | + } | ||
3336 | + | ||
3337 | + @Override | ||
3338 | + public void onFailure(int errorCode) { | ||
3339 | +// receiver.onFailure(errorCode); | ||
3340 | + if (tries < MAX_RETRIES) { | ||
3341 | + getSMCouponsUniversalRetro(service, (tries + 1), future); | ||
3342 | + } else { | ||
3343 | +// future.set(new CouponList()); | ||
3344 | + future.setException(new Throwable()); | ||
3345 | + } | ||
3346 | + } | ||
3347 | + }); | ||
3348 | + } else { | ||
3349 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
3350 | + dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty"); | ||
3351 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
3352 | +// future.set(new CouponList()); | ||
3353 | + future.setException(new Throwable()); | ||
3354 | + } | ||
3355 | + } | ||
3356 | + | ||
3357 | + @Override | ||
3358 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
3359 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
3360 | + dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty"); | ||
3361 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
3362 | +// future.set(new CouponList()); | ||
3363 | + future.setException(new Throwable()); | ||
3364 | + } | ||
3365 | + }); | ||
3366 | + | ||
3367 | + return future; | ||
3368 | + } | ||
3369 | + | ||
3204 | public static void sendAccelerationDataToServer(JSONArray telematicsData, final CallbackReceiver<Integer> receiver) { | 3370 | public static void sendAccelerationDataToServer(JSONArray telematicsData, final CallbackReceiver<Integer> receiver) { |
3205 | WarpUtils.log("************* WARPLY User Telematics Request ********************"); | 3371 | WarpUtils.log("************* WARPLY User Telematics Request ********************"); |
3206 | WarpUtils.log("[WARP Trace] WARPLY User Telematics Request is active"); | 3372 | WarpUtils.log("[WARP Trace] WARPLY User Telematics Request is active"); | ... | ... |
-
Please register or login to post a comment