Panagiotis Triantafyllou

minor fixes and additions

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4-cosbeta31i'
PUBLISH_VERSION = '4.5.4-cosbeta32'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -29,7 +29,9 @@ import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.CouponsetsList;
import ly.warp.sdk.io.models.NewCampaignList;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyGetCampaignsRequest;
import ly.warp.sdk.io.request.WarplyGetCouponsetsRequest;
import ly.warp.sdk.io.request.WarplyInboxRequest;
import ly.warp.sdk.io.request.WarplyUserCouponsRequest;
......@@ -69,6 +71,7 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
if (!Thread.currentThread().isInterrupted()) {
// WarplyManager.getConsumer(new WarplyConsumerRequest(), mConsumerReceiver);
Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver);
// WarplyManager.getCampaigns(new WarplyGetCampaignsRequest().setLanguage("el"), mCampaignsCallback);
}
}).start();
}
......@@ -204,6 +207,18 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
}
};
private CallbackReceiver<NewCampaignList> mCampaignsCallback = new CallbackReceiver<NewCampaignList>() {
@Override
public void onSuccess(NewCampaignList result) {
WarplyManager.getUserCouponsWithCouponsets(new WarplyUserCouponsRequest(), mUserCouponsReceiver);
}
@Override
public void onFailure(int errorCode) {
Thread.currentThread().interrupt();
}
};
private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() {
@Override
......
......@@ -182,6 +182,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
if (extraFields.has("ccms_offer") && extraFields.optString("ccms_offer").equals("true")) {
for (LoyaltyContextualOfferModel ccms : WarplyManagerHelper.getCCMSLoyaltyCampaigns()) {
if (ccms.getLoyaltyCampaignId().equals(dataItem.getCampaign().getSessionUUID())) {
WarpUtils.log("CCMS_CLICK " + ccms.toString());
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCcmsUrl(dataItem.getCampaign(), ccms)));
break;
}
......
......@@ -73,30 +73,30 @@ public class Campaign implements Parcelable, Serializable {
/* Member variables of the Campaign object */
private final int action;
private final double delivered;
private int action;
private double delivered;
private double expires;
private final String message;
private String message;
private String offerCategory;
private final String offerMessage;
private final String sessionUUID;
private final double starts;
private final String subtitle;
private final String title;
private final int sorting;
private final int opened;
private String offerMessage;
private String sessionUUID;
private double starts;
private String subtitle;
private String title;
private int sorting;
private int opened;
private boolean isNew;
private final String logoUrl;
private final String extraFields;
private final String type;
private final boolean expired;
private String logoUrl;
private String extraFields;
private String type;
private boolean expired;
private boolean show;
private String deliveryMethod;
private String displayType;
private String indexUrl;
private String busId;
private ArrayList<CampaignAction> actions = new ArrayList<>();
private final String campaignTypeSettings;
private String campaignTypeSettings;
/**
* Basic constructor used to create an object from a String, representing a
......@@ -109,6 +109,33 @@ public class Campaign implements Parcelable, Serializable {
this(new JSONObject(json));
}
public Campaign() {
this.action = 0;
this.delivered = 0.0d;
this.expires = 0.0d;
this.message = "";
this.offerCategory = "";
this.offerMessage = "";
this.sessionUUID = "";
this.starts = 0.0d;
this.subtitle = "";
this.title = "";
this.sorting = 0;
this.opened = 0;
this.isNew = true;
this.logoUrl = "";
this.extraFields = "";
this.type = "";
this.expired = false;
this.show = true;
this.deliveryMethod = "";
this.displayType = "";
this.indexUrl = "";
this.busId = "";
this.actions = new ArrayList<>();
this.campaignTypeSettings = "";
}
/**
* Constructor used to create an Object from a given JSON Object
*
......@@ -475,6 +502,94 @@ public class Campaign implements Parcelable, Serializable {
return campaignTypeSettings;
}
public void setExpires(double expires) {
this.expires = expires;
}
public void setOfferCategory(String offerCategory) {
this.offerCategory = offerCategory;
}
public void setShow(boolean show) {
this.show = show;
}
public void setDeliveryMethod(String deliveryMethod) {
this.deliveryMethod = deliveryMethod;
}
public void setDisplayType(String displayType) {
this.displayType = displayType;
}
public void setIndexUrl(String indexUrl) {
this.indexUrl = indexUrl;
}
public void setActions(ArrayList<CampaignAction> actions) {
this.actions = actions;
}
public void setAction(int action) {
this.action = action;
}
public void setDelivered(double delivered) {
this.delivered = delivered;
}
public void setMessage(String message) {
this.message = message;
}
public void setOfferMessage(String offerMessage) {
this.offerMessage = offerMessage;
}
public void setSessionUUID(String sessionUUID) {
this.sessionUUID = sessionUUID;
}
public void setStarts(double starts) {
this.starts = starts;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
public void setTitle(String title) {
this.title = title;
}
public void setSorting(int sorting) {
this.sorting = sorting;
}
public void setOpened(int opened) {
this.opened = opened;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public void setExtraFields(String extraFields) {
this.extraFields = extraFields;
}
public void setType(String type) {
this.type = type;
}
public void setExpired(boolean expired) {
this.expired = expired;
}
public void setCampaignTypeSettings(String campaignTypeSettings) {
this.campaignTypeSettings = campaignTypeSettings;
}
@Override
public int describeContents() {
return 0;
......
......@@ -69,12 +69,12 @@ public class NewCampaign implements Parcelable, Serializable {
/* Member variables of the Campaign object */
private final String campaignType;
private final String settings;
private JSONObject settings = new JSONObject();
private final String audience;
private final String deliveryMethod;
private final String displayType;
private final String extraFields;
private final String workflowSettings;
private JSONObject extraFields = new JSONObject();
private JSONObject workflowSettings = new JSONObject();
private final String category;
private final int sorting;
private final String indexUrl;
......@@ -115,13 +115,13 @@ public class NewCampaign implements Parcelable, Serializable {
this.category = json.optString(CATEGORY);
this.title = json.optString(TITLE);
this.sorting = json.optInt(SORTING);
this.extraFields = json.optString(EXTRA_FIELDS);
this.extraFields = json.optJSONObject(EXTRA_FIELDS);
this.campaignType = json.optString(CAMPAIGN_TYPE);
this.deliveryMethod = json.optString(DELIVERY_METHOD);
this.displayType = json.optString(DISPLAY_TYPE);
this.settings = json.optString(SETTINGS);
this.settings = json.optJSONObject(SETTINGS);
this.audience = json.optString(AUDIENCE);
this.workflowSettings = json.optString(WORKFLOW_SETTINGS);
this.workflowSettings = json.optJSONObject(WORKFLOW_SETTINGS);
this.description = json.optString(DESCRIPTION);
this.startDate = json.optString(START_DATE);
this.endDate = json.optString(END_DATE);
......@@ -140,12 +140,12 @@ public class NewCampaign implements Parcelable, Serializable {
this.sorting = source.readInt();
this.isNew = source.readByte() != 0;
this.logoUrl = source.readString();
this.extraFields = source.readString();
// this.extraFields = source.readString();
this.deliveryMethod = source.readString();
this.displayType = source.readString();
this.settings = source.readString();
// this.settings = source.readString();
this.audience = source.readString();
this.workflowSettings = source.readString();
// this.workflowSettings = source.readString();
this.description = source.readString();
this.startDate = source.readString();
this.endDate = source.readString();
......@@ -164,12 +164,12 @@ public class NewCampaign implements Parcelable, Serializable {
dest.writeInt(this.sorting);
dest.writeInt(this.isNew ? 1 : 0);
dest.writeString(this.logoUrl);
dest.writeString(extraFields);
// dest.writeString(extraFields);
dest.writeString(deliveryMethod);
dest.writeString(displayType);
dest.writeString(this.settings);
// dest.writeString(this.settings);
dest.writeString(this.audience);
dest.writeString(this.workflowSettings);
// dest.writeString(this.workflowSettings);
dest.writeString(this.description);
dest.writeString(this.startDate);
dest.writeString(this.endDate);
......@@ -295,10 +295,6 @@ public class NewCampaign implements Parcelable, Serializable {
return indexUrl;
}
public String getExtraFields() {
return extraFields;
}
public String getDeliveryMethod() {
return deliveryMethod;
}
......@@ -311,18 +307,10 @@ public class NewCampaign implements Parcelable, Serializable {
return campaignType;
}
public String getSettings() {
return settings;
}
public String getAudience() {
return audience;
}
public String getWorkflowSettings() {
return workflowSettings;
}
public String getCategory() {
return category;
}
......@@ -355,6 +343,18 @@ public class NewCampaign implements Parcelable, Serializable {
return isNew;
}
public JSONObject getSettings() {
return settings;
}
public JSONObject getExtraFields() {
return extraFields;
}
public JSONObject getWorkflowSettings() {
return workflowSettings;
}
@Override
public int describeContents() {
return 0;
......
......@@ -28,6 +28,8 @@ package ly.warp.sdk.utils.managers;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import ly.warp.sdk.Warply;
import ly.warp.sdk.activities.BaseFragmentActivity;
import ly.warp.sdk.db.WarplyDBHelper;
......@@ -48,6 +50,8 @@ import ly.warp.sdk.io.callbacks.TagsCategoriesHook;
import ly.warp.sdk.io.callbacks.TagsHook;
import ly.warp.sdk.io.callbacks.TransactionsHook;
import ly.warp.sdk.io.models.AddressList;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Card;
import ly.warp.sdk.io.models.CardList;
import ly.warp.sdk.io.models.Consumer;
......@@ -58,6 +62,7 @@ import ly.warp.sdk.io.models.Couponset;
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.NewCampaign;
import ly.warp.sdk.io.models.NewCampaignList;
import ly.warp.sdk.io.models.PacingDetails;
import ly.warp.sdk.io.models.PointsList;
......@@ -118,6 +123,7 @@ import ly.warp.sdk.utils.constants.WarpConstants;
*/
public class WarplyManager {
private static NewCampaignList mNewCampaignList = new NewCampaignList();
public static void getProducts(WarplyProductsRequest request, final CallbackReceiver<ProductList> receiver) {
// String productCategory = "";
......@@ -1318,27 +1324,88 @@ public class WarplyManager {
});
}
public static void getCampaigns(WarplyGetCampaignsRequest request, boolean auth, final CallbackReceiver<NewCampaignList> receiver) {
public static void getCampaigns(WarplyGetCampaignsRequest request, final CallbackReceiver<NewCampaignList> 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, auth, "campaigns", request.toJson(), new NewCampaignsHook(new CallbackReceiver<NewCampaignList>() {
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_NEW_CAMPAIGNS, false, "campaigns", request.toJson(), new NewCampaignsHook(new CallbackReceiver<NewCampaignList>() {
@Override
public void onSuccess(NewCampaignList result) {
// receiver.onSuccess(result);
mNewCampaignList.clear();
mNewCampaignList.addAll(result);
getCampaignsPersonalized(request, new CallbackReceiver<NewCampaignList>() {
@Override
public void onSuccess(NewCampaignList resultPersonalized) {
receiver.onSuccess(resultPersonalized);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
},
request.getSignature()));
}
public static void getCampaignsPersonalized(WarplyGetCampaignsRequest request, final CallbackReceiver<NewCampaignList> 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, true, "campaignsPersonalized", request.toJson(), new NewCampaignsHook(new CallbackReceiver<NewCampaignList>() {
@Override
public void onSuccess(NewCampaignList result) {
mNewCampaignList.addAll(result);
CampaignList tempCampaigns = new CampaignList();
for (NewCampaign newCamp : mNewCampaignList) {
Campaign camp = new Campaign();
camp.setIndexUrl(newCamp.getIndexUrl());
camp.setLogoUrl(newCamp.getLogoUrl());
camp.setMessage(newCamp.getMessage());
camp.setOfferCategory(newCamp.getCommunicationCategory());
camp.setSessionUUID(newCamp.getCommunicationUUID());
camp.setTitle(newCamp.getTitle());
camp.setSubtitle(newCamp.getSubtitle());
camp.setSorting(newCamp.getSorting());
camp.setNew(newCamp.getIsNew());
camp.setType(newCamp.getCampaignType());
try {
camp.setExtraFields(newCamp.getExtraFields().toString());
} catch (NullPointerException e) {
camp.setExtraFields("");
e.printStackTrace();
}
try {
camp.setCampaignTypeSettings(newCamp.getSettings().toString());
} catch (NullPointerException e) {
camp.setCampaignTypeSettings("");
e.printStackTrace();
}
tempCampaigns.add(camp);
}
WarplyManagerHelper.setCampaignList(tempCampaigns);
receiver.onSuccess(result);
}
@Override
public void onFailure(int errorCode) {
if (auth) {
if (errorCode == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
getCampaigns(request, auth, receiver);
getCampaignsPersonalized(request, receiver);
else
receiver.onFailure(status);
}
......@@ -1350,8 +1417,6 @@ public class WarplyManager {
});
} else
receiver.onFailure(errorCode);
} else
receiver.onFailure(errorCode);
}
},
request.getSignature()));
......@@ -1554,7 +1619,7 @@ public class WarplyManager {
WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
WarpUtils.log("**************************************************");
WarplyManager.getCouponsets(new WarplyGetCouponsetsRequest()
getCouponsets(new WarplyGetCouponsetsRequest()
.setLanguage(WarplyProperty.getLanguage(Warply.getWarplyContext())), new CallbackReceiver<CouponsetsList>() {
@Override
public void onSuccess(CouponsetsList result) {
......
......@@ -383,19 +383,6 @@ public class WarpView extends WebView {
questionnaireEvent.setName(parts[1]);
EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent));
} else if (parts[1].equals("userAnswered")) {
QuestionnaireEventModel questionnaireEvent = new QuestionnaireEventModel();
try {
questionnaireEvent.setName(parts[1]);
questionnaireEvent.setParameter(parts[2]);
WarpUtils.setUserTag(Warply.getWarplyContext(), parts[2]);
EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent));
} catch (IndexOutOfBoundsException e) {
questionnaireEvent.setName(parts[1]);
questionnaireEvent.setParameter("");
WarpUtils.setUserTag(Warply.getWarplyContext(), "");
EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent));
}
} else if (parts[1].equals("addUserTag")) {
// QuestionnaireEventModel questionnaireEvent = new QuestionnaireEventModel();
try {
// questionnaireEvent.setName(parts[1]);
......@@ -408,6 +395,19 @@ public class WarpView extends WebView {
WarpUtils.setUserTag(Warply.getWarplyContext(), "");
// EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent));
}
} else if (parts[1].equals("addUserTag")) {
QuestionnaireEventModel questionnaireEvent = new QuestionnaireEventModel();
try {
questionnaireEvent.setName(parts[1]);
questionnaireEvent.setParameter(parts[2]);
WarpUtils.setUserTag(Warply.getWarplyContext(), parts[2]);
EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent));
} catch (IndexOutOfBoundsException e) {
questionnaireEvent.setName(parts[1]);
questionnaireEvent.setParameter("");
WarpUtils.setUserTag(Warply.getWarplyContext(), "");
EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent));
}
} else if (parts[1].equals("couponRetrieved")) {
EventBus.getDefault().post(new WarplyEventBusManager(new CouponEventModel()));
} else if (parts[1].equals("couponShared")) {
......