Panagiotis Triantafyllou

sm deals changes, cancel unified coupon

......@@ -36,7 +36,7 @@ public class SplashActivity extends BaseActivity {
public void onWarplyReady() {
if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) {
WarplyManager.getCosmoteUser(new WarplyCosmoteUserRequest()
.setGuid("7000000833"), //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons, prod 6006552990, prod 6005892749, live 3000184910
.setGuid("7000000800"), //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.6rc76'
PUBLISH_VERSION = '4.5.4.6rc77'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -6,11 +6,13 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
......@@ -22,6 +24,8 @@ import com.google.zxing.BarcodeFormat;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.EAN13Writer;
import org.greenrobot.eventbus.EventBus;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -30,11 +34,15 @@ import java.util.Date;
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
import ly.warp.sdk.R;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.RefreshUnifiedCouponsEventModel;
import ly.warp.sdk.io.models.UnifiedCoupon;
import ly.warp.sdk.utils.WarplyManagerHelper;
import ly.warp.sdk.utils.managers.WarplyAnalyticsManager;
import ly.warp.sdk.utils.managers.WarplyEventBusManager;
import ly.warp.sdk.utils.managers.WarplyManager;
import ly.warp.sdk.views.adapters.ActiveCouponAdapter;
......@@ -51,12 +59,14 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
private ImageView mIvBack, mIvBarcode, mIvMarketExpand;
private TextView mTvTerms, mTvCouponCode, mTvCouponDate, mTvMarketExpand,
mTvTermsValue, mTvFullBarcode, mTvActiveValue;
private LinearLayout mLlShops, mLlBarcodeContainer, mLlTerms, mLlMarketCoupons, mLlMarketExpand;
private LinearLayout mLlShops, mLlBarcodeContainer, mLlTerms, mLlMarketCoupons, mLlMarketExpand,
mLlCancelUnified;
private UnifiedCoupon mCoupon;
private boolean mIsBarcodeShown = false, mIsTermsShown = false, mIsFromWallet = false,
mIsMarketExpand = true, mShopsPressed = false, mCouponPressed = false;
private RecyclerView mRecyclerCoupons;
private ActiveCouponAdapter mAdapterCoupons;
private AlertDialog mErrorAlertDialog, mSuccessAlertDialog, mAskCancelUnifiedAlertDialog;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -94,6 +104,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
mIvMarketExpand = findViewById(R.id.iv_market_expand);
mRecyclerCoupons = findViewById(R.id.rv_active_market_coupons);
mTvActiveValue = findViewById(R.id.textView14);
mLlCancelUnified = findViewById(R.id.ll_cancel_coupon);
mRecyclerCoupons.setNestedScrollingEnabled(false);
mRecyclerCoupons.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
......@@ -155,6 +166,10 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
mIvMarketExpand.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_up_dark_new));
mIsMarketExpand = true;
}
return;
}
if (view.getId() == R.id.ll_cancel_coupon) {
askCancelUnifiedDialog();
}
}
......@@ -193,7 +208,8 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
cpnlist.add(cpn);
}
mTvActiveValue.setText(HtmlCompat.fromHtml(String.format(getString(R.string.cos_unified_subtitle), String.valueOf(activeValue)), HtmlCompat.FROM_HTML_MODE_COMPACT));
// mTvActiveValue.setText(HtmlCompat.fromHtml(String.format(getString(R.string.cos_unified_subtitle), String.valueOf(activeValue)), HtmlCompat.FROM_HTML_MODE_COMPACT));
mTvActiveValue.setText(getString(R.string.cos_unified_subtitle2));
Collections.sort(cpnlist, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
for (Coupon tempItem : cpnlist) {
......@@ -234,6 +250,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
mLlShops.setOnClickListener(this);
mLlTerms.setOnClickListener(this);
mLlMarketExpand.setOnClickListener(this);
mLlCancelUnified.setOnClickListener(this);
String tempCoupon = "";
int result = 0;
......@@ -280,6 +297,72 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
}
}
private void cancelUnified() {
if (mCoupon.getCoupons() != null && mCoupon.getCoupons().size() == 0) return;
String transactionID = mCoupon.getCoupons().get(0).getTransactionUuid();
if (TextUtils.isEmpty(transactionID)) return;
WarplyManager.cancelUnifiedCoupon(transactionID, mCancelUnifiedCallback);
}
private void askCancelUnifiedDialog() {
if (!isFinishing()) {
mAskCancelUnifiedAlertDialog = new AlertDialog.Builder(this)
.setTitle(R.string.cos_dlg_cancel_unified_coupon_success_title)
.setMessage(R.string.cos_dlg_cancel_unified_coupon_success_subtitle2)
.setPositiveButton(R.string.cos_dlg_positive_button3, (dialogPositive, whichPositive) -> {
cancelUnified();
})
.setNegativeButton(R.string.cos_dlg_negative_button4, (dialogNegative, whichNegative) -> {
dialogNegative.dismiss();
})
.show();
}
}
private void errorDialog() {
if (!isFinishing()) {
mErrorAlertDialog = new AlertDialog.Builder(this)
.setTitle(R.string.cos_dlg_cancel_unified_coupon_success_title)
.setMessage(R.string.cos_dlg_error_subtitle)
.setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> {
dialogPositive.dismiss();
})
.setCancelable(false)
.show();
}
}
private void successDialog() {
if (!isFinishing()) {
mSuccessAlertDialog = new AlertDialog.Builder(this)
.setTitle(R.string.cos_dlg_cancel_unified_coupon_success_title)
.setMessage(R.string.cos_dlg_cancel_unified_coupon_success_subtitle)
.setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> {
dialogPositive.dismiss();
RefreshUnifiedCouponsEventModel couponsRefreshed = new RefreshUnifiedCouponsEventModel();
EventBus.getDefault().post(new WarplyEventBusManager(couponsRefreshed));
onBackPressed();
})
.setCancelable(false)
.show();
}
}
private final CallbackReceiver<Integer> mCancelUnifiedCallback = new CallbackReceiver<Integer>() {
@Override
public void onSuccess(Integer result) {
successDialog();
}
@Override
public void onFailure(int errorCode) {
errorDialog();
}
};
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ly.warp.sdk.io.models;
/**
* Created by Panagiotis Triantafyllou on 03-Oct-23.
*/
public class RefreshUnifiedCouponsEventModel {
private boolean success;
public RefreshUnifiedCouponsEventModel() {
this.success = true;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
......@@ -102,6 +102,18 @@ public interface ApiService {
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> cancelUnifiedCoupon(@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> getTelematicsHistoy(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
......
......@@ -14,6 +14,7 @@ import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel;
import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel;
import ly.warp.sdk.io.models.LoyaltySDKSessionExpiredEventModel;
import ly.warp.sdk.io.models.QuestionnaireEventModel;
import ly.warp.sdk.io.models.RefreshUnifiedCouponsEventModel;
import ly.warp.sdk.io.models.UnifiedCouponsEventModel;
import ly.warp.sdk.io.models.WarplyCCMSEnabledModel;
import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
......@@ -46,6 +47,7 @@ public class WarplyEventBusManager {
private CouponsEventModel couponsAdded;
private UnifiedCouponsEventModel unifiedCouponsAdded;
private RefreshUnifiedCouponsEventModel refreshUnifiedCouponsAdded;
private LoyaltyEventModel campaignsAdded;
private HealthEventModel healthAdded;
private WarplyCouponsChangedEventModel couponsChanged;
......@@ -96,6 +98,10 @@ public class WarplyEventBusManager {
this.unifiedCouponsAdded = unifiedCouponsAdded;
}
public WarplyEventBusManager(RefreshUnifiedCouponsEventModel refreshUnifiedCouponsAdded) {
this.refreshUnifiedCouponsAdded = refreshUnifiedCouponsAdded;
}
public WarplyEventBusManager(WarplyPacingCardEventModel widgetChanged) {
this.widgetChanged = widgetChanged;
}
......@@ -238,6 +244,10 @@ public class WarplyEventBusManager {
return unifiedCouponsAdded;
}
public RefreshUnifiedCouponsEventModel getRefreshUnifiedCouponsAdded() {
return refreshUnifiedCouponsAdded;
}
public LoyaltyEventModel getCampaignsAdded() {
return campaignsAdded;
}
......
......@@ -2027,6 +2027,56 @@ public class WarplyManager {
});
}
public static void cancelUnifiedCoupon(String transactionID, final CallbackReceiver<Integer> receiver) {
WarpUtils.log("************* WARPLY Cancel Unified Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Cancel Unified Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
cancelUnifiedCoupon(service, transactionID, new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject jobjResponse = null;
try {
jobjResponse = new JSONObject(response.body().string());
} catch (Exception e) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_cancel_unified_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
e.printStackTrace();
}
if (jobjResponse != null && jobjResponse.has("status") && jobjResponse.optInt("status", 2) == 1) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_cancel_unified_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
Integer status = new Integer(jobjResponse.optInt("status", 2));
receiver.onSuccess(status);
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_cancel_unified_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_cancel_unified_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(response.code());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_cancel_unified_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
});
}
public static void getUnifiedCouponsDeals(final CallbackReceiver<ArrayList<UnifiedCoupon>> receiver) {
WarpUtils.log("************* WARPLY User Coupons Request ********************");
WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
......@@ -2997,6 +3047,44 @@ public class WarplyManager {
});
}
private static void cancelUnifiedCoupon(ApiService service, String transactionID, 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> jsonParamsUnified = new ArrayMap<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "cancel_unified_coupon");
jsonParams.put("transaction_id", transactionID);
jsonParamsUnified.put("coupon", jsonParams);
RequestBody cancelUnifiedDataRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsUnified)).toString());
Call<ResponseBody> telematicsCall = service.cancelUnifiedCoupon(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
cancelUnifiedDataRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp),
"Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")
);
telematicsCall.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 getTelematicsHistory(ApiService service, Callback<ResponseBody> callback) {
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
......
......@@ -125,9 +125,9 @@ public class MarketCouponAdapter extends RecyclerView.Adapter<MarketCouponAdapte
}
if (count > 1) {
holder.tvCouponCount.setText(String.format(mContext.getString(R.string.cos_market_active_coupons), String.valueOf(count), String.valueOf(activeValue)));
holder.tvCouponCount.setText(String.format(mContext.getString(R.string.cos_market_active_coupons2), String.valueOf(count)));
} else if (count == 1) {
holder.tvCouponCount.setText(String.format(mContext.getString(R.string.cos_market_active_coupons_single), String.valueOf(count), String.valueOf(activeValue)));
holder.tvCouponCount.setText(String.format(mContext.getString(R.string.cos_market_active_coupons_single2), String.valueOf(count)));
}
......
......@@ -219,7 +219,7 @@
<LinearLayout
android:id="@+id/ll_shops"
android:layout_width="220dp"
android:layout_width="260dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginHorizontal="32dp"
......@@ -240,6 +240,29 @@
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_cancel_coupon"
android:layout_width="260dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginHorizontal="32dp"
android:layout_marginTop="20dp"
android:background="@drawable/selector_button_green_border"
android:gravity="center"
android:orientation="horizontal"
android:paddingVertical="8dp">
<TextView
fontPath="fonts/PeridotPE-SemiBold.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:text="@string/cos_cancel_unified_coupon"
android:textColor="@color/cos_green12"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:id="@+id/rl_terms"
android:layout_width="wrap_content"
......
......@@ -156,8 +156,11 @@
<string name="cos_market_item_title">COSMOTE\nSUPERMARKET\nDEALS</string>
<string name="cos_market_active_coupons">έχεις %1$s ενεργά κουπόνια αξίας %2$s€</string>
<string name="cos_market_active_coupons_single">έχεις %1$s ενεργό κουπόνι αξίας %2$s€</string>
<string name="cos_market_active_coupons2">έχεις %1$s ενεργά κουπόνια</string>
<string name="cos_market_active_coupons_single2">έχεις %1$s ενεργό κουπόνι</string>
<string name="cos_unified_title">Εκπτωτικό κουπόνι COSMOTE SUPERMARKET DEALS!</string>
<string name="cos_unified_subtitle">Χρησιμοποίησε τον παρακάτω κωδικό και πάρε έκπτωση στα ενεργά κουπόνια προσφορών αξίας <![CDATA[<b>%1$s€</b>]]>.</string>
<string name="cos_unified_subtitle2">Χρησιμοποίησε τον παρακάτω κωδικό και πάρε έκπτωση στα ενεργά κουπόνια προσφορών.</string>
<string name="cos_markets">Δες τα supermarket</string>
<string name="cos_show_market_coupons">Εμφάνιση προσφορών</string>
<string name="cos_hide_market_coupons">Απόκρυψη προσφορών</string>
......@@ -189,6 +192,12 @@
<string name="cos_telematics_history_analysis_rate">Αξιολογήστε την ανάλυση</string>
<string name="lbl_telematics_no_location">Για να ξεκινήσετε θα πρέπει να ενεργοποιήσετε την τοποθεσία σας</string>
<string name="lbl_telematics_generic_error">Άγνωστο σφάλμα</string>
<string name="cos_cancel_unified_coupon">Ακύρωση ενιαίου κουπονιού</string>
<string name="cos_dlg_cancel_unified_coupon_success_title">Ακύρωση Κουπονιού</string>
<string name="cos_dlg_cancel_unified_coupon_success_subtitle">Το ενιαίο κουπόνι σου ακυρώθηκε επιτυχώς. Βρες τα μεμονωμένα κουπόνια στο καλάθι SM deals.</string>
<string name="cos_dlg_cancel_unified_coupon_success_subtitle2">Είσαι σίγουρος ότι θέλεις να ακυρώσεις το κουπόνι σου;</string>
<string name="cos_dlg_negative_button4">Όχι</string>
<string name="cos_dlg_positive_button3">Ναι</string>
<string-array name="coupons_array">
<item>Κουπόνια</item>
......