Panagiotis Triantafyllou

seasonal, pacing request

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4-cosbeta15'
PUBLISH_VERSION = '4.5.4-cosbeta16'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
package ly.warp.sdk.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
......@@ -14,18 +12,13 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import ly.warp.sdk.R;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Couponset;
import ly.warp.sdk.io.models.CouponsetsList;
import ly.warp.sdk.io.models.LoyaltyContextualOfferModel;
import ly.warp.sdk.io.models.LoyaltyGiftsForYouOfferClickEvent;
import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage;
......@@ -62,10 +55,9 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gifts_for_you);
ArrayList<LoyaltyGiftsForYouPackage> list = new ArrayList();
mergeDatasets(
WarplyManagerHelper.getUniqueCampaignList().get("gifts_for_you"),
WarplyManagerHelper.getCouponsets()
WarplyManagerHelper.getSeasonalList()
);
mIvBack = findViewById(R.id.iv_list_close);
......@@ -132,11 +124,11 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
}
} else if (dataItem.getDataType() == 2) {
EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltyContextualOfferModel()));
Intent intent = new Intent(GiftsForYouActivity.this, CouponsetInfoActivity.class);
intent.putExtra("couponset", (Serializable) dataItem.getCouponset());
startActivity(intent);
LoyaltyGiftsForYouOfferClickEvent seasonalCLick = new LoyaltyGiftsForYouOfferClickEvent();
seasonalCLick.setTitle(dataItem.getSeasonalList().getTitle());
seasonalCLick.setLoyaltyPackageId(dataItem.getSeasonalList().getLoyaltyPackageId());
seasonalCLick.setImageUrl(dataItem.getSeasonalList().getImageUrl());
EventBus.getDefault().post(new WarplyEventBusManager(seasonalCLick));
}
})
.doOnError(error -> {
......@@ -145,22 +137,22 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
}
}
private ArrayList<MergedGifts> mergeDatasets(CampaignList campaignList, CouponsetsList couponsetsList) {
private ArrayList<MergedGifts> mergeDatasets(CampaignList campaignList, ArrayList<LoyaltyGiftsForYouPackage> seasonalList) {
if (campaignList != null && campaignList.size() > 0) {
for (Campaign campaign : campaignList) {
MergedGifts data = new MergedGifts();
data.setCampaign(campaign);
data.setCouponset(null);
data.setSeasonalList(null);
data.setDataType(1);
mData.add(data);
}
}
if (couponsetsList != null && couponsetsList.size() > 0) {
for (Couponset couponset : couponsetsList) {
if (seasonalList != null && seasonalList.size() > 0) {
for (LoyaltyGiftsForYouPackage seasonal : seasonalList) {
MergedGifts data = new MergedGifts();
data.setCampaign(null);
data.setCouponset(couponset);
data.setSeasonalList(seasonal);
data.setDataType(2);
mData.add(data);
}
......
/*
* 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.callbacks;
import org.json.JSONObject;
import ly.warp.sdk.io.models.PacingDetails;
/**
* Created by Panagiotis Triantafyllou on 24-June-22.
*/
public class PacingDetailsHook implements CallbackReceiver<JSONObject> {
private final CallbackReceiver<PacingDetails> mListener;
private final String mRequestSignature;
public PacingDetailsHook(CallbackReceiver<PacingDetails> listener, String requestSignature) {
this.mListener = listener;
this.mRequestSignature = requestSignature;
}
@Override
public void onSuccess(JSONObject result) {
if (mListener != null) {
int status = result.optInt("status", 2);
if (status == 1) {
mListener.onSuccess(new PacingDetails(result));
} else
mListener.onFailure(status);
}
}
@Override
public void onFailure(int errorCode) {
if (mListener != null)
mListener.onFailure(errorCode);
}
}
......@@ -31,16 +31,13 @@ package ly.warp.sdk.io.models;
public class MergedGifts {
private int dataType = 0;
private Couponset couponset;
private LoyaltyGiftsForYouPackage seasonalList;
private Campaign campaign;
public void setDataType(int dataType) {
this.dataType = dataType;
}
public void setCouponset(Couponset couponset) {
this.couponset = couponset;
}
public void setCampaign(Campaign campaign) {
this.campaign = campaign;
......@@ -50,8 +47,12 @@ public class MergedGifts {
return dataType;
}
public Couponset getCouponset() {
return couponset;
public LoyaltyGiftsForYouPackage getSeasonalList() {
return seasonalList;
}
public void setSeasonalList(LoyaltyGiftsForYouPackage seasonalList) {
this.seasonalList = seasonalList;
}
public Campaign getCampaign() {
......
/*
* 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;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 24-June-22.
*/
public class PacingDetails {
private static final long serialVersionUID = -4754964462459705285L;
/* Constants used to export the campaign in JSON formal and vice versa */
private static final String STEPS = "steps";
private static final String METERS = "meters";
private static final String RESULT = "result";
/* Member variables of the Campaign object */
private PacingInner steps = new PacingInner();
private PacingInner meters = new PacingInner();
/**
* Basic constructor used to create an object from a String, representing a
* JSON Object
*
* @param json The String, representing the JSON Object
* @throws JSONException Thrown if the String cannot be converted to JSON
*/
public PacingDetails(String json) throws JSONException {
this(new JSONObject(json));
}
/**
* Constructor used to create an Object from a given JSON Object
*
* @param json JSON Object used to create the Campaign
*/
public PacingDetails(JSONObject json) {
if (json != null) {
JSONObject result = new JSONObject();
result = json.optJSONObject(RESULT);
if (result != null) {
if (result.optJSONObject(STEPS) != null) {
this.steps = new PacingInner(result.optJSONObject(STEPS));
}
if (result.optJSONObject(METERS) != null) {
this.meters = new PacingInner(result.optJSONObject(METERS));
}
}
}
}
/**
* Converts the Campaign into a JSON Object
*
* @return The JSON Object created from this campaign
*/
public JSONObject toJSONObject() {
JSONObject jObj = new JSONObject();
try {
jObj.putOpt(STEPS, this.steps);
jObj.putOpt(METERS, this.meters);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
}
return jObj;
}
/**
* String representation of the Campaign, as a JSON object
*
* @return A String representation of JSON object
*/
public String toString() {
if (toJSONObject() != null)
return toJSONObject().toString();
return null;
}
/**
* String representation of the Campaign, as a human readable JSON object
*
* @return A human readable String representation of JSON object
*/
public String toHumanReadableString() {
String humanReadableString = null;
try {
humanReadableString = toJSONObject().toString(2);
} catch (JSONException e) {
WarpUtils.warn("Failed converting Campaign JSON object to String",
e);
}
return humanReadableString;
}
private class PacingInner {
private static final String TOTAL = "total";
private static final String MONTH = "month";
private static final String WEEK = "week";
private static final String DAY = "day";
private PacingDetailsInner total = new PacingDetailsInner();
private PacingDetailsInner month = new PacingDetailsInner();
private PacingDetailsInner week = new PacingDetailsInner();
private PacingDetailsInner day = new PacingDetailsInner();
public PacingInner() {
this.total = new PacingDetailsInner();
this.month = new PacingDetailsInner();
this.week = new PacingDetailsInner();
this.day = new PacingDetailsInner();
}
public PacingInner(JSONObject json) {
if (json != null) {
if (json.optJSONObject(TOTAL) != null) {
this.total = new PacingDetailsInner(json.optJSONObject(TOTAL));
}
if (json.optJSONObject(MONTH) != null) {
this.total = new PacingDetailsInner(json.optJSONObject(MONTH));
}
if (json.optJSONObject(WEEK) != null) {
this.total = new PacingDetailsInner(json.optJSONObject(WEEK));
}
if (json.optJSONObject(DAY) != null) {
this.total = new PacingDetailsInner(json.optJSONObject(DAY));
}
}
}
public PacingDetailsInner getTotal() {
return total;
}
public void setTotal(PacingDetailsInner total) {
this.total = total;
}
public PacingDetailsInner getMonth() {
return month;
}
public void setMonth(PacingDetailsInner month) {
this.month = month;
}
public PacingDetailsInner getWeek() {
return week;
}
public void setWeek(PacingDetailsInner week) {
this.week = week;
}
public PacingDetailsInner getDay() {
return day;
}
public void setDay(PacingDetailsInner day) {
this.day = day;
}
}
private class PacingDetailsInner {
private static final String GOAL = "goal";
private static final String VALLUE = "value";
private static final String PER_DAY = "per_day";
private double goal = 0.0d;
private double value = 0.0d;
private ArrayList<PacingDetailsDay> per_day = new ArrayList<>();
public PacingDetailsInner() {
this.goal = 0.0f;
this.value = 0.0f;
this.per_day = new ArrayList<>();
}
public PacingDetailsInner(JSONObject json) {
if (json != null) {
this.goal = json.optDouble(GOAL);
this.value = json.optDouble(VALLUE);
if (json.optJSONArray(PER_DAY) != null) {
JSONArray perDay = new JSONArray();
perDay = json.optJSONArray(PER_DAY);
if (perDay != null) {
ArrayList<PacingDetailsDay> list = new ArrayList<>();
for (int i = 0; i < perDay.length(); i++) {
JSONObject object = perDay.optJSONObject(i);
if (object != null) {
list.add(new PacingDetailsDay(object));
}
}
this.per_day = list;
}
}
}
}
public double getGoal() {
return goal;
}
public void setGoal(double goal) {
this.goal = goal;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public ArrayList<PacingDetailsDay> getPer_day() {
return per_day;
}
public void setPer_day(ArrayList<PacingDetailsDay> per_day) {
this.per_day = per_day;
}
}
private class PacingDetailsDay {
private static final String DAY = "day";
private static final String VALLUE = "value";
private String day = "";
private double value = 0.0d;
public PacingDetailsDay() {
this.day = "";
this.value = 0.0f;
}
public PacingDetailsDay(JSONObject json) {
if (json != null) {
this.day = json.optString(DAY);
this.value = json.optDouble(VALLUE);
}
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}
// ================================================================================
// Getters
// ================================================================================
public PacingInner getSteps() {
return steps;
}
public void setSteps(PacingInner steps) {
this.steps = steps;
}
public PacingInner getMeters() {
return meters;
}
public void setMeters(PacingInner meters) {
this.meters = meters;
}
}
package ly.warp.sdk.io.request;
import android.util.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 24-June-22.
*/
public class PacingDetailsRequest {
// ===========================================================
// Constants
// ===========================================================
private final String KEY_MAPP = "consumer_data";
private final String KEY_ACTION = "action";
private final String KEY_ACTION_VALUE = "integration";
private final String KEY_METHOD = "method";
private final String KEY_METHOD_VALUE = "steps";
private final String KEY_OPERATION = "operation";
private final String KEY_OPERATION_VALUE = "get";
// ===========================================================
// Fields
// ===========================================================
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mSharingId = "";
// ===========================================================
// Constructor
// ===========================================================
/**
* Default constructor of CosmoteSharingRequest, initializes an empty filters HashMap
*/
public PacingDetailsRequest() {
mFilters = new HashMap<>();
}
public PacingDetailsRequest(PacingDetailsRequest copy) {
if (copy != null) {
this.mFilters = copy.mFilters;
this.mCacheUpdateInterval = copy.mCacheUpdateInterval;
}
}
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean equals(Object object) {
if (object instanceof PacingDetailsRequest) {
PacingDetailsRequest other = (PacingDetailsRequest) object;
return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters)));
}
return false;
}
@Override
public int hashCode() {
return mFilters.hashCode();
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
public PacingDetailsRequest setSharingId(String sharingId) {
mSharingId = sharingId;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
* @return mCacheUpdateInterval
*/
public long getCacheUpdateInterval() {
return mCacheUpdateInterval;
}
/**
* Call this to set how often the cached data will be updated.
*
* @param updateInterval The time that data will be cached
* @return CosmoteSharingRequest
*/
public PacingDetailsRequest setCacheUpdateInterval(long updateInterval) {
this.mCacheUpdateInterval = updateInterval;
if (mCacheUpdateInterval < 0) {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to check if the Application uses Cache
*
* @return <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
*/
public boolean isUseCache() {
return mCacheUpdateInterval > 0;
}
/**
* Call this to check whether the cached data need to be updated
*
* @param useCache <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
* @return CosmoteSharingRequest
*/
public PacingDetailsRequest setUseCache(boolean useCache) {
if (useCache) {
mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval
: WarpConstants.INBOX_UPDATE_INTERVAL;
} else {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to build the offers Json object
*
* @return bodyJsonObject
*/
public JSONObject toJson() {
JSONObject bodyJsonObject = new JSONObject();
try {
JSONObject extraJson = new JSONObject();
extraJson.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
extraJson.putOpt(KEY_METHOD, KEY_METHOD_VALUE);
extraJson.putOpt(KEY_OPERATION, KEY_OPERATION_VALUE);
bodyJsonObject.putOpt(KEY_MAPP, extraJson);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
e.printStackTrace();
}
return bodyJsonObject;
}
public String getSignature() {
String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_pacing_details_request";
try {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8"));
signature = Base64.encodeToString(hash, Base64.NO_WRAP);
} catch (NullPointerException | NoSuchAlgorithmException
| UnsupportedEncodingException e) {
e.printStackTrace();
}
return signature;
}
}
......@@ -40,6 +40,7 @@ import ly.warp.sdk.io.callbacks.CouponsetsHook;
import ly.warp.sdk.io.callbacks.MerchantCategoriesHook;
import ly.warp.sdk.io.callbacks.MerchantsHook;
import ly.warp.sdk.io.callbacks.NewCampaignsHook;
import ly.warp.sdk.io.callbacks.PacingDetailsHook;
import ly.warp.sdk.io.callbacks.PointsHook;
import ly.warp.sdk.io.callbacks.ProductsHook;
import ly.warp.sdk.io.callbacks.TagsCategoriesHook;
......@@ -55,6 +56,7 @@ import ly.warp.sdk.io.models.CouponsetsList;
import ly.warp.sdk.io.models.MerchantCategoriesList;
import ly.warp.sdk.io.models.MerchantList;
import ly.warp.sdk.io.models.NewCampaignList;
import ly.warp.sdk.io.models.PacingDetails;
import ly.warp.sdk.io.models.PointsList;
import ly.warp.sdk.io.models.ProductList;
import ly.warp.sdk.io.models.TagsCategoriesList;
......@@ -62,6 +64,7 @@ import ly.warp.sdk.io.models.TagsList;
import ly.warp.sdk.io.models.TransactionsList;
import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest;
import ly.warp.sdk.io.request.CosmoteSharingRequest;
import ly.warp.sdk.io.request.PacingDetailsRequest;
import ly.warp.sdk.io.request.WarplyAddAddressRequest;
import ly.warp.sdk.io.request.WarplyAddCardRequest;
import ly.warp.sdk.io.request.WarplyAuthorizeRequest;
......@@ -1429,4 +1432,40 @@ public class WarplyManager {
}
});
}
public static void getPacingDetails(PacingDetailsRequest request, final CallbackReceiver<PacingDetails> receiver) {
WarpUtils.log("************* WARPLY Pacing Details Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Pacing Details Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(true, "context", request.toJson(), new PacingDetailsHook(new CallbackReceiver<PacingDetails>() {
@Override
public void onSuccess(PacingDetails result) {
receiver.onSuccess(result);
}
@Override
public void onFailure(int errorCode) {
if (errorCode == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
getPacingDetails(request, receiver);
else
receiver.onFailure(status);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
} else
receiver.onFailure(errorCode);
}
},
request.getSignature()));
}
}
......
......@@ -91,13 +91,13 @@ public class MergedGiftsAdapter extends RecyclerView.Adapter<MergedGiftsAdapter.
holder.tvMergedGiftsTitle.setText(mergedgiftsItem.getCampaign().getTitle());
} else if (mergedgiftsItem != null && mergedgiftsItem.getDataType() == 2) {
if (!TextUtils.isEmpty(mergedgiftsItem.getCouponset().getImgPreview())) {
if (!TextUtils.isEmpty(mergedgiftsItem.getSeasonalList().getImageUrl())) {
Glide.with(mContext)
// .setDefaultRequestOptions(
// RequestOptions
// .placeholderOf(R.drawable.ic_default_contact_photo)
// .error(R.drawable.ic_default_contact_photo))
.load(mergedgiftsItem.getCouponset().getImgPreview())
.load(mergedgiftsItem.getSeasonalList().getImageUrl())
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(holder.ivMergedGiftsLogo);
} else {
......@@ -106,7 +106,7 @@ public class MergedGiftsAdapter extends RecyclerView.Adapter<MergedGiftsAdapter.
.into(holder.ivMergedGiftsLogo);
}
holder.tvMergedGiftsTitle.setText(mergedgiftsItem.getCouponset().getName());
holder.tvMergedGiftsTitle.setText(mergedgiftsItem.getSeasonalList().getTitle());
// holder.tvMergedGiftsTitle.setText(Html.fromHtml(mergedgiftsItem.getCouponset().getDescription()));
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
......