Panagiotis Triantafyllou

feedback fixes

......@@ -36,7 +36,7 @@ public class SplashActivity extends BaseActivity {
public void onWarplyReady() {
if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) {
WarplyManager.getCosmoteUser(new WarplyCosmoteUserRequest()
.setGuid("6005892749"), //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons, prod 6006552990, prod 6005892749, live 3000184910
.setGuid("7000070282"), //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons, prod 6006552990, prod 6005892749, live 3000184910
mLoginReceiver);
} else {
startNextActivity();
......
......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4.6rc70'
PUBLISH_VERSION = '4.5.4.6rc71'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -280,9 +280,9 @@ public class LoyaltyMarketAnalysisActivity extends Activity implements View.OnCl
@Override
public void onSuccess(SharingList result) {
if (result != null && result.size() > 0) {
if (WarplyManagerHelper.getCouponsets() != null && WarplyManagerHelper.getCouponsets().size() > 0) {
if (WarplyManagerHelper.getCouponsetsDeals() != null && WarplyManagerHelper.getCouponsetsDeals().size() > 0) {
for (SharingCoupon shCoupon : result) {
for (Couponset cpnset : WarplyManagerHelper.getCouponsets()) {
for (Couponset cpnset : WarplyManagerHelper.getCouponsetsDeals()) {
if (shCoupon.getCouponsetUuid().equals(cpnset.getUuid())) {
SharingCoupon newShCoupon = new SharingCoupon();
newShCoupon = shCoupon;
......
......@@ -55,6 +55,7 @@ import ly.warp.sdk.io.models.ActiveDFYCouponEventModel;
import ly.warp.sdk.io.models.ActiveDFYCouponModel;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.Couponset;
import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel;
import ly.warp.sdk.io.models.UnifiedCoupon;
import ly.warp.sdk.io.models.WarplyDealsAnalysisEventModel;
......@@ -530,15 +531,29 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener, Vie
// Third Expandable Banner
if (WarplyManagerHelper.getMarketCoupons().size() > 0) {
countValue = 0.0f;
for (UnifiedCoupon unicou : WarplyManagerHelper.getMarketCoupons()) {
if (unicou.getCoupons() != null && unicou.getCoupons().size() > 0) {
for (Coupon inncou : unicou.getCoupons()) {
if (inncou.getStatus() == 0) {
countValue += Float.valueOf(inncou.getDiscount());
// for (UnifiedCoupon unicou : WarplyManagerHelper.getMarketCoupons()) {
// if (unicou.getCoupons() != null && unicou.getCoupons().size() > 0) {
// for (Coupon inncou : unicou.getCoupons()) {
// if (inncou.getStatus() == 0) {
// countValue += Float.valueOf(inncou.getDiscount());
// }
// }
// }
// }
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.valueOf(cou.getDiscount());
break;
}
}
}
}
}
mFavValue += countValue;
String badgeValue = String.format("%.02f", countValue);
mTvMarketValue.setText(String.format(getString(R.string.cos_value), badgeValue));
......
......@@ -43,6 +43,18 @@ public interface ApiService {
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getUserCoupons(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
......
......@@ -111,8 +111,10 @@ public class WarplyManagerHelper {
private static Consumer mConsumerInternal = new Consumer();
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 mCouponListExpired = new CouponList();
private static CouponsetsList mCouponsetsList = new CouponsetsList();
private static CouponsetsList mCouponsetsDealsList = new CouponsetsList();
private static CustomerStateModel mCustomerStateModel = new CustomerStateModel();
private static ArrayList<Campaign> mCampaignList = new ArrayList<Campaign>();
private static ArrayList<Campaign> mCampaignListAll = new ArrayList<Campaign>();
......@@ -1231,6 +1233,15 @@ public class WarplyManagerHelper {
});
}
public static void setCouponRedeemedList(CouponList couponRedeemedList) {
mCouponRedeemedList.clear();
mCouponRedeemedList.addAll(couponRedeemedList);
}
public static CouponList getCouponRedeemedList() {
return mCouponRedeemedList;
}
public static LoyaltyBadgeModel getLoyaltyBadge() {
return mLoyaltyBadge;
}
......@@ -1243,6 +1254,14 @@ public class WarplyManagerHelper {
mCouponsetsList = couponsets;
}
public static void setCouponsetsDeals(CouponsetsList couponsetsDeals) {
mCouponsetsDealsList = couponsetsDeals;
}
public static CouponsetsList getCouponsetsDeals() {
return mCouponsetsDealsList;
}
public static void setMerchantList(MerchantList merchantList) {
mMerchantList.clear();
mMerchantList = merchantList;
......
......@@ -1898,66 +1898,124 @@ public class WarplyManager {
WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
getUnifiedCouponsRetro(service, new Callback<ResponseBody>() {
getCouponsetsRetro(service, true, 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;
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> responseCouponsets) {
if (responseCouponsets.code() == 200 && responseCouponsets.body() != null) {
JSONObject jobjCouponsetsResponse = null;
try {
jobjCouponsResponse = new JSONObject(responseCoupons.body().string());
jobjCouponsetsResponse = new JSONObject(responseCouponsets.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) {
ArrayList<UnifiedCoupon> couponList = new ArrayList<UnifiedCoupon>();
ArrayList<UnifiedCoupon> allCouponList = new ArrayList<UnifiedCoupon>();
if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_unified_coupons_loyalty");
dynatraceEvent.setEventName("custom_success_couponsets_sm_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
JSONObject finalJobjCouponsResponse = jobjCouponsResponse;
final ExecutorService executor = Executors.newFixedThreadPool(1);
executor.submit(() -> {
JSONObject jCouponsBody = null;
try {
jCouponsBody = finalJobjCouponsResponse.optJSONObject("result");
if (jCouponsBody != null && jCouponsBody.length() > 0) {
JSONArray jCouponsInnerBody = null;
jCouponsInnerBody = jCouponsBody.optJSONArray("coupons");
if (jCouponsInnerBody != null && jCouponsInnerBody.length() > 0) {
for (int i = 0; i < jCouponsInnerBody.length(); i++) {
UnifiedCoupon tempUni = new UnifiedCoupon(jCouponsInnerBody.optJSONObject(i));
allCouponList.add(tempUni);
if (tempUni.getStatus().trim().equals("active"))
couponList.add(tempUni);
}
WarplyManagerHelper.setMarketCoupons(allCouponList);
JSONObject finalJobjCouponsetsResponse = jobjCouponsetsResponse;
// COUPONSETS START //
JSONArray jCouponsetsBody = null;
try {
jCouponsetsBody = finalJobjCouponsetsResponse.optJSONArray("result");
} catch (Exception e) {
e.printStackTrace();
}
// COUPONSETS END //
if (jCouponsetsBody != null) {
CouponsetsList mCouponsetList = new CouponsetsList();
for (int i = 0; i < jCouponsetsBody.length(); ++i) {
Couponset tempCouponset = new Couponset(jCouponsetsBody.optJSONObject(i));
mCouponsetList.add(tempCouponset);
}
WarplyManagerHelper.setCouponsetsDeals(mCouponsetList);
getUnifiedCouponsRetro(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) {
ArrayList<UnifiedCoupon> couponList = new ArrayList<UnifiedCoupon>();
ArrayList<UnifiedCoupon> allCouponList = new ArrayList<UnifiedCoupon>();
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_unified_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
JSONObject finalJobjCouponsResponse = jobjCouponsResponse;
final ExecutorService executor = Executors.newFixedThreadPool(1);
executor.submit(() -> {
JSONObject jCouponsBody = null;
try {
jCouponsBody = finalJobjCouponsResponse.optJSONObject("result");
if (jCouponsBody != null && jCouponsBody.length() > 0) {
JSONArray jCouponsInnerBody = null;
jCouponsInnerBody = jCouponsBody.optJSONArray("coupons");
if (jCouponsInnerBody != null && jCouponsInnerBody.length() > 0) {
for (int i = 0; i < jCouponsInnerBody.length(); i++) {
UnifiedCoupon tempUni = new UnifiedCoupon(jCouponsInnerBody.optJSONObject(i));
allCouponList.add(tempUni);
if (tempUni.getStatus().trim().equals("active"))
couponList.add(tempUni);
}
WarplyManagerHelper.setMarketCoupons(allCouponList);
}
}
} catch (Exception e) {
e.printStackTrace();
}
new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(couponList));
executor.shutdownNow();
});
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_unified_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_unified_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(responseCoupons.code());
}
}
} catch (Exception e) {
e.printStackTrace();
}
new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(couponList));
executor.shutdownNow();
});
@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_unified_coupons_loyalty");
dynatraceEvent.setEventName("custom_error_couponsets_sm_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_unified_coupons_loyalty");
dynatraceEvent.setEventName("custom_error_couponsets_sm_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(responseCoupons.code());
receiver.onFailure(responseCouponsets.code());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
public void onFailure(Call<ResponseBody> call, Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
dynatraceEvent.setEventName("custom_error_couponsets_sm_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
......@@ -2305,6 +2363,7 @@ public class WarplyManager {
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));
......@@ -2323,8 +2382,16 @@ public class WarplyManager {
}
}
}
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) {
......@@ -2469,6 +2536,47 @@ public class WarplyManager {
});
}
private static void getCouponsetsRetro(ApiService service, boolean isFiltered, 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());
Map<String, Object> jsonParamsCouponsets = new ArrayMap<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "retrieve_multilingual");
jsonParams.put("active", true);
jsonParams.put("visible", true);
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParams.put("couponset_types", new JSONArray().put("supermarket"));
jsonParamsCouponsets.put("coupon", jsonParams);
RequestBody couponsetsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCouponsets)).toString());
Call<ResponseBody> couponsetsCall = service.getCouponsets(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
couponsetsRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp),
"Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")
);
couponsetsCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
callback.onResponse(call, response);
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
callback.onFailure(call, t);
}
});
}
private static void getUnifiedCouponsRetro(ApiService service, Callback<ResponseBody> callback) {
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
......