Panagiotis Triantafyllou

fixes

...@@ -3,7 +3,6 @@ package ly.warp.sdk.activities; ...@@ -3,7 +3,6 @@ package ly.warp.sdk.activities;
3 import android.app.Activity; 3 import android.app.Activity;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 -import android.text.TextUtils;
7 import android.util.Log; 6 import android.util.Log;
8 import android.view.View; 7 import android.view.View;
9 import android.widget.ImageView; 8 import android.widget.ImageView;
...@@ -14,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; ...@@ -14,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
14 import androidx.recyclerview.widget.RecyclerView; 13 import androidx.recyclerview.widget.RecyclerView;
15 14
16 import org.greenrobot.eventbus.EventBus; 15 import org.greenrobot.eventbus.EventBus;
16 +import org.greenrobot.eventbus.Subscribe;
17 import org.json.JSONObject; 17 import org.json.JSONObject;
18 18
19 import java.io.Serializable; 19 import java.io.Serializable;
...@@ -102,6 +102,18 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene ...@@ -102,6 +102,18 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
102 } 102 }
103 103
104 @Override 104 @Override
105 + protected void onStart() {
106 + super.onStart();
107 + EventBus.getDefault().register(this);
108 + }
109 +
110 + @Override
111 + protected void onStop() {
112 + super.onStop();
113 + EventBus.getDefault().unregister(this);
114 + }
115 +
116 + @Override
105 public void onClick(View view) { 117 public void onClick(View view) {
106 if (view.getId() == R.id.iv_list_close) { 118 if (view.getId() == R.id.iv_list_close) {
107 onBackPressed(); 119 onBackPressed();
...@@ -113,6 +125,90 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene ...@@ -113,6 +125,90 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
113 } 125 }
114 } 126 }
115 127
128 + @Subscribe()
129 + public void onMessageEvent(WarplyEventBusManager event) {
130 + if (event.getCcmsAdded() != null) {
131 + filterItems();
132 +
133 + if (WarplyManagerHelper.getSeasonalList() != null && WarplyManagerHelper.getSeasonalList().size() > 0) {
134 + mHashSetSeasonalList.addAll(WarplyManagerHelper.getSeasonalList());
135 + mSeasonalList.clear();
136 + mSeasonalList.addAll(mHashSetSeasonalList);
137 + }
138 +
139 + mergeDatasets(
140 + mValuesList,
141 + mSeasonalList
142 + );
143 +
144 + runOnUiThread(() -> {
145 + if (mData != null && mData.size() > 0) {
146 + mAdapterMergedGifts = new MergedGiftsAdapter(GiftsForYouActivity.this, mData);
147 + mRecyclerMergedGifts.setAdapter(mAdapterMergedGifts);
148 + mAdapterMergedGifts.getPositionClicks()
149 + .doOnNext(dataItem -> {
150 + if (dataItem.getDataType() == 1) {
151 + EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltyGiftsForYouOfferClickEvent()));
152 +
153 + if (dataItem.getCampaign().getType().equals("coupon")) {
154 + try {
155 + JSONObject campaignSettings = WarpJSONParser.getJSONFromString(dataItem.getCampaign().getCampaignTypeSettings());
156 + if (campaignSettings != null) {
157 + if (campaignSettings.has("couponset")) {
158 + String cpnUuid = campaignSettings.optString("couponset");
159 + for (Couponset cpns : WarplyManagerHelper.getCouponsets()) {
160 + if (cpns.getUuid().equals(cpnUuid)) {
161 + Intent intent = new Intent(GiftsForYouActivity.this, CouponsetInfoActivity.class);
162 + intent.putExtra("couponset", (Serializable) cpns);
163 + startActivity(intent);
164 + break;
165 + }
166 + }
167 + } else {
168 + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
169 + }
170 + }
171 + } catch (Exception exception) {
172 + exception.printStackTrace();
173 + }
174 +
175 + return;
176 + }
177 +
178 + try {
179 + JSONObject extraFields = WarpJSONParser.getJSONFromString(dataItem.getCampaign().getExtraFields());
180 + if (extraFields != null) {
181 + if (extraFields.has("ccms_offer") && extraFields.optString("ccms_offer").equals("true")) {
182 + for (LoyaltyContextualOfferModel ccms : WarplyManagerHelper.getCCMSLoyaltyCampaigns()) {
183 + if (ccms.getLoyaltyCampaignId().equals(dataItem.getCampaign().getSessionUUID())) {
184 + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCcmsUrl(dataItem.getCampaign(), ccms)));
185 + break;
186 + }
187 + }
188 + } else {
189 + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
190 + }
191 + }
192 + } catch (Exception exception) {
193 + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
194 + }
195 + } else if (dataItem.getDataType() == 2) {
196 + LoyaltyGiftsForYouOfferClickEvent seasonalCLick = new LoyaltyGiftsForYouOfferClickEvent();
197 + seasonalCLick.setTitle(dataItem.getSeasonalList().getTitle());
198 + seasonalCLick.setLoyaltyPackageId(dataItem.getSeasonalList().getLoyaltyPackageId());
199 + seasonalCLick.setImageUrl(dataItem.getSeasonalList().getImageUrl());
200 + EventBus.getDefault().post(new WarplyEventBusManager(seasonalCLick));
201 + }
202 + })
203 + .doOnError(error -> {
204 + })
205 + .subscribe();
206 + mAdapterMergedGifts.notifyDataSetChanged();
207 + }
208 + });
209 + }
210 + }
211 +
116 // =========================================================== 212 // ===========================================================
117 // Methods 213 // Methods
118 // =========================================================== 214 // ===========================================================
...@@ -190,6 +286,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene ...@@ -190,6 +286,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
190 } 286 }
191 287
192 private void mergeDatasets(ArrayList<Campaign> campaignList, ArrayList<LoyaltyGiftsForYouPackage> seasonalList) { 288 private void mergeDatasets(ArrayList<Campaign> campaignList, ArrayList<LoyaltyGiftsForYouPackage> seasonalList) {
289 + mData.clear();
193 if (campaignList != null && campaignList.size() > 0) { 290 if (campaignList != null && campaignList.size() > 0) {
194 Log.v("GIFTS_FOR_YOU", String.valueOf(campaignList.size())); 291 Log.v("GIFTS_FOR_YOU", String.valueOf(campaignList.size()));
195 for (Campaign campaign : campaignList) { 292 for (Campaign campaign : campaignList) {
...@@ -214,6 +311,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene ...@@ -214,6 +311,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene
214 } 311 }
215 312
216 private void filterItems() { 313 private void filterItems() {
314 + mValuesList.clear();
217 ArrayList<Campaign> gfyList = new ArrayList<>(); 315 ArrayList<Campaign> gfyList = new ArrayList<>();
218 if (WarplyManagerHelper.getCampaignListAll() != null && WarplyManagerHelper.getCampaignListAll().size() > 0) { 316 if (WarplyManagerHelper.getCampaignListAll() != null && WarplyManagerHelper.getCampaignListAll().size() > 0) {
219 Log.v("Got L:{" + String.valueOf(WarplyManagerHelper.getCampaignListAll().size()) + "}", " LOYALTY campaigns"); 317 Log.v("Got L:{" + String.valueOf(WarplyManagerHelper.getCampaignListAll().size()) + "}", " LOYALTY campaigns");
......
...@@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; ...@@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
12 import androidx.recyclerview.widget.RecyclerView; 12 import androidx.recyclerview.widget.RecyclerView;
13 13
14 import org.greenrobot.eventbus.EventBus; 14 import org.greenrobot.eventbus.EventBus;
15 +import org.greenrobot.eventbus.Subscribe;
15 import org.json.JSONObject; 16 import org.json.JSONObject;
16 17
17 import java.util.ArrayList; 18 import java.util.ArrayList;
...@@ -80,6 +81,18 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener ...@@ -80,6 +81,18 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener
80 } 81 }
81 82
82 @Override 83 @Override
84 + protected void onStart() {
85 + super.onStart();
86 + EventBus.getDefault().register(this);
87 + }
88 +
89 + @Override
90 + protected void onStop() {
91 + super.onStop();
92 + EventBus.getDefault().unregister(this);
93 + }
94 +
95 + @Override
83 public void onClick(View view) { 96 public void onClick(View view) {
84 if (view.getId() == R.id.iv_list_close) { 97 if (view.getId() == R.id.iv_list_close) {
85 onBackPressed(); 98 onBackPressed();
...@@ -91,6 +104,49 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener ...@@ -91,6 +104,49 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener
91 } 104 }
92 } 105 }
93 106
107 + @Subscribe()
108 + public void onMessageEvent(WarplyEventBusManager event) {
109 + if (event.getCcmsAdded() != null) {
110 + filterItems();
111 +
112 + runOnUiThread(() -> {
113 + if (mValuesList != null && mValuesList.size() > 0) {
114 + Log.v("MORE_FOR_YOU", String.valueOf(mValuesList.size()));
115 + mAdapterMore = new MoreCampaignAdapter(this, mValuesList);
116 + mRecyclerMore.setAdapter(mAdapterMore);
117 + mAdapterMore.getPositionClicks()
118 + .doOnNext(gift -> {
119 + EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltySDKFirebaseEventModel()));
120 +
121 + try {
122 + JSONObject extraFields = WarpJSONParser.getJSONFromString(gift.getExtraFields());
123 + if (extraFields != null) {
124 + if (extraFields.has("ccms_offer") && extraFields.optString("ccms_offer").equals("true")) {
125 + for (LoyaltyContextualOfferModel ccms : WarplyManagerHelper.getCCMSLoyaltyCampaigns()) {
126 + if (ccms.getLoyaltyCampaignId().equals(gift.getSessionUUID())) {
127 + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCcmsUrl(gift, ccms)));
128 + break;
129 + }
130 + }
131 + } else {
132 + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(gift)));
133 + }
134 + }
135 + } catch (Exception exception) {
136 + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(gift)));
137 + }
138 + })
139 + .doOnError(error -> {
140 + })
141 + .subscribe();
142 + mAdapterMore.notifyDataSetChanged();
143 + } else {
144 + mRecyclerMore.setVisibility(View.GONE);
145 + }
146 + });
147 + }
148 + }
149 +
94 // =========================================================== 150 // ===========================================================
95 // Methods 151 // Methods
96 // =========================================================== 152 // ===========================================================
...@@ -138,6 +194,7 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener ...@@ -138,6 +194,7 @@ public class MoreForYouActivity extends Activity implements View.OnClickListener
138 } 194 }
139 195
140 private void filterItems() { 196 private void filterItems() {
197 + mValuesList.clear();
141 ArrayList<Campaign> gfyList = new ArrayList<>(); 198 ArrayList<Campaign> gfyList = new ArrayList<>();
142 if (WarplyManagerHelper.getCampaignListAll() != null && WarplyManagerHelper.getCampaignListAll().size() > 0) { 199 if (WarplyManagerHelper.getCampaignListAll() != null && WarplyManagerHelper.getCampaignListAll().size() > 0) {
143 Log.v("Got L:{" + String.valueOf(WarplyManagerHelper.getCampaignListAll().size()) + "}", " LOYALTY campaigns"); 200 Log.v("Got L:{" + String.valueOf(WarplyManagerHelper.getCampaignListAll().size()) + "}", " LOYALTY campaigns");
......
1 +/*
2 + * Copyright 2010-2013 Warply Ltd. All rights reserved.
3 + *
4 + * Redistribution and use in source and binary forms, without modification, are
5 + * permitted provided that the following conditions are met:
6 + *
7 + * 1. Redistributions of source code must retain the above copyright notice,
8 + * this list of conditions and the following disclaimer.
9 + *
10 + * 2. Redistributions in binary form must reproduce the above copyright notice,
11 + * this list of conditions and the following disclaimer in the documentation
12 + * and/or other materials provided with the distribution.
13 + *
14 + * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
15 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 + * EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20 + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 + */
25 +
26 +package ly.warp.sdk.io.models;
27 +
28 +
29 +/**
30 + * Created by Panagiotis Triantafyllou on 12-July-22.
31 + */
32 +
33 +public class ContexualEventModel {
34 + private boolean success;
35 +
36 + public ContexualEventModel() {
37 + this.success = true;
38 + }
39 +
40 + public boolean isSuccess() {
41 + return success;
42 + }
43 +
44 + public void setSuccess(boolean success) {
45 + this.success = success;
46 + }
47 +}
...@@ -31,6 +31,7 @@ import android.util.Log; ...@@ -31,6 +31,7 @@ import android.util.Log;
31 31
32 import androidx.appcompat.app.AlertDialog; 32 import androidx.appcompat.app.AlertDialog;
33 33
34 +import org.greenrobot.eventbus.EventBus;
34 import org.json.JSONObject; 35 import org.json.JSONObject;
35 36
36 import java.util.ArrayList; 37 import java.util.ArrayList;
...@@ -45,6 +46,7 @@ import ly.warp.sdk.io.models.ActiveDFYCouponModel; ...@@ -45,6 +46,7 @@ import ly.warp.sdk.io.models.ActiveDFYCouponModel;
45 import ly.warp.sdk.io.models.Campaign; 46 import ly.warp.sdk.io.models.Campaign;
46 import ly.warp.sdk.io.models.CampaignList; 47 import ly.warp.sdk.io.models.CampaignList;
47 import ly.warp.sdk.io.models.Consumer; 48 import ly.warp.sdk.io.models.Consumer;
49 +import ly.warp.sdk.io.models.ContexualEventModel;
48 import ly.warp.sdk.io.models.Coupon; 50 import ly.warp.sdk.io.models.Coupon;
49 import ly.warp.sdk.io.models.CouponList; 51 import ly.warp.sdk.io.models.CouponList;
50 import ly.warp.sdk.io.models.CouponsetsList; 52 import ly.warp.sdk.io.models.CouponsetsList;
...@@ -55,6 +57,7 @@ import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage; ...@@ -55,6 +57,7 @@ import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage;
55 import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest; 57 import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest;
56 import ly.warp.sdk.io.request.CosmoteSharingRequest; 58 import ly.warp.sdk.io.request.CosmoteSharingRequest;
57 import ly.warp.sdk.io.request.WarplyIntegrationRequest; 59 import ly.warp.sdk.io.request.WarplyIntegrationRequest;
60 +import ly.warp.sdk.utils.managers.WarplyEventBusManager;
58 import ly.warp.sdk.utils.managers.WarplyManager; 61 import ly.warp.sdk.utils.managers.WarplyManager;
59 62
60 /** 63 /**
...@@ -410,6 +413,9 @@ public class WarplyManagerHelper { ...@@ -410,6 +413,9 @@ public class WarplyManagerHelper {
410 mCCMSList.clear(); 413 mCCMSList.clear();
411 mCCMSList.addAll(list); 414 mCCMSList.addAll(list);
412 415
416 + ContexualEventModel ccmsAdded = new ContexualEventModel();
417 + EventBus.getDefault().post(new WarplyEventBusManager(ccmsAdded));
418 +
413 // if (list == null || list.size() == 0) { 419 // if (list == null || list.size() == 0) {
414 // CampaignList tempGifts = new CampaignList(); 420 // CampaignList tempGifts = new CampaignList();
415 // if (mUniqueCampaignList != null && mUniqueCampaignList.get("gifts_for_you") != null && mUniqueCampaignList.get("gifts_for_you").size() > 0) { 421 // 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; ...@@ -3,6 +3,7 @@ package ly.warp.sdk.utils.managers;
3 import java.util.HashMap; 3 import java.util.HashMap;
4 4
5 import ly.warp.sdk.io.models.ActiveDFYCouponEventModel; 5 import ly.warp.sdk.io.models.ActiveDFYCouponEventModel;
6 +import ly.warp.sdk.io.models.ContexualEventModel;
6 import ly.warp.sdk.io.models.CouponEventModel; 7 import ly.warp.sdk.io.models.CouponEventModel;
7 import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; 8 import ly.warp.sdk.io.models.LoyaltyContextualOfferModel;
8 import ly.warp.sdk.io.models.LoyaltyGiftsForYouOfferClickEvent; 9 import ly.warp.sdk.io.models.LoyaltyGiftsForYouOfferClickEvent;
...@@ -31,6 +32,7 @@ public class WarplyEventBusManager { ...@@ -31,6 +32,7 @@ public class WarplyEventBusManager {
31 private QuestionnaireEventModel questionnaire; 32 private QuestionnaireEventModel questionnaire;
32 private CouponEventModel coupon; 33 private CouponEventModel coupon;
33 private ActiveDFYCouponEventModel activeCoupon; 34 private ActiveDFYCouponEventModel activeCoupon;
35 + private ContexualEventModel ccmsAdded;
34 36
35 public WarplyEventBusManager() { 37 public WarplyEventBusManager() {
36 38
...@@ -44,6 +46,10 @@ public class WarplyEventBusManager { ...@@ -44,6 +46,10 @@ public class WarplyEventBusManager {
44 this.questionnaire = questionnaire; 46 this.questionnaire = questionnaire;
45 } 47 }
46 48
49 + public WarplyEventBusManager(ContexualEventModel ccmsAdded) {
50 + this.ccmsAdded = ccmsAdded;
51 + }
52 +
47 public WarplyEventBusManager(CouponEventModel coupon) { 53 public WarplyEventBusManager(CouponEventModel coupon) {
48 this.coupon = coupon; 54 this.coupon = coupon;
49 } 55 }
...@@ -157,4 +163,8 @@ public class WarplyEventBusManager { ...@@ -157,4 +163,8 @@ public class WarplyEventBusManager {
157 public WarplyPacingEventModel getPacing() { 163 public WarplyPacingEventModel getPacing() {
158 return pacing; 164 return pacing;
159 } 165 }
166 +
167 + public ContexualEventModel getCcmsAdded() {
168 + return ccmsAdded;
169 + }
160 } 170 }
......