Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_android_sdk_maven_plugin
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Panagiotis Triantafyllou
2024-03-05 18:15:12 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c1cbb93a505ad8118ce4b002681d6f37de4164a7
c1cbb93a
1 parent
b84ba327
new coupons request part1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
822 additions
and
301 deletions
warply_android_sdk/src/main/java/ly/warp/sdk/activities/BaseFragmentActivity.java
warply_android_sdk/src/main/java/ly/warp/sdk/io/models/Coupon.java
warply_android_sdk/src/main/java/ly/warp/sdk/io/models/Couponset.java
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
warply_android_sdk/src/main/java/ly/warp/sdk/activities/BaseFragmentActivity.java
View file @
c1cbb93
...
...
@@ -50,8 +50,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
mBottomNavigationView
=
findViewById
(
R
.
id
.
bt_tabs
);
WarplyManager
.
getUserCouponsWithCouponsets
(
mUserCouponsReceiver
);
WarplyManager
.
getCampaigns
(
mCampaignsCallback
);
WarplyManager
.
getUnifiedCouponsDeals
(
mUnifiedCallback
);
//
WarplyManager.getCampaigns(mCampaignsCallback);
//
WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback);
}
@Override
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/io/models/Coupon.java
View file @
c1cbb93
...
...
@@ -95,6 +95,7 @@ public class Coupon implements Parcelable, Serializable {
private
double
final_price
=
0.0d
;
private
String
short_description
=
""
;
private
String
terms
=
""
;
private
Couponset
couponsetDetails
=
new
Couponset
(
true
);
public
Coupon
()
{
this
.
barcode
=
""
;
...
...
@@ -121,6 +122,19 @@ public class Coupon implements Parcelable, Serializable {
this
.
terms
=
""
;
}
public
Coupon
(
boolean
isUniversal
)
{
this
.
barcode
=
""
;
this
.
coupon
=
""
;
this
.
discount
=
""
;
this
.
expiration
=
""
;
this
.
status
=
0
;
this
.
changesDates
=
new
JSONObject
();
this
.
couponsetUuid
=
""
;
this
.
merchantUuid
=
""
;
this
.
redeemDate
=
new
Date
();
this
.
couponsetDetails
=
new
Couponset
(
isUniversal
);
}
/**
* Basic constructor used to create an object from a String, representing a
* JSON Object
...
...
@@ -176,6 +190,50 @@ public class Coupon implements Parcelable, Serializable {
}
}
public
Coupon
(
JSONObject
json
,
boolean
isUniversal
)
{
if
(
json
!=
null
)
{
this
.
barcode
=
json
.
optString
(
BARCODE
);
this
.
changesDates
=
json
.
optJSONObject
(
CHANGES_DATES
);
if
(
this
.
changesDates
!=
null
)
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm"
);
Date
newDate
=
new
Date
();
String
tempRedeemDate
=
this
.
changesDates
.
optString
(
"redeemed"
);
try
{
newDate
=
simpleDateFormat
.
parse
(
tempRedeemDate
);
this
.
redeemDate
=
newDate
;
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
this
.
coupon
=
json
.
optString
(
COUPON
);
this
.
couponsetUuid
=
json
.
optString
(
COUPONSET_UUID
);
this
.
discount
=
json
.
optString
(
DISCOUNT
);
if
(
this
.
discount
.
contains
(
","
))
{
this
.
discount
=
this
.
discount
.
replace
(
","
,
"."
);
}
this
.
expiration
=
json
.
optString
(
EXPIRATION
);
this
.
merchantUuid
=
json
.
optString
(
MERCHANT_UUID
);
this
.
status
=
json
.
optInt
(
STATUS
);
JSONObject
tempCouponsetDetails
=
json
.
optJSONObject
(
"couponset_details"
);
if
(
tempCouponsetDetails
!=
null
)
{
this
.
couponsetDetails
=
new
Couponset
(
tempCouponsetDetails
,
isUniversal
);
}
// this.category = json.optString(CATEGORY);
// this.created = json.optString(CREATED);
// this.description = json.optString(DESCRIPTION);
// this.image = json.optString(IMAGE);
// this.name = json.optString(NAME);
// this.transactionDate = json.optString(TRANSACTION_DATE);
// this.transactionUuid = json.optString(TRANSACTION_UUID);
// this.innerText = json.optString(INNER_TEXT);
// this.discount_type = json.isNull(DISCOUNT_TYPE) ? "" : json.optString(DISCOUNT_TYPE);
// this.final_price = json.optDouble(FINAL_PRICE);
// this.short_description = json.optString(SHORT_DESCRIPTION);
// this.terms = json.optString(TERMS);
}
}
public
Coupon
(
Parcel
source
)
{
this
.
barcode
=
source
.
readString
();
this
.
category
=
source
.
readString
();
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/io/models/Couponset.java
View file @
c1cbb93
...
...
@@ -33,6 +33,9 @@ import org.json.JSONException;
import
org.json.JSONObject
;
import
java.io.Serializable
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
ly.warp.sdk.utils.WarpUtils
;
import
ly.warp.sdk.utils.constants.WarpConstants
;
...
...
@@ -108,6 +111,7 @@ public class Couponset implements Parcelable, Serializable {
private
String
innerText
=
""
;
private
String
discount_type
=
""
;
private
double
final_price
=
0.0d
;
private
Date
endDate
=
new
Date
();
public
Couponset
()
{
this
.
uuid
=
""
;
...
...
@@ -140,6 +144,23 @@ public class Couponset implements Parcelable, Serializable {
this
.
final_price
=
0.0d
;
}
public
Couponset
(
boolean
isUniversal
)
{
this
.
admin_name
=
""
;
this
.
active
=
false
;
this
.
buyable
=
false
;
this
.
category
=
""
;
this
.
created
=
""
;
this
.
discount
=
""
;
this
.
discount_type
=
""
;
this
.
name
=
""
;
this
.
img
=
new
JSONArray
();
this
.
short_description
=
""
;
this
.
terms
=
""
;
this
.
updated
=
""
;
this
.
uuid
=
""
;
// this.endDate = new Date();
}
/**
* Basic constructor used to create an object from a String, representing a
* JSON Object
...
...
@@ -196,6 +217,56 @@ public class Couponset implements Parcelable, Serializable {
}
}
public
Couponset
(
JSONObject
json
,
boolean
isUniversal
)
{
if
(
json
!=
null
)
{
this
.
uuid
=
json
.
optString
(
UUID
);
this
.
admin_name
=
json
.
optString
(
ADMIN_NAME
);
this
.
created
=
json
.
optString
(
CREATED
);
this
.
updated
=
json
.
optString
(
UPDATED
);
this
.
img
=
json
.
optJSONArray
(
IMG
);
this
.
active
=
json
.
optBoolean
(
ACTIVE
);
this
.
buyable
=
json
.
optBoolean
(
BUYABLE
);
this
.
name
=
json
.
optString
(
NAME
);
this
.
short_description
=
json
.
optString
(
SHORT_DESCRIPTION
);
this
.
discount
=
json
.
optString
(
DISCOUNT
);
this
.
category
=
json
.
optString
(
CATEGORY
);
this
.
terms
=
json
.
optString
(
TERMS
);
this
.
discount_type
=
json
.
isNull
(
DISCOUNT_TYPE
)
?
""
:
json
.
optString
(
DISCOUNT_TYPE
);
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
// Date newDate = new Date();
// String tempRedeemDate = json.optString("end_date");
// try {
// newDate = simpleDateFormat.parse(tempRedeemDate);
// this.endDate = newDate;
// } catch (ParseException e) {
// e.printStackTrace();
// }
// this.app_uuid = json.optString(APP_UUID);
// this.img_preview = json.optString(IMG_PREVIEW);
// this.sorting = json.optInt(SORTING);
// this.visible = json.optBoolean(VISIBLE);
// this.user_generated = json.optBoolean(USER_GENERATED);
// this.limits = json.optJSONObject(LIMITS);
// this.points = json.optInt(POINTS);
// this.points_cause = json.optString(POINTS_CAUSE);
// JSONObject exp = null;
// try {
// exp = new JSONObject(json.optString(EXPIRATION));
// this.expiration = exp.optString(VALUE);
// } catch (JSONException e) {
// e.printStackTrace();
// this.expiration = "";
// }
// this.third_party_service = json.optBoolean(THIRD_PARTY_SERVICE);
// this.description = json.optString(DESCRIPTION);
// this.availability = json.optInt(AVAILABILITY);
// this.merchantUuid = json.optString(MERCHANT_UUID);
// this.innerText = json.optString(INNER_TEXT);
// this.final_price = json.isNull(FINAL_PRICE) ? 0.0d : json.optDouble(FINAL_PRICE);
}
}
public
Couponset
(
Parcel
source
)
{
this
.
uuid
=
source
.
readString
();
this
.
admin_name
=
source
.
readString
();
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
View file @
c1cbb93
...
...
@@ -1501,76 +1501,6 @@ public class WarplyManager {
});
}
public
static
void
getCampaigns
(
WarplyGetCampaignsRequest
request
,
final
CallbackReceiver
<
ArrayList
<
Campaign
>>
receiver
)
{
WarpUtils
.
log
(
"************* WARPLY Get Campaigns Request ********************"
);
WarpUtils
.
log
(
"[WARP Trace] WARPLY Get Campaigns Request is active"
);
WarpUtils
.
log
(
"**************************************************"
);
Warply
.
postReceiveMicroappData
(
WarpConstants
.
MICROAPP_NEW_CAMPAIGNS
,
false
,
"campaigns"
,
request
.
toJson
(),
new
NewCampaignsHook
(
new
CallbackReceiver
<
ArrayList
<
Campaign
>>()
{
@Override
public
void
onSuccess
(
ArrayList
<
Campaign
>
result
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_success_campaigns_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
getCampaignsPersonalized
(
request
,
new
CallbackReceiver
<
ArrayList
<
Campaign
>>()
{
@Override
public
void
onSuccess
(
ArrayList
<
Campaign
>
resultPersonalized
)
{
ArrayList
<
Campaign
>
newCampaignList
=
new
ArrayList
<
Campaign
>();
newCampaignList
.
clear
();
newCampaignList
.
addAll
(
result
);
newCampaignList
.
addAll
(
resultPersonalized
);
Collections
.
sort
(
newCampaignList
,
(
obj1
,
obj2
)
->
Integer
.
compare
(
obj1
.
getSorting
(),
obj2
.
getSorting
()));
WarplyManagerHelper
.
setCampaignList
(
newCampaignList
);
ArrayList
<
Campaign
>
campaignLoyaltyList
=
new
ArrayList
<>();
campaignLoyaltyList
.
clear
();
ArrayList
<
Campaign
>
campaignCarouselList
=
new
ArrayList
<>();
campaignCarouselList
.
clear
();
for
(
Campaign
camp
:
newCampaignList
)
{
JSONObject
campMetadata
=
WarpJSONParser
.
getJSONFromString
(
camp
.
getExtraFields
());
if
(
campMetadata
!=
null
)
{
if
(
campMetadata
.
has
(
"carousel"
))
{
campaignCarouselList
.
add
(
camp
);
}
}
try
{
JSONObject
extraFields
=
WarpJSONParser
.
getJSONFromString
(
camp
.
getExtraFields
());
if
(
extraFields
!=
null
)
{
if
(
extraFields
.
length
()
==
0
||
!(
extraFields
.
has
(
"ccms_offer"
)
||
extraFields
.
has
(
"type"
)))
{
campaignLoyaltyList
.
add
(
camp
);
}
}
}
catch
(
Exception
exception
)
{
campaignLoyaltyList
.
add
(
camp
);
}
}
WarplyManagerHelper
.
setCarouselList
(
campaignCarouselList
);
Set
<
Campaign
>
set
=
new
LinkedHashSet
<>(
campaignLoyaltyList
);
campaignLoyaltyList
.
clear
();
campaignLoyaltyList
.
addAll
(
set
);
receiver
.
onSuccess
(
campaignLoyaltyList
);
//resultPersonalized
}
@Override
public
void
onFailure
(
int
errorCode
)
{
receiver
.
onFailure
(
errorCode
);
}
});
}
@Override
public
void
onFailure
(
int
errorCode
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_campaigns_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
errorCode
);
}
},
request
.
getSignature
()));
}
private
static
ArrayList
<
Campaign
>
mergeCampaignResults
(
ArrayList
<
Campaign
>
resultCampaigns
,
ArrayList
<
Campaign
>
resultPersonalizedCampaigns
,
JSONObject
resultCampaignsAvailability
)
{
ArrayList
<
Campaign
>
newCampaignList
=
new
ArrayList
<
Campaign
>();
ArrayList
<
Campaign
>
campaignLoyaltyList
=
new
ArrayList
<>();
...
...
@@ -1627,6 +1557,237 @@ public class WarplyManager {
return
campaignLoyaltyList
;
}
public
static
void
getUserCouponsWithCouponsets
(
final
CallbackReceiver
<
CouponList
>
receiver
)
{
WarpUtils
.
log
(
"************* WARPLY User Coupons Request ********************"
);
WarpUtils
.
log
(
"[WARP Trace] WARPLY User Coupons Request is active"
);
WarpUtils
.
log
(
"**************************************************"
);
ApiService
service
=
ApiClient
.
getRetrofitInstance
().
create
(
ApiService
.
class
);
ListeningExecutorService
executorService
=
MoreExecutors
.
listeningDecorator
(
Executors
.
newFixedThreadPool
(
3
));
//TODO: check to see if we need merchants global else delete request
ListenableFuture
<
MerchantList
>
futureMerchants
=
getMerchantsRetro
(
service
);
ListenableFuture
<
CouponsetsList
>
futureCouponsets
=
getCouponsetsRetro
(
service
);
ListenableFuture
<
CouponList
>
futureCoupons
=
getCouponsUniversalRetro
(
service
);
// getMerchantsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) {
// if (responseMerchants.code() == 200 && responseMerchants.body() != null) {
// JSONObject jobjMerchantsResponse = null;
// try {
// jobjMerchantsResponse = new JSONObject(responseMerchants.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONArray jMerchantsBody = null;
// try {
// jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result");
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jMerchantsBody != null) {
// MerchantList mMerchantList = new MerchantList();
//
// final ExecutorService executorShops = Executors.newFixedThreadPool(1);
// JSONArray finalMerchantsJBody = jMerchantsBody;
// executorShops.submit(() -> {
// for (int i = 0; i < finalMerchantsJBody.length(); ++i) {
// mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i)));
// }
// WarplyManagerHelper.setMerchantList(mMerchantList);
// executorShops.shutdownNow();
// });
//
// getCouponsetsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) {
// if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) {
// JSONObject jobjCouponsetsResponse = null;
// try {
// jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse;
// getUserCouponsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) {
// if (responseCoupons.code() == 200 && responseCoupons.body() != null) {
// JSONObject jobjCouponsResponse = null;
// try {
// jobjCouponsResponse = new JSONObject(responseCoupons.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONObject finalJobjCouponsResponse = jobjCouponsResponse;
// final ExecutorService executor = Executors.newFixedThreadPool(1);
// executor.submit(() -> {
// // COUPONS START //
// JSONArray jCouponsBody = null;
// try {
// jCouponsBody = finalJobjCouponsResponse.optJSONArray("result");
// } catch (Exception e) {
// e.printStackTrace();
// }
// // COUPONS END //
//
// // COUPONSETS START //
// JSONArray jCouponsetsBody = null;
// try {
// jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON");
// } catch (Exception e) {
// e.printStackTrace();
// }
// // COUPONSETS END //
//
// if (jCouponsetsBody != null && jCouponsBody != null) {
// CouponList mCouponList = new CouponList();
// CouponList mCouponRedeemedList = new CouponList();
// CouponsetsList mCouponsetList = new CouponsetsList();
// for (int i = 0; i < jCouponsetsBody.length(); ++i) {
// Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i));
// mCouponsetList.add(tempCouponset);
// for (int j = 0; j < jCouponsBody.length(); ++j) {
// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
// if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) {
// tempCoupon.setDescription(tempCouponset.getShortDescription());
// tempCoupon.setImage(tempCouponset.getImgPreview());
// tempCoupon.setName(tempCouponset.getName());
// tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid());
// tempCoupon.setInnerText(tempCouponset.getInnerText());
// tempCoupon.setDiscount_type(tempCouponset.getDiscount_type());
// tempCoupon.setFinal_price(tempCouponset.getFinal_price());
// mCouponList.add(tempCoupon);
// }
// }
// }
//
// for (int j = 0; j < jCouponsBody.length(); ++j) {
// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
// if (tempCoupon.getStatus() == 0) {
// mCouponRedeemedList.add(tempCoupon);
// }
// }
// WarplyManagerHelper.setCouponsets(mCouponsetList);
// WarplyManagerHelper.setCouponList(mCouponList);
// WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList);
//
// CouponList mActiveCouponList = new CouponList();
// for (Coupon coupon : mCouponList) {
// if (coupon.getStatus() == 1) {
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
// Date newDate = new Date();
// try {
// newDate = simpleDateFormat.parse(coupon.getExpiration());
// } catch (
// ParseException e) {
// e.printStackTrace();
// }
// coupon.setExpirationDate(newDate);
// mActiveCouponList.add(coupon);
// }
// }
//
// Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
//
// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList));
// executor.shutdownNow();
// }
// });
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(responseCoupons.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// });
//
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
//
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(responseCouponsets.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// });
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(2);
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(responseMerchants.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(2);
// }
// });
}
public
static
void
getCampaigns
(
final
CallbackReceiver
<
ArrayList
<
Campaign
>>
receiver
)
{
WarpUtils
.
log
(
"************* WARPLY Get Campaigns Request ********************"
);
WarpUtils
.
log
(
"[WARP Trace] WARPLY Get Campaigns Request is active"
);
...
...
@@ -3322,232 +3483,234 @@ public class WarplyManager {
});
}
public
static
void
getUserCouponsWithCouponsets
(
final
CallbackReceiver
<
CouponList
>
receiver
)
{
WarpUtils
.
log
(
"************* WARPLY User Coupons Request ********************"
);
WarpUtils
.
log
(
"[WARP Trace] WARPLY User Coupons Request is active"
);
WarpUtils
.
log
(
"**************************************************"
);
ApiService
service
=
ApiClient
.
getRetrofitInstance
().
create
(
ApiService
.
class
);
getMerchantsRetro
(
service
,
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Response
<
ResponseBody
>
responseMerchants
)
{
if
(
responseMerchants
.
code
()
==
200
&&
responseMerchants
.
body
()
!=
null
)
{
JSONObject
jobjMerchantsResponse
=
null
;
try
{
jobjMerchantsResponse
=
new
JSONObject
(
responseMerchants
.
body
().
string
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jobjMerchantsResponse
!=
null
&&
jobjMerchantsResponse
.
has
(
"status"
)
&&
jobjMerchantsResponse
.
optString
(
"status"
,
"2"
).
equals
(
"1"
))
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_success_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
JSONArray
jMerchantsBody
=
null
;
try
{
jMerchantsBody
=
jobjMerchantsResponse
.
optJSONObject
(
"context"
).
optJSONObject
(
"MAPP_SHOPS"
).
optJSONArray
(
"result"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jMerchantsBody
!=
null
)
{
MerchantList
mMerchantList
=
new
MerchantList
();
final
ExecutorService
executorShops
=
Executors
.
newFixedThreadPool
(
1
);
JSONArray
finalMerchantsJBody
=
jMerchantsBody
;
executorShops
.
submit
(()
->
{
for
(
int
i
=
0
;
i
<
finalMerchantsJBody
.
length
();
++
i
)
{
mMerchantList
.
add
(
new
Merchant
(
finalMerchantsJBody
.
optJSONObject
(
i
)));
}
WarplyManagerHelper
.
setMerchantList
(
mMerchantList
);
executorShops
.
shutdownNow
();
});
getCouponsetsRetro
(
service
,
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Response
<
ResponseBody
>
responseCouponsets
)
{
if
(
responseCouponsets
.
code
()
==
200
&&
responseCouponsets
.
body
()
!=
null
)
{
JSONObject
jobjCouponsetsResponse
=
null
;
try
{
jobjCouponsetsResponse
=
new
JSONObject
(
responseCouponsets
.
body
().
string
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jobjCouponsetsResponse
!=
null
&&
jobjCouponsetsResponse
.
has
(
"status"
)
&&
jobjCouponsetsResponse
.
optString
(
"status"
,
"2"
).
equals
(
"1"
))
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_success_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
JSONObject
finalJobjCouponsetsResponse
=
jobjCouponsetsResponse
;
getUserCouponsRetro
(
service
,
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Response
<
ResponseBody
>
responseCoupons
)
{
if
(
responseCoupons
.
code
()
==
200
&&
responseCoupons
.
body
()
!=
null
)
{
JSONObject
jobjCouponsResponse
=
null
;
try
{
jobjCouponsResponse
=
new
JSONObject
(
responseCoupons
.
body
().
string
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jobjCouponsResponse
!=
null
&&
jobjCouponsResponse
.
has
(
"status"
)
&&
jobjCouponsResponse
.
optInt
(
"status"
,
2
)
==
1
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_success_user_coupons_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
JSONObject
finalJobjCouponsResponse
=
jobjCouponsResponse
;
final
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
1
);
executor
.
submit
(()
->
{
// COUPONS START //
JSONArray
jCouponsBody
=
null
;
try
{
jCouponsBody
=
finalJobjCouponsResponse
.
optJSONArray
(
"result"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// COUPONS END //
// COUPONSETS START //
JSONArray
jCouponsetsBody
=
null
;
try
{
jCouponsetsBody
=
finalJobjCouponsetsResponse
.
optJSONObject
(
"context"
).
optJSONArray
(
"MAPP_COUPON"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// COUPONSETS END //
if
(
jCouponsetsBody
!=
null
&&
jCouponsBody
!=
null
)
{
CouponList
mCouponList
=
new
CouponList
();
CouponList
mCouponRedeemedList
=
new
CouponList
();
CouponsetsList
mCouponsetList
=
new
CouponsetsList
();
for
(
int
i
=
0
;
i
<
jCouponsetsBody
.
length
();
++
i
)
{
Couponset
tempCouponset
=
new
Couponset
(
jCouponsetsBody
.
optJSONObject
(
i
));
mCouponsetList
.
add
(
tempCouponset
);
for
(
int
j
=
0
;
j
<
jCouponsBody
.
length
();
++
j
)
{
Coupon
tempCoupon
=
new
Coupon
(
jCouponsBody
.
optJSONObject
(
j
));
if
(
tempCoupon
.
getCouponsetUuid
().
equals
(
tempCouponset
.
getUuid
()))
{
tempCoupon
.
setDescription
(
tempCouponset
.
getShortDescription
());
tempCoupon
.
setImage
(
tempCouponset
.
getImgPreview
());
tempCoupon
.
setName
(
tempCouponset
.
getName
());
tempCoupon
.
setMerchantUuid
(
tempCouponset
.
getMerchantUuid
());
tempCoupon
.
setInnerText
(
tempCouponset
.
getInnerText
());
tempCoupon
.
setDiscount_type
(
tempCouponset
.
getDiscount_type
());
tempCoupon
.
setFinal_price
(
tempCouponset
.
getFinal_price
());
mCouponList
.
add
(
tempCoupon
);
}
}
}
for
(
int
j
=
0
;
j
<
jCouponsBody
.
length
();
++
j
)
{
Coupon
tempCoupon
=
new
Coupon
(
jCouponsBody
.
optJSONObject
(
j
));
if
(
tempCoupon
.
getStatus
()
==
0
)
{
mCouponRedeemedList
.
add
(
tempCoupon
);
}
}
WarplyManagerHelper
.
setCouponsets
(
mCouponsetList
);
WarplyManagerHelper
.
setCouponList
(
mCouponList
);
WarplyManagerHelper
.
setCouponRedeemedList
(
mCouponRedeemedList
);
CouponList
mActiveCouponList
=
new
CouponList
();
for
(
Coupon
coupon
:
mCouponList
)
{
if
(
coupon
.
getStatus
()
==
1
)
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm"
);
Date
newDate
=
new
Date
();
try
{
newDate
=
simpleDateFormat
.
parse
(
coupon
.
getExpiration
());
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
coupon
.
setExpirationDate
(
newDate
);
mActiveCouponList
.
add
(
coupon
);
}
}
Collections
.
sort
(
mActiveCouponList
,
(
coupon1
,
coupon2
)
->
coupon1
.
getExpirationDate
().
compareTo
(
coupon2
.
getExpirationDate
()));
new
Handler
(
Looper
.
getMainLooper
()).
post
(()
->
receiver
.
onSuccess
(
mActiveCouponList
));
executor
.
shutdownNow
();
}
});
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_user_coupons_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
2
);
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_user_coupons_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
responseCoupons
.
code
());
}
}
@Override
public
void
onFailure
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Throwable
t
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_user_coupons_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
2
);
}
});
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
2
);
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
responseCouponsets
.
code
());
}
}
@Override
public
void
onFailure
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Throwable
t
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
2
);
}
});
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
2
);
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
receiver
.
onFailure
(
responseMerchants
.
code
());
}
}
@Override
public
void
onFailure
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Throwable
t
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
// public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) {
// WarpUtils.log("************* WARPLY User Coupons Request ********************");
// WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
// WarpUtils.log("**************************************************");
//
// ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
//
// getMerchantsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) {
// if (responseMerchants.code() == 200 && responseMerchants.body() != null) {
// JSONObject jobjMerchantsResponse = null;
// try {
// jobjMerchantsResponse = new JSONObject(responseMerchants.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONArray jMerchantsBody = null;
// try {
// jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result");
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jMerchantsBody != null) {
// MerchantList mMerchantList = new MerchantList();
//
// final ExecutorService executorShops = Executors.newFixedThreadPool(1);
// JSONArray finalMerchantsJBody = jMerchantsBody;
// executorShops.submit(() -> {
// for (int i = 0; i < finalMerchantsJBody.length(); ++i) {
// mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i)));
// }
// WarplyManagerHelper.setMerchantList(mMerchantList);
// executorShops.shutdownNow();
// });
//
// getCouponsetsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCouponsets) {
// if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) {
// JSONObject jobjCouponsetsResponse = null;
// try {
// jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse;
// getUserCouponsRetro(service, new Callback<ResponseBody>() {
// @Override
// public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) {
// if (responseCoupons.code() == 200 && responseCoupons.body() != null) {
// JSONObject jobjCouponsResponse = null;
// try {
// jobjCouponsResponse = new JSONObject(responseCoupons.body().string());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// JSONObject finalJobjCouponsResponse = jobjCouponsResponse;
// final ExecutorService executor = Executors.newFixedThreadPool(1);
// executor.submit(() -> {
// // COUPONS START //
// JSONArray jCouponsBody = null;
// try {
// jCouponsBody = finalJobjCouponsResponse.optJSONArray("result");
// } catch (Exception e) {
// e.printStackTrace();
// }
// // COUPONS END //
//
// // COUPONSETS START //
// JSONArray jCouponsetsBody = null;
// try {
// jCouponsetsBody = finalJobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON");
// } catch (Exception e) {
// e.printStackTrace();
// }
// // COUPONSETS END //
//
// if (jCouponsetsBody != null && jCouponsBody != null) {
// CouponList mCouponList = new CouponList();
// CouponList mCouponRedeemedList = new CouponList();
// CouponsetsList mCouponsetList = new CouponsetsList();
// for (int i = 0; i < jCouponsetsBody.length(); ++i) {
// Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i));
// mCouponsetList.add(tempCouponset);
// for (int j = 0; j < jCouponsBody.length(); ++j) {
// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
// if (tempCoupon.getCouponsetUuid().equals(tempCouponset.getUuid())) {
// tempCoupon.setDescription(tempCouponset.getShortDescription());
// tempCoupon.setImage(tempCouponset.getImgPreview());
// tempCoupon.setName(tempCouponset.getName());
// tempCoupon.setMerchantUuid(tempCouponset.getMerchantUuid());
// tempCoupon.setInnerText(tempCouponset.getInnerText());
// tempCoupon.setDiscount_type(tempCouponset.getDiscount_type());
// tempCoupon.setFinal_price(tempCouponset.getFinal_price());
// mCouponList.add(tempCoupon);
// }
// }
// }
//
// for (int j = 0; j < jCouponsBody.length(); ++j) {
// Coupon tempCoupon = new Coupon(jCouponsBody.optJSONObject(j));
// if (tempCoupon.getStatus() == 0) {
// mCouponRedeemedList.add(tempCoupon);
// }
// }
// WarplyManagerHelper.setCouponsets(mCouponsetList);
// WarplyManagerHelper.setCouponList(mCouponList);
// WarplyManagerHelper.setCouponRedeemedList(mCouponRedeemedList);
//
// CouponList mActiveCouponList = new CouponList();
// for (Coupon coupon : mCouponList) {
// if (coupon.getStatus() == 1) {
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
// Date newDate = new Date();
// try {
// newDate = simpleDateFormat.parse(coupon.getExpiration());
// } catch (
// ParseException e) {
// e.printStackTrace();
// }
// coupon.setExpirationDate(newDate);
// mActiveCouponList.add(coupon);
// }
// }
//
// Collections.sort(mActiveCouponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
//
// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mActiveCouponList));
// executor.shutdownNow();
// }
// });
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(responseCoupons.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// });
//
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
//
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(responseCouponsets.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
// }
// });
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(2);
// }
// } else {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(responseMerchants.code());
// }
// }
//
// @Override
// public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_error_shops_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// receiver.onFailure(2);
// }
// });
// }
receiver
.
onFailure
(
2
);
}
});
}
private
static
/*void*/
ListenableFuture
<
CouponsetsList
>
getCouponsetsRetro
(
ApiService
service
/*, Callback<ResponseBody> callback*/
)
{
SettableFuture
<
CouponsetsList
>
future
=
SettableFuture
.
create
();
private
static
void
getCouponsetsRetro
(
ApiService
service
,
Callback
<
ResponseBody
>
callback
)
{
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
());
...
...
@@ -3584,14 +3747,68 @@ public class WarplyManager {
couponsetsCall
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Response
<
ResponseBody
>
response
)
{
callback
.
onResponse
(
call
,
response
);
if
(
response
.
code
()
==
200
&&
response
.
body
()
!=
null
)
{
JSONObject
jobjCouponsetsResponse
=
null
;
try
{
jobjCouponsetsResponse
=
new
JSONObject
(
response
.
body
().
string
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jobjCouponsetsResponse
!=
null
&&
jobjCouponsetsResponse
.
has
(
"status"
)
&&
jobjCouponsetsResponse
.
optString
(
"status"
,
"2"
).
equals
(
"1"
))
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_success_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
JSONArray
jCouponsetsBody
=
null
;
try
{
jCouponsetsBody
=
jobjCouponsetsResponse
.
optJSONObject
(
"context"
).
optJSONArray
(
"MAPP_COUPON"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jCouponsetsBody
!=
null
)
{
CouponsetsList
mCouponsetList
=
new
CouponsetsList
();
final
ExecutorService
executorCouponsets
=
Executors
.
newFixedThreadPool
(
1
);
JSONArray
finalJCouponsetsBody
=
jCouponsetsBody
;
executorCouponsets
.
submit
(()
->
{
for
(
int
i
=
0
;
i
<
finalJCouponsetsBody
.
length
();
++
i
)
{
Couponset
tempCouponset
=
new
Couponset
(
finalJCouponsetsBody
.
optJSONObject
(
i
));
mCouponsetList
.
add
(
tempCouponset
);
}
WarplyManagerHelper
.
setCouponsets
(
mCouponsetList
);
executorCouponsets
.
shutdownNow
();
future
.
set
(
mCouponsetList
);
});
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
CouponsetsList
());
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
CouponsetsList
());
}
}
@Override
public
void
onFailure
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Throwable
t
)
{
callback
.
onFailure
(
call
,
t
);
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_couponsets_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
CouponsetsList
());
}
});
return
future
;
}
private
static
void
getCouponsetsRetro
(
ApiService
service
,
boolean
isFiltered
,
Callback
<
ResponseBody
>
callback
)
{
...
...
@@ -4017,7 +4234,9 @@ public class WarplyManager {
});
}
private
static
void
getMerchantsRetro
(
ApiService
service
,
Callback
<
ResponseBody
>
callback
)
{
private
static
/*void*/
ListenableFuture
<
MerchantList
>
getMerchantsRetro
(
ApiService
service
/*, Callback<ResponseBody> callback*/
)
{
SettableFuture
<
MerchantList
>
future
=
SettableFuture
.
create
();
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
());
...
...
@@ -4050,14 +4269,65 @@ public class WarplyManager {
merchantsCall
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Response
<
ResponseBody
>
response
)
{
callback
.
onResponse
(
call
,
response
);
if
(
response
.
code
()
==
200
&&
response
.
body
()
!=
null
)
{
JSONObject
jobjMerchantsResponse
=
null
;
try
{
jobjMerchantsResponse
=
new
JSONObject
(
response
.
body
().
string
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jobjMerchantsResponse
!=
null
&&
jobjMerchantsResponse
.
has
(
"status"
)
&&
jobjMerchantsResponse
.
optString
(
"status"
,
"2"
).
equals
(
"1"
))
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_success_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
JSONArray
jMerchantsBody
=
null
;
try
{
jMerchantsBody
=
jobjMerchantsResponse
.
optJSONObject
(
"context"
).
optJSONObject
(
"MAPP_SHOPS"
).
optJSONArray
(
"result"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jMerchantsBody
!=
null
)
{
MerchantList
mMerchantList
=
new
MerchantList
();
final
ExecutorService
executorShops
=
Executors
.
newFixedThreadPool
(
1
);
JSONArray
finalMerchantsJBody
=
jMerchantsBody
;
executorShops
.
submit
(()
->
{
for
(
int
i
=
0
;
i
<
finalMerchantsJBody
.
length
();
++
i
)
{
mMerchantList
.
add
(
new
Merchant
(
finalMerchantsJBody
.
optJSONObject
(
i
)));
}
WarplyManagerHelper
.
setMerchantList
(
mMerchantList
);
executorShops
.
shutdownNow
();
future
.
set
(
mMerchantList
);
});
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
MerchantList
());
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
MerchantList
());
}
}
@Override
public
void
onFailure
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Throwable
t
)
{
callback
.
onFailure
(
call
,
t
);
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_shops_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
MerchantList
());
}
});
return
future
;
}
private
static
void
getMerchantsRetro
(
ApiService
service
,
ArrayList
<
String
>
catuuids
,
Callback
<
ResponseBody
>
callback
)
{
...
...
@@ -4205,6 +4475,128 @@ public class WarplyManager {
});
}
private
static
ListenableFuture
<
CouponList
>
getCouponsUniversalRetro
(
ApiService
service
)
{
SettableFuture
<
CouponList
>
future
=
SettableFuture
.
create
();
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
()));
// JSONObject jPagination= new JSONObject();
// try {
// jPagination.putOpt("page",1);
// jPagination.putOpt("per_page", 10);
// } catch (JSONException e) {
// throw new RuntimeException(e);
// }
// jsonParams.put("pagination", jPagination);
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_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
mCouponsList
=
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
);
mCouponsList
.
add
(
tempCoupon
);
}
// WarplyManagerHelper.setCouponsets(mCouponsetList);
executorCoupons
.
shutdownNow
();
future
.
set
(
mCouponsList
);
});
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_user_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)
// getCouponsUniversalRetro(service, callback);
// else
// callback.onFailure(call, new Throwable());
// }
//
// @Override
// public void onFailure(int errorCode) {
// callback.onFailure(call, new Throwable());
// }
// });
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_user_coupons_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
CouponList
());
}
future
.
set
(
new
CouponList
());
}
@Override
public
void
onFailure
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Throwable
t
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_user_coupons_loyalty"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
CouponList
());
}
});
return
future
;
}
public
static
void
getCosmoteUser
(
WarplyCosmoteUserRequest
request
,
final
CallbackReceiver
<
JSONObject
>
receiver
)
{
WarpUtils
.
log
(
"************* WARPLY Cosmote User Request ********************"
);
WarpUtils
.
log
(
"[WARP Trace] WARPLY Cosmote User Request is active"
);
...
...
Please
register
or
login
to post a comment