Panagiotis Triantafyllou

new coupons request for sm inside getUnifiedCouponsDeals and new static variable for this list

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="direct_access_persist.xml">
<option name="deviceSelectionList">
<list>
<PersistentDeviceSelectionData>
<option name="api" value="27" />
<option name="brand" value="DOCOMO" />
<option name="codename" value="F01L" />
<option name="id" value="F01L" />
<option name="manufacturer" value="FUJITSU" />
<option name="name" value="F-01L" />
<option name="screenDensity" value="360" />
<option name="screenX" value="720" />
<option name="screenY" value="1280" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="28" />
<option name="brand" value="DOCOMO" />
<option name="codename" value="SH-01L" />
<option name="id" value="SH-01L" />
<option name="manufacturer" value="SHARP" />
<option name="name" value="AQUOS sense2 SH-01L" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1080" />
<option name="screenY" value="2160" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="samsung" />
<option name="codename" value="a51" />
<option name="id" value="a51" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy A51" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="akita" />
<option name="id" value="akita" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="samsung" />
<option name="codename" value="b0q" />
<option name="id" value="b0q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S22 Ultra" />
<option name="screenDensity" value="600" />
<option name="screenX" value="1440" />
<option name="screenY" value="3088" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="32" />
<option name="brand" value="google" />
<option name="codename" value="bluejay" />
<option name="id" value="bluejay" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 6a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="29" />
<option name="brand" value="samsung" />
<option name="codename" value="crownqlteue" />
<option name="id" value="crownqlteue" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Note9" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2220" />
<option name="screenY" value="1080" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="dm3q" />
<option name="id" value="dm3q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S23 Ultra" />
<option name="screenDensity" value="600" />
<option name="screenX" value="1440" />
<option name="screenY" value="3088" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="felix" />
<option name="id" value="felix" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Fold" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2208" />
<option name="screenY" value="1840" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="felix_camera" />
<option name="id" value="felix_camera" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Fold (Camera-enabled)" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2208" />
<option name="screenY" value="1840" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="samsung" />
<option name="codename" value="gts8uwifi" />
<option name="id" value="gts8uwifi" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Tab S8 Ultra" />
<option name="screenDensity" value="320" />
<option name="screenX" value="1848" />
<option name="screenY" value="2960" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="husky" />
<option name="id" value="husky" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8 Pro" />
<option name="screenDensity" value="390" />
<option name="screenX" value="1008" />
<option name="screenY" value="2244" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="motorola" />
<option name="codename" value="java" />
<option name="id" value="java" />
<option name="manufacturer" value="Motorola" />
<option name="name" value="G20" />
<option name="screenDensity" value="280" />
<option name="screenX" value="720" />
<option name="screenY" value="1600" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="lynx" />
<option name="id" value="lynx" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 7a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="google" />
<option name="codename" value="oriole" />
<option name="id" value="oriole" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 6" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="panther" />
<option name="id" value="panther" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 7" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="samsung" />
<option name="codename" value="q2q" />
<option name="id" value="q2q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Z Fold3" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1768" />
<option name="screenY" value="2208" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="q5q" />
<option name="id" value="q5q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Z Fold5" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1812" />
<option name="screenY" value="2176" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="google" />
<option name="codename" value="r11" />
<option name="id" value="r11" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Watch" />
<option name="screenDensity" value="320" />
<option name="screenX" value="384" />
<option name="screenY" value="384" />
<option name="type" value="WEAR_OS" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="google" />
<option name="codename" value="redfin" />
<option name="id" value="redfin" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 5" />
<option name="screenDensity" value="440" />
<option name="screenX" value="1080" />
<option name="screenY" value="2340" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="shiba" />
<option name="id" value="shiba" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="tangorpro" />
<option name="id" value="tangorpro" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Tablet" />
<option name="screenDensity" value="320" />
<option name="screenX" value="1600" />
<option name="screenY" value="2560" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="29" />
<option name="brand" value="samsung" />
<option name="codename" value="x1q" />
<option name="id" value="x1q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S20" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1440" />
<option name="screenY" value="3200" />
</PersistentDeviceSelectionData>
</list>
</option>
</component>
</project>
\ No newline at end of file
......@@ -105,6 +105,7 @@ public class WarplyManagerHelper {
private static HashMap<String, CampaignList> mUniqueCampaignList = new HashMap<String, CampaignList>();
private static CouponList mCouponList = new CouponList();
private static CouponList mCouponRedeemedList = new CouponList();
private static CouponList mSmCouponsList = new CouponList();
private static CouponList mCouponListExpired = new CouponList();
private static CouponsetsList mCouponsetsList = new CouponsetsList();
private static CouponsetsList mCouponsetsDealsList = new CouponsetsList();
......@@ -1368,10 +1369,19 @@ public class WarplyManagerHelper {
mCouponRedeemedList.addAll(couponRedeemedList);
}
public static void setSmCouponsList(CouponList couponRedeemedList) {
mSmCouponsList.clear();
mSmCouponsList.addAll(couponRedeemedList);
}
public static CouponList getCouponRedeemedList() {
return mCouponRedeemedList;
}
public static CouponList getSmCouponsList() {
return mSmCouponsList;
}
public static LoyaltyBadgeModel getLoyaltyBadge() {
return mLoyaltyBadge;
}
......
......@@ -3123,30 +3123,60 @@ public class WarplyManager {
e.printStackTrace();
}
// if (allCouponList != null && allCouponList.size() > 0) {
// float countValue = 0.0f;
// if (WarplyManagerHelper.getCouponRedeemedList().size() > 0) {
// if (WarplyManagerHelper.getCouponsetsDeals().size() > 0) {
// for (Couponset couset : WarplyManagerHelper.getCouponsetsDeals()) {
// for (Coupon cou : WarplyManagerHelper.getCouponRedeemedList()) {
// if (cou.getCouponsetUuid().equals(couset.getUuid())) {
// countValue += Float.parseFloat(cou.getDiscount());
// cou.setDescription(couset.getShortDescription());
// cou.setImage(couset.getImgPreview());
// cou.setName(couset.getName());
// cou.setMerchantUuid(couset.getMerchantUuid());
// cou.setInnerText(couset.getInnerText());
// cou.setDiscount_type(couset.getDiscount_type());
// cou.setFinal_price(couset.getFinal_price());
// break;
// }
// }
// }
// }
// }
//
// WarplyManagerHelper.setUnifiedCouponsDiscount(countValue);
// }
CouponList mTempActiveSMCoupons = new CouponList();
for (UnifiedCoupon uni : couponList) {
if (!uni.getCoupons().isEmpty()) {
for (Coupon coupon : uni.getCoupons()) {
if (coupon.getStatus() == 1) {
Coupon tempCoupon = coupon;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date newDate = new Date();
try {
newDate = simpleDateFormat.parse(tempCoupon.getExpiration());
} catch (
ParseException e) {
e.printStackTrace();
}
tempCoupon.setExpirationDate(newDate);
mTempActiveSMCoupons.add(tempCoupon);
}
}
}
}
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
SettableFuture<CouponList> futureUniversal = SettableFuture.create();
ListenableFuture<CouponList> futureCoupons = getSMCouponsUniversalRetro(service, 0, futureUniversal);
ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCoupons);
ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync(
allResultsFuture,
results -> {
CouponList resultCoupons = (CouponList) results.get(0);
return executorService.submit(() -> resultCoupons);
},
executorService
);
Futures.addCallback(mergedResultFuture, new FutureCallback<CouponList>() {
@Override
public void onSuccess(CouponList mergedResult) {
CouponList mfinalActiveSMCoupons = new CouponList();
for (Coupon mergedItem : mergedResult) {
for (Coupon tempItem : mTempActiveSMCoupons) {
if (!mergedItem.getCoupon().equals(tempItem.getCoupon())) {
mfinalActiveSMCoupons.add(mergedItem);
}
}
}
WarplyManagerHelper.setSmCouponsList(mfinalActiveSMCoupons);
executorService.shutdownNow();
}
@Override
public void onFailure(Throwable throwable) {
executorService.shutdownNow();
}
}, executorService);
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventUnifiedCouponsService.class).build();
WorkManager.getInstance(Warply.getWarplyContext()).enqueue(mywork);
......@@ -3201,6 +3231,142 @@ public class WarplyManager {
});
}
private static ListenableFuture<CouponList> getSMCouponsUniversalRetro(ApiService service, int tries, SettableFuture<CouponList> future) {
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParamsCoupons = new ArrayMap<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "user_coupons");
JSONArray jArr = new JSONArray();
jArr.put("merchant");
jsonParams.put("details", jArr);
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParams.put("couponset_types", new JSONArray().put("supermarket"));
jsonParamsCoupons.put("coupon", jsonParams);
RequestBody couponsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCoupons)).toString());
Call<ResponseBody> couponsCall = service.getUserCoupons(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
couponsRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp),
"Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")
);
couponsCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject jobjCouponsResponse = null;
try {
jobjCouponsResponse = new JSONObject(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optString("status", "2").equals("1")) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_user_sm_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
JSONArray jCouponsBody = null;
try {
jCouponsBody = jobjCouponsResponse.optJSONArray("result");
} catch (Exception e) {
e.printStackTrace();
}
if (jCouponsBody != null) {
CouponList mActiveCouponList = new CouponList();
final ExecutorService executorCoupons = Executors.newFixedThreadPool(1);
JSONArray finalJCouponsBody = jCouponsBody;
executorCoupons.submit(() -> {
for (int i = 0; i < finalJCouponsBody.length(); ++i) {
Coupon tempCoupon = new Coupon(finalJCouponsBody.optJSONObject(i), true);
if (tempCoupon.getStatus() == 1) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date newDate = new Date();
try {
newDate = simpleDateFormat.parse(tempCoupon.getExpiration());
} catch (
ParseException e) {
e.printStackTrace();
}
tempCoupon.setExpirationDate(newDate);
mActiveCouponList.add(tempCoupon);
}
}
Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
executorCoupons.shutdownNow();
future.set(mActiveCouponList);
});
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new CouponList());
}
} else if (response.code() == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
getSMCouponsUniversalRetro(service, tries/*, receiver*/, future);
else {
// receiver.onFailure(status);
if (tries < MAX_RETRIES) {
getSMCouponsUniversalRetro(service, (tries + 1), future);
} else {
// future.set(new CouponList());
future.setException(new Throwable());
}
}
}
@Override
public void onFailure(int errorCode) {
// receiver.onFailure(errorCode);
if (tries < MAX_RETRIES) {
getSMCouponsUniversalRetro(service, (tries + 1), future);
} else {
// future.set(new CouponList());
future.setException(new Throwable());
}
}
});
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// future.set(new CouponList());
future.setException(new Throwable());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_user_sm_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// future.set(new CouponList());
future.setException(new Throwable());
}
});
return future;
}
public static void sendAccelerationDataToServer(JSONArray telematicsData, final CallbackReceiver<Integer> receiver) {
WarpUtils.log("************* WARPLY User Telematics Request ********************");
WarpUtils.log("[WARP Trace] WARPLY User Telematics Request is active");
......