Panagiotis Triantafyllou

fixes

......@@ -3,7 +3,6 @@ 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;
......@@ -14,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONObject;
import java.io.Serializable;
......@@ -102,6 +102,18 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
}
@Override
protected void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
protected void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.iv_list_close) {
onBackPressed();
......@@ -113,6 +125,90 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
}
}
@Subscribe()
public void onMessageEvent(WarplyEventBusManager event) {
if (event.getCcmsAdded() != null) {
filterItems();
if (WarplyManagerHelper.getSeasonalList() != null && WarplyManagerHelper.getSeasonalList().size() > 0) {
mHashSetSeasonalList.addAll(WarplyManagerHelper.getSeasonalList());
mSeasonalList.clear();
mSeasonalList.addAll(mHashSetSeasonalList);
}
mergeDatasets(
mValuesList,
mSeasonalList
);
runOnUiThread(() -> {
if (mData != null && mData.size() > 0) {
mAdapterMergedGifts = new MergedGiftsAdapter(GiftsForYouActivity.this, mData);
mRecyclerMergedGifts.setAdapter(mAdapterMergedGifts);
mAdapterMergedGifts.getPositionClicks()
.doOnNext(dataItem -> {
if (dataItem.getDataType() == 1) {
EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltyGiftsForYouOfferClickEvent()));
if (dataItem.getCampaign().getType().equals("coupon")) {
try {
JSONObject campaignSettings = WarpJSONParser.getJSONFromString(dataItem.getCampaign().getCampaignTypeSettings());
if (campaignSettings != null) {
if (campaignSettings.has("couponset")) {
String cpnUuid = campaignSettings.optString("couponset");
for (Couponset cpns : WarplyManagerHelper.getCouponsets()) {
if (cpns.getUuid().equals(cpnUuid)) {
Intent intent = new Intent(GiftsForYouActivity.this, CouponsetInfoActivity.class);
intent.putExtra("couponset", (Serializable) cpns);
startActivity(intent);
break;
}
}
} else {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return;
}
try {
JSONObject extraFields = WarpJSONParser.getJSONFromString(dataItem.getCampaign().getExtraFields());
if (extraFields != null) {
if (extraFields.has("ccms_offer") && extraFields.optString("ccms_offer").equals("true")) {
for (LoyaltyContextualOfferModel ccms : WarplyManagerHelper.getCCMSLoyaltyCampaigns()) {
if (ccms.getLoyaltyCampaignId().equals(dataItem.getCampaign().getSessionUUID())) {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCcmsUrl(dataItem.getCampaign(), ccms)));
break;
}
}
} else {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
}
}
} catch (Exception exception) {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
}
} else if (dataItem.getDataType() == 2) {
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 -> {
})
.subscribe();
mAdapterMergedGifts.notifyDataSetChanged();
}
});
}
}
// ===========================================================
// Methods
// ===========================================================
......@@ -190,6 +286,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
}
private void mergeDatasets(ArrayList<Campaign> campaignList, ArrayList<LoyaltyGiftsForYouPackage> seasonalList) {
mData.clear();
if (campaignList != null && campaignList.size() > 0) {
Log.v("GIFTS_FOR_YOU", String.valueOf(campaignList.size()));
for (Campaign campaign : campaignList) {
......@@ -214,6 +311,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
}
private void filterItems() {
mValuesList.clear();
ArrayList<Campaign> gfyList = new ArrayList<>();
if (WarplyManagerHelper.getCampaignListAll() != null && WarplyManagerHelper.getCampaignListAll().size() > 0) {
Log.v("Got L:{" + String.valueOf(WarplyManagerHelper.getCampaignListAll().size()) + "}", " LOYALTY campaigns");
......
......@@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONObject;
import java.util.ArrayList;
......@@ -80,6 +81,18 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener
}
@Override
protected void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
protected void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.iv_list_close) {
onBackPressed();
......@@ -91,6 +104,49 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener
}
}
@Subscribe()
public void onMessageEvent(WarplyEventBusManager event) {
if (event.getCcmsAdded() != null) {
filterItems();
runOnUiThread(() -> {
if (mValuesList != null && mValuesList.size() > 0) {
Log.v("MORE_FOR_YOU", String.valueOf(mValuesList.size()));
mAdapterMore = new MoreCampaignAdapter(this, mValuesList);
mRecyclerMore.setAdapter(mAdapterMore);
mAdapterMore.getPositionClicks()
.doOnNext(gift -> {
EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltySDKFirebaseEventModel()));
try {
JSONObject extraFields = WarpJSONParser.getJSONFromString(gift.getExtraFields());
if (extraFields != null) {
if (extraFields.has("ccms_offer") && extraFields.optString("ccms_offer").equals("true")) {
for (LoyaltyContextualOfferModel ccms : WarplyManagerHelper.getCCMSLoyaltyCampaigns()) {
if (ccms.getLoyaltyCampaignId().equals(gift.getSessionUUID())) {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCcmsUrl(gift, ccms)));
break;
}
}
} else {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(gift)));
}
}
} catch (Exception exception) {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(gift)));
}
})
.doOnError(error -> {
})
.subscribe();
mAdapterMore.notifyDataSetChanged();
} else {
mRecyclerMore.setVisibility(View.GONE);
}
});
}
}
// ===========================================================
// Methods
// ===========================================================
......@@ -138,6 +194,7 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener
}
private void filterItems() {
mValuesList.clear();
ArrayList<Campaign> gfyList = new ArrayList<>();
if (WarplyManagerHelper.getCampaignListAll() != null && WarplyManagerHelper.getCampaignListAll().size() > 0) {
Log.v("Got L:{" + String.valueOf(WarplyManagerHelper.getCampaignListAll().size()) + "}", " LOYALTY campaigns");
......
/*
* 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 12-July-22.
*/
public class ContexualEventModel {
private boolean success;
public ContexualEventModel() {
this.success = true;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
......@@ -31,6 +31,7 @@ import android.util.Log;
import androidx.appcompat.app.AlertDialog;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
import java.util.ArrayList;
......@@ -45,6 +46,7 @@ import ly.warp.sdk.io.models.ActiveDFYCouponModel;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.models.ContexualEventModel;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.CouponsetsList;
......@@ -55,6 +57,7 @@ import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage;
import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest;
import ly.warp.sdk.io.request.CosmoteSharingRequest;
import ly.warp.sdk.io.request.WarplyIntegrationRequest;
import ly.warp.sdk.utils.managers.WarplyEventBusManager;
import ly.warp.sdk.utils.managers.WarplyManager;
/**
......@@ -410,6 +413,9 @@ public class WarplyManagerHelper {
mCCMSList.clear();
mCCMSList.addAll(list);
ContexualEventModel ccmsAdded = new ContexualEventModel();
EventBus.getDefault().post(new WarplyEventBusManager(ccmsAdded));
// if (list == null || list.size() == 0) {
// CampaignList tempGifts = new CampaignList();
// if (mUniqueCampaignList != null && mUniqueCampaignList.get("gifts_for_you") != null && mUniqueCampaignList.get("gifts_for_you").size() > 0) {
......
......@@ -3,6 +3,7 @@ package ly.warp.sdk.utils.managers;
import java.util.HashMap;
import ly.warp.sdk.io.models.ActiveDFYCouponEventModel;
import ly.warp.sdk.io.models.ContexualEventModel;
import ly.warp.sdk.io.models.CouponEventModel;
import ly.warp.sdk.io.models.LoyaltyContextualOfferModel;
import ly.warp.sdk.io.models.LoyaltyGiftsForYouOfferClickEvent;
......@@ -31,6 +32,7 @@ public class WarplyEventBusManager {
private QuestionnaireEventModel questionnaire;
private CouponEventModel coupon;
private ActiveDFYCouponEventModel activeCoupon;
private ContexualEventModel ccmsAdded;
public WarplyEventBusManager() {
......@@ -44,6 +46,10 @@ public class WarplyEventBusManager {
this.questionnaire = questionnaire;
}
public WarplyEventBusManager(ContexualEventModel ccmsAdded) {
this.ccmsAdded = ccmsAdded;
}
public WarplyEventBusManager(CouponEventModel coupon) {
this.coupon = coupon;
}
......@@ -157,4 +163,8 @@ public class WarplyEventBusManager {
public WarplyPacingEventModel getPacing() {
return pacing;
}
public ContexualEventModel getCcmsAdded() {
return ccmsAdded;
}
}
......