Panagiotis Triantafyllou

couponsets and merchants implementation

1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="AndroidProjectSystem">
4 + <option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
5 + </component>
6 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="CompilerConfiguration">
4 + <bytecodeTargetLevel target="21" />
5 + </component>
6 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="deploymentTargetSelector">
4 + <selectionStates>
5 + <SelectionState runConfigName="app">
6 + <option name="selectionMode" value="DROPDOWN" />
7 + </SelectionState>
8 + </selectionStates>
9 + </component>
10 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="GradleMigrationSettings" migrationVersion="1" />
4 + <component name="GradleSettings">
5 + <option name="linkedExternalProjectsSettings">
6 + <GradleProjectSettings>
7 + <option name="testRunner" value="CHOOSE_PER_TEST" />
8 + <option name="externalProjectPath" value="$PROJECT_DIR$" />
9 + <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
10 + <option name="modules">
11 + <set>
12 + <option value="$PROJECT_DIR$" />
13 + <option value="$PROJECT_DIR$/app" />
14 + <option value="$PROJECT_DIR$/warply_android_sdk" />
15 + </set>
16 + </option>
17 + </GradleProjectSettings>
18 + </option>
19 + </component>
20 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="ProjectMigrations">
4 + <option name="MigrateToGradleLocalJavaHome">
5 + <set>
6 + <option value="$PROJECT_DIR$" />
7 + </set>
8 + </option>
9 + </component>
10 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<project version="4">
2 + <component name="ExternalStorageConfigurationManager" enabled="true" />
3 + <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
4 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="RunConfigurationProducerService">
4 + <option name="ignoredProducers">
5 + <set>
6 + <option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
7 + <option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
8 + <option value="com.intellij.execution.junit.PatternConfigurationProducer" />
9 + <option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
10 + <option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
11 + <option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
12 + <option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
13 + <option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
14 + </set>
15 + </option>
16 + </component>
17 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="VcsDirectoryMappings">
4 + <mapping directory="" vcs="Git" />
5 + </component>
6 +</project>
...\ No newline at end of file ...\ No newline at end of file
...@@ -26,6 +26,7 @@ import ly.warp.sdk.io.adapters.BannerAdapter; ...@@ -26,6 +26,7 @@ import ly.warp.sdk.io.adapters.BannerAdapter;
26 import ly.warp.sdk.io.adapters.OfferAdapter; 26 import ly.warp.sdk.io.adapters.OfferAdapter;
27 import ly.warp.sdk.io.callbacks.CallbackReceiver; 27 import ly.warp.sdk.io.callbacks.CallbackReceiver;
28 import ly.warp.sdk.io.models.BannerItem; 28 import ly.warp.sdk.io.models.BannerItem;
29 +import ly.warp.sdk.io.models.Couponset;
29 import ly.warp.sdk.io.models.DummyDataProvider; 30 import ly.warp.sdk.io.models.DummyDataProvider;
30 import ly.warp.sdk.io.models.OfferCategory; 31 import ly.warp.sdk.io.models.OfferCategory;
31 import ly.warp.sdk.io.models.OfferItem; 32 import ly.warp.sdk.io.models.OfferItem;
...@@ -100,6 +101,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Offe ...@@ -100,6 +101,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Offe
100 initViews(); 101 initViews();
101 mPbLoading.setVisibility(View.VISIBLE); 102 mPbLoading.setVisibility(View.VISIBLE);
102 WarplyManager.getCampaigns(mCampaignsCallback); 103 WarplyManager.getCampaigns(mCampaignsCallback);
104 + WarplyManager.getCouponsets(mCouponsetsCallback);
103 105
104 // Setup all category sections 106 // Setup all category sections
105 // setupTopOffersSection(); 107 // setupTopOffersSection();
...@@ -431,7 +433,6 @@ public class HomeActivity extends Activity implements View.OnClickListener, Offe ...@@ -431,7 +433,6 @@ public class HomeActivity extends Activity implements View.OnClickListener, Offe
431 }); 433 });
432 mBannerAdapter.setOnBannerContentClickListener(article -> { 434 mBannerAdapter.setOnBannerContentClickListener(article -> {
433 //TODO: click article 435 //TODO: click article
434 - String s = "";
435 }); 436 });
436 437
437 // Set the number of pages to preload for adjacent items 438 // Set the number of pages to preload for adjacent items
...@@ -519,4 +520,16 @@ public class HomeActivity extends Activity implements View.OnClickListener, Offe ...@@ -519,4 +520,16 @@ public class HomeActivity extends Activity implements View.OnClickListener, Offe
519 mViewPager.setVisibility(View.GONE); 520 mViewPager.setVisibility(View.GONE);
520 } 521 }
521 }; 522 };
523 +
524 + private CallbackReceiver<ArrayList<Couponset>> mCouponsetsCallback = new CallbackReceiver<ArrayList<Couponset>>() {
525 + @Override
526 + public void onSuccess(ArrayList<Couponset> result) {
527 + mPbLoading.setVisibility(View.GONE);
528 + }
529 +
530 + @Override
531 + public void onFailure(int errorCode) {
532 + mPbLoading.setVisibility(View.GONE);
533 + }
534 + };
522 } 535 }
......
...@@ -80,6 +80,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -80,6 +80,12 @@ public class Couponset implements Parcelable, Serializable {
80 private static final String FINAL_PRICE = "final_price"; 80 private static final String FINAL_PRICE = "final_price";
81 private static final String DISCOUNT_TYPE = "discount_type"; 81 private static final String DISCOUNT_TYPE = "discount_type";
82 private static final String EXTRA_FIELDS = "extra_fields"; 82 private static final String EXTRA_FIELDS = "extra_fields";
83 + private static final String IS_NEW = "is_new";
84 + private static final String PROMOTED = "promoted";
85 + private static final String PERSONALIZED = "personalized";
86 + private static final String LOCKED = "locked";
87 + private static final String UNLOCK_ACTION = "unlock_action";
88 + private static final String UNLOCK_MESSAGE = "unlock_message";
83 89
84 90
85 /* Member variables of the Campaign object */ 91 /* Member variables of the Campaign object */
...@@ -115,6 +121,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -115,6 +121,12 @@ public class Couponset implements Parcelable, Serializable {
115 private Date endDate = new Date(); 121 private Date endDate = new Date();
116 private String couponsetType = ""; 122 private String couponsetType = "";
117 private JSONObject extraFields = new JSONObject(); 123 private JSONObject extraFields = new JSONObject();
124 + private boolean isNew = false;
125 + private boolean promoted = false;
126 + private boolean personalized = false;
127 + private boolean locked = false;
128 + private String unlockAction = "";
129 + private String unlockMessage = "";
118 130
119 public Couponset() { 131 public Couponset() {
120 this.uuid = ""; 132 this.uuid = "";
...@@ -146,6 +158,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -146,6 +158,12 @@ public class Couponset implements Parcelable, Serializable {
146 this.discount_type = ""; 158 this.discount_type = "";
147 this.final_price = 0.0d; 159 this.final_price = 0.0d;
148 this.extraFields = new JSONObject(); 160 this.extraFields = new JSONObject();
161 + this.isNew = false;
162 + this.promoted = false;
163 + this.personalized = false;
164 + this.locked = false;
165 + this.unlockAction = "";
166 + this.unlockMessage = "";
149 } 167 }
150 168
151 public Couponset(boolean isUniversal) { 169 public Couponset(boolean isUniversal) {
...@@ -168,6 +186,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -168,6 +186,12 @@ public class Couponset implements Parcelable, Serializable {
168 this.innerText = ""; 186 this.innerText = "";
169 this.final_price = 0.0d; 187 this.final_price = 0.0d;
170 this.extraFields = new JSONObject(); 188 this.extraFields = new JSONObject();
189 + this.isNew = false;
190 + this.promoted = false;
191 + this.personalized = false;
192 + this.locked = false;
193 + this.unlockAction = "";
194 + this.unlockMessage = "";
171 } 195 }
172 196
173 /** 197 /**
...@@ -204,6 +228,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -204,6 +228,12 @@ public class Couponset implements Parcelable, Serializable {
204 this.active = json.optBoolean(ACTIVE); 228 this.active = json.optBoolean(ACTIVE);
205 this.visible = json.optBoolean(VISIBLE); 229 this.visible = json.optBoolean(VISIBLE);
206 this.buyable = json.optBoolean(BUYABLE); 230 this.buyable = json.optBoolean(BUYABLE);
231 + this.isNew = json.optBoolean(IS_NEW);
232 + this.promoted = json.optBoolean(PROMOTED);
233 + this.personalized = json.optBoolean(PERSONALIZED);
234 + this.locked = json.optBoolean(LOCKED);
235 + this.unlockAction = json.optString(UNLOCK_ACTION);
236 + this.unlockMessage = json.optString(UNLOCK_MESSAGE);
207 this.user_generated = json.optBoolean(USER_GENERATED); 237 this.user_generated = json.optBoolean(USER_GENERATED);
208 this.limits = json.optJSONObject(LIMITS); 238 this.limits = json.optJSONObject(LIMITS);
209 this.points = json.optInt(POINTS); 239 this.points = json.optInt(POINTS);
...@@ -247,6 +277,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -247,6 +277,12 @@ public class Couponset implements Parcelable, Serializable {
247 } catch (JSONException e) { 277 } catch (JSONException e) {
248 e.printStackTrace(); 278 e.printStackTrace();
249 } 279 }
280 + this.isNew = json.optBoolean(IS_NEW);
281 + this.promoted = json.optBoolean(PROMOTED);
282 + this.personalized = json.optBoolean(PERSONALIZED);
283 + this.locked = json.optBoolean(LOCKED);
284 + this.unlockAction = json.optString(UNLOCK_ACTION);
285 + this.unlockMessage = json.optString(UNLOCK_MESSAGE);
250 this.active = json.optBoolean(ACTIVE); 286 this.active = json.optBoolean(ACTIVE);
251 this.buyable = json.optBoolean(BUYABLE); 287 this.buyable = json.optBoolean(BUYABLE);
252 this.name = json.optString(NAME); 288 this.name = json.optString(NAME);
...@@ -322,6 +358,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -322,6 +358,12 @@ public class Couponset implements Parcelable, Serializable {
322 this.innerText = source.readString(); 358 this.innerText = source.readString();
323 this.discount_type = source.readString(); 359 this.discount_type = source.readString();
324 this.final_price = source.readDouble(); 360 this.final_price = source.readDouble();
361 + this.isNew = source.readByte() != 0;
362 + this.promoted = source.readByte() != 0;
363 + this.personalized = source.readByte() != 0;
364 + this.locked = source.readByte() != 0;
365 + this.unlockAction = source.readString();
366 + this.unlockMessage = source.readString();
325 } 367 }
326 368
327 @Override 369 @Override
...@@ -352,6 +394,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -352,6 +394,12 @@ public class Couponset implements Parcelable, Serializable {
352 dest.writeString(this.innerText); 394 dest.writeString(this.innerText);
353 dest.writeString(this.discount_type); 395 dest.writeString(this.discount_type);
354 dest.writeDouble(this.final_price); 396 dest.writeDouble(this.final_price);
397 + dest.writeByte((byte) (this.isNew ? 1 : 0));
398 + dest.writeByte((byte) (this.promoted ? 1 : 0));
399 + dest.writeByte((byte) (this.personalized ? 1 : 0));
400 + dest.writeByte((byte) (this.locked ? 1 : 0));
401 + dest.writeString(this.unlockAction);
402 + dest.writeString(this.unlockMessage);
355 } 403 }
356 404
357 /** 405 /**
...@@ -391,6 +439,12 @@ public class Couponset implements Parcelable, Serializable { ...@@ -391,6 +439,12 @@ public class Couponset implements Parcelable, Serializable {
391 jObj.putOpt(DISCOUNT_TYPE, this.discount_type); 439 jObj.putOpt(DISCOUNT_TYPE, this.discount_type);
392 jObj.putOpt(FINAL_PRICE, this.final_price); 440 jObj.putOpt(FINAL_PRICE, this.final_price);
393 jObj.putOpt(EXTRA_FIELDS, this.extraFields); 441 jObj.putOpt(EXTRA_FIELDS, this.extraFields);
442 + jObj.putOpt(IS_NEW, this.isNew);
443 + jObj.putOpt(PROMOTED, this.promoted);
444 + jObj.putOpt(PERSONALIZED, this.personalized);
445 + jObj.putOpt(LOCKED, this.locked);
446 + jObj.putOpt(UNLOCK_ACTION, this.unlockAction);
447 + jObj.putOpt(UNLOCK_MESSAGE, this.unlockMessage);
394 } catch (JSONException e) { 448 } catch (JSONException e) {
395 if (WarpConstants.DEBUG) { 449 if (WarpConstants.DEBUG) {
396 e.printStackTrace(); 450 e.printStackTrace();
...@@ -682,6 +736,55 @@ public class Couponset implements Parcelable, Serializable { ...@@ -682,6 +736,55 @@ public class Couponset implements Parcelable, Serializable {
682 return img_preview; 736 return img_preview;
683 } 737 }
684 738
739 +
740 + public boolean isNew() {
741 + return isNew;
742 + }
743 +
744 + public void setNew(boolean aNew) {
745 + isNew = aNew;
746 + }
747 +
748 + public boolean isPromoted() {
749 + return promoted;
750 + }
751 +
752 + public void setPromoted(boolean promoted) {
753 + this.promoted = promoted;
754 + }
755 +
756 + public boolean isPersonalized() {
757 + return personalized;
758 + }
759 +
760 + public void setPersonalized(boolean personalized) {
761 + this.personalized = personalized;
762 + }
763 +
764 + public boolean isLocked() {
765 + return locked;
766 + }
767 +
768 + public void setLocked(boolean locked) {
769 + this.locked = locked;
770 + }
771 +
772 + public String getUnlockAction() {
773 + return unlockAction;
774 + }
775 +
776 + public void setUnlockAction(String unlockAction) {
777 + this.unlockAction = unlockAction;
778 + }
779 +
780 + public String getUnlockMessage() {
781 + return unlockMessage;
782 + }
783 +
784 + public void setUnlockMessage(String unlockMessage) {
785 + this.unlockMessage = unlockMessage;
786 + }
787 +
685 @Override 788 @Override
686 public int describeContents() { 789 public int describeContents() {
687 return 0; 790 return 0;
......
...@@ -66,7 +66,9 @@ public class NewCampaign implements Parcelable, Serializable { ...@@ -66,7 +66,9 @@ public class NewCampaign implements Parcelable, Serializable {
66 private static final String SETTINGS = "settings"; 66 private static final String SETTINGS = "settings";
67 private static final String AUDIENCE = "audience"; 67 private static final String AUDIENCE = "audience";
68 private static final String IS_NEW = "is_new"; 68 private static final String IS_NEW = "is_new";
69 - private static final String BANNER_IMAGE = "Banner_img"; 69 + private static final String BANNER_IMAGE = "banner_img";
70 + private static final String BANNER_IMAGE_MOBILE = "banner_img_mobile";
71 + private static final String CAMPAIGN_URL = "campaign_url";
70 private static final String BANNER_TITLE = "Banner_title"; 72 private static final String BANNER_TITLE = "Banner_title";
71 73
72 /* Member variables of the Campaign object */ 74 /* Member variables of the Campaign object */
...@@ -92,6 +94,8 @@ public class NewCampaign implements Parcelable, Serializable { ...@@ -92,6 +94,8 @@ public class NewCampaign implements Parcelable, Serializable {
92 private final String communicationCategory; 94 private final String communicationCategory;
93 private boolean isNew = false; 95 private boolean isNew = false;
94 private String bannerImage = ""; 96 private String bannerImage = "";
97 + private String bannerImageMobile = "";
98 + private String campaignUrl = "";
95 private String bannerTitle = ""; 99 private String bannerTitle = "";
96 private boolean showExpiration = false; 100 private boolean showExpiration = false;
97 private String couponImg = ""; 101 private String couponImg = "";
...@@ -139,6 +143,12 @@ public class NewCampaign implements Parcelable, Serializable { ...@@ -139,6 +143,12 @@ public class NewCampaign implements Parcelable, Serializable {
139 if (this.extraFields.has(BANNER_IMAGE)) { 143 if (this.extraFields.has(BANNER_IMAGE)) {
140 this.bannerImage = this.extraFields.optString(BANNER_IMAGE); 144 this.bannerImage = this.extraFields.optString(BANNER_IMAGE);
141 } 145 }
146 + if (this.extraFields.has(BANNER_IMAGE_MOBILE)) {
147 + this.bannerImageMobile = this.extraFields.optString(BANNER_IMAGE_MOBILE);
148 + }
149 + if (this.extraFields.has(CAMPAIGN_URL)) {
150 + this.campaignUrl = this.extraFields.optString(CAMPAIGN_URL);
151 + }
142 if (this.extraFields.has(BANNER_TITLE)) { 152 if (this.extraFields.has(BANNER_TITLE)) {
143 this.bannerTitle = this.extraFields.optString(BANNER_TITLE); 153 this.bannerTitle = this.extraFields.optString(BANNER_TITLE);
144 } 154 }
...@@ -183,6 +193,8 @@ public class NewCampaign implements Parcelable, Serializable { ...@@ -183,6 +193,8 @@ public class NewCampaign implements Parcelable, Serializable {
183 this.category = source.readString(); 193 this.category = source.readString();
184 this.campaignType = source.readString(); 194 this.campaignType = source.readString();
185 this.bannerImage = source.readString(); 195 this.bannerImage = source.readString();
196 + this.bannerImageMobile = source.readString();
197 + this.campaignUrl = source.readString();
186 this.bannerTitle = source.readString(); 198 this.bannerTitle = source.readString();
187 } 199 }
188 200
...@@ -210,6 +222,8 @@ public class NewCampaign implements Parcelable, Serializable { ...@@ -210,6 +222,8 @@ public class NewCampaign implements Parcelable, Serializable {
210 dest.writeString(this.campaignType); 222 dest.writeString(this.campaignType);
211 dest.writeString(this.communicationUUID); 223 dest.writeString(this.communicationUUID);
212 dest.writeString(this.bannerImage); 224 dest.writeString(this.bannerImage);
225 + dest.writeString(this.bannerImageMobile);
226 + dest.writeString(this.campaignUrl);
213 dest.writeString(this.bannerTitle); 227 dest.writeString(this.bannerTitle);
214 } 228 }
215 229
...@@ -420,6 +434,22 @@ public class NewCampaign implements Parcelable, Serializable { ...@@ -420,6 +434,22 @@ public class NewCampaign implements Parcelable, Serializable {
420 this.filter = filter; 434 this.filter = filter;
421 } 435 }
422 436
437 + public String getBannerImageMobile() {
438 + return bannerImageMobile;
439 + }
440 +
441 + public void setBannerImageMobile(String bannerImageMobile) {
442 + this.bannerImageMobile = bannerImageMobile;
443 + }
444 +
445 + public String getCampaignUrl() {
446 + return campaignUrl;
447 + }
448 +
449 + public void setCampaignUrl(String campaignUrl) {
450 + this.campaignUrl = campaignUrl;
451 + }
452 +
423 @Override 453 @Override
424 public int describeContents() { 454 public int describeContents() {
425 return 0; 455 return 0;
......
...@@ -118,6 +118,28 @@ public interface ApiService { ...@@ -118,6 +118,28 @@ public interface ApiService {
118 @Header(WarpConstants.HEADER_SIGNATURE) String signature, 118 @Header(WarpConstants.HEADER_SIGNATURE) String signature,
119 @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); 119 @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
120 120
121 + @Headers("Content-Type: application/json")
122 + @POST("/api/mobile/v2/{appUuid}/context/")
123 + Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid,
124 + @Body RequestBody request,
125 + @Header(WarpConstants.HEADER_DATE) String timeStamp,
126 + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
127 + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
128 + @Header(WarpConstants.HEADER_CHANNEL) String channel,
129 + @Header(WarpConstants.HEADER_WEB_ID) String webId,
130 + @Header(WarpConstants.HEADER_SIGNATURE) String signature);
131 +
132 + @Headers("Content-Type: application/json")
133 + @POST("/api/mobile/v2/{appUuid}/context/")
134 + Call<ResponseBody> getMerchants(@Path("appUuid") String appUuid,
135 + @Body RequestBody request,
136 + @Header(WarpConstants.HEADER_DATE) String timeStamp,
137 + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
138 + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
139 + @Header(WarpConstants.HEADER_CHANNEL) String channel,
140 + @Header(WarpConstants.HEADER_WEB_ID) String webId,
141 + @Header(WarpConstants.HEADER_SIGNATURE) String signature);
142 +
121 // =========================================================== 143 // ===========================================================
122 // Getter & Setter 144 // Getter & Setter
123 // =========================================================== 145 // ===========================================================
......
...@@ -60,6 +60,8 @@ import ly.warp.sdk.io.models.Campaign; ...@@ -60,6 +60,8 @@ import ly.warp.sdk.io.models.Campaign;
60 import ly.warp.sdk.io.models.Content; 60 import ly.warp.sdk.io.models.Content;
61 import ly.warp.sdk.io.models.Coupon; 61 import ly.warp.sdk.io.models.Coupon;
62 import ly.warp.sdk.io.models.CouponList; 62 import ly.warp.sdk.io.models.CouponList;
63 +import ly.warp.sdk.io.models.Couponset;
64 +import ly.warp.sdk.io.models.Merchant;
63 import ly.warp.sdk.io.models.NewCampaign; 65 import ly.warp.sdk.io.models.NewCampaign;
64 import ly.warp.sdk.io.models.RedeemedSMHistoryModel; 66 import ly.warp.sdk.io.models.RedeemedSMHistoryModel;
65 import ly.warp.sdk.io.request.WarplyRefreshTokenRequest; 67 import ly.warp.sdk.io.request.WarplyRefreshTokenRequest;
...@@ -385,6 +387,192 @@ public class WarplyManager { ...@@ -385,6 +387,192 @@ public class WarplyManager {
385 }, executorService); 387 }, executorService);
386 } 388 }
387 389
390 + public static void getCouponsets(final CallbackReceiver<ArrayList<Couponset>> receiver) {
391 + WarpUtils.log("************* WARPLY Couponsets Request ********************");
392 + WarpUtils.log("[WARP Trace] WARPLY Couponsets Request is active");
393 + WarpUtils.log("**************************************************");
394 +
395 + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
396 + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
397 +
398 + ListenableFuture<ArrayList<Couponset>> futureCouponsets = getCouponsetsRetro(service);
399 + ListenableFuture<ArrayList<Merchant>> futureMerchants = getMerchantsRetro(service);
400 +
401 + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCouponsets, futureMerchants);
402 + ListenableFuture<ArrayList<Couponset>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> {
403 + ArrayList<Couponset> resultCoupons = (ArrayList<Couponset>) results.get(0);
404 + return executorService.submit(() -> resultCoupons/*createCouponSetsSection(resultCoupons)*/);
405 + }, executorService);
406 +
407 + Futures.addCallback(mergedResultFuture, new FutureCallback<ArrayList<Couponset>>() {
408 + @Override
409 + public void onSuccess(ArrayList<Couponset> mergedResult) {
410 + executorService.shutdownNow();
411 + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult));
412 + }
413 +
414 + @Override
415 + public void onFailure(Throwable throwable) {
416 + executorService.shutdownNow();
417 + new Handler(Looper.getMainLooper()).post(() -> receiver.onFailure(2));
418 + }
419 + }, executorService);
420 + }
421 +
422 + private static ListenableFuture<ArrayList<Couponset>> getCouponsetsRetro(ApiService service/*, Callback<ResponseBody> callback*/) {
423 + SettableFuture<ArrayList<Couponset>> future = SettableFuture.create();
424 +
425 + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
426 + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
427 + String webId = WarpUtils.getWebId(Warply.getWarplyContext());
428 +
429 + Map<String, Object> jsonParamsCouponsets = new ArrayMap<>();
430 + Map<String, Object> jsonParams = new ArrayMap<>();
431 + jsonParams.put("action", "retrieve_multilingual");
432 + jsonParams.put("active", true);
433 + jsonParams.put("visible", true);
434 + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
435 + jsonParamsCouponsets.put("coupon", jsonParams);
436 +
437 + RequestBody couponsetsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCouponsets)).toString());
438 + Call<ResponseBody> couponsetsCall = service.getCouponsets(
439 + WarplyProperty.getAppUuid(Warply.getWarplyContext()),
440 + couponsetsRequest,
441 + timeStamp,
442 + "android:" + Warply.getWarplyContext().getPackageName(),
443 + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
444 + "mobile",
445 + webId,
446 + WarpUtils.produceSignature(apiKey + timeStamp)
447 + );
448 + couponsetsCall.enqueue(new Callback<ResponseBody>() {
449 + @Override
450 + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
451 + if (response.code() == 200 && response.body() != null) {
452 + JSONObject jobjCouponsetsResponse = null;
453 + try {
454 + jobjCouponsetsResponse = new JSONObject(response.body().string());
455 + } catch (Exception e) {
456 + e.printStackTrace();
457 + }
458 + if (jobjCouponsetsResponse != null && jobjCouponsetsResponse.has("status") && jobjCouponsetsResponse.optString("status", "2").equals("1")) {
459 + JSONArray jCouponsetsBody = null;
460 + try {
461 + jCouponsetsBody = jobjCouponsetsResponse.optJSONObject("context").optJSONArray("MAPP_COUPON");
462 + } catch (Exception e) {
463 + e.printStackTrace();
464 + }
465 +
466 + if (jCouponsetsBody != null) {
467 + ArrayList<Couponset> mCouponsetList = new ArrayList<Couponset>();
468 + final ExecutorService executorCouponsets = Executors.newFixedThreadPool(1);
469 + JSONArray finalJCouponsetsBody = jCouponsetsBody;
470 + executorCouponsets.submit(() -> {
471 + for (int i = 0; i < finalJCouponsetsBody.length(); ++i) {
472 + Couponset tempCouponset = new Couponset(finalJCouponsetsBody.optJSONObject(i));
473 + mCouponsetList.add(tempCouponset);
474 + }
475 +
476 + executorCouponsets.shutdownNow();
477 + future.set(mCouponsetList);
478 + });
479 + }
480 + } else {
481 + future.set(new ArrayList<Couponset>());
482 + }
483 + } else if (String.valueOf(response.code()).startsWith("5")) {
484 + future.set(new ArrayList<Couponset>());
485 + } else {
486 +// future.set(new CouponsetsList());
487 + future.setException(new Throwable());
488 + }
489 + }
490 +
491 + @Override
492 + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
493 +// future.set(new CouponsetsList());
494 + future.setException(new Throwable());
495 + }
496 + });
497 + return future;
498 + }
499 +
500 + private static ListenableFuture<ArrayList<Merchant>> getMerchantsRetro(ApiService service/*, Callback<ResponseBody> callback*/) {
501 + SettableFuture<ArrayList<Merchant>> future = SettableFuture.create();
502 +
503 + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
504 + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
505 + String webId = WarpUtils.getWebId(Warply.getWarplyContext());
506 +
507 + Map<String, Object> jsonParamsMerchants = new ArrayMap<>();
508 + Map<String, Object> jsonParams = new ArrayMap<>();
509 + jsonParams.put("action", "retrieve_multilingual");
510 + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
511 + jsonParamsMerchants.put("shops", jsonParams);
512 +
513 + RequestBody couponsetsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsMerchants)).toString());
514 + Call<ResponseBody> merchantsCall = service.getMerchants(
515 + WarplyProperty.getAppUuid(Warply.getWarplyContext()),
516 + couponsetsRequest,
517 + timeStamp,
518 + "android:" + Warply.getWarplyContext().getPackageName(),
519 + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
520 + "mobile",
521 + webId,
522 + WarpUtils.produceSignature(apiKey + timeStamp)
523 + );
524 + merchantsCall.enqueue(new Callback<ResponseBody>() {
525 + @Override
526 + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
527 + if (response.code() == 200 && response.body() != null) {
528 + JSONObject jobjMerchantsResponse = null;
529 + try {
530 + jobjMerchantsResponse = new JSONObject(response.body().string());
531 + } catch (Exception e) {
532 + e.printStackTrace();
533 + }
534 + if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) {
535 + JSONArray jMerchantsBody = null;
536 + try {
537 + jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result");
538 + } catch (Exception e) {
539 + e.printStackTrace();
540 + }
541 +
542 + if (jMerchantsBody != null) {
543 + ArrayList<Merchant> mMerchantList = new ArrayList<Merchant>();
544 + final ExecutorService executorCouponsets = Executors.newFixedThreadPool(1);
545 + JSONArray finalJMerchantsBody = jMerchantsBody;
546 + executorCouponsets.submit(() -> {
547 + for (int i = 0; i < finalJMerchantsBody.length(); ++i) {
548 + Merchant tempCouponset = new Merchant(finalJMerchantsBody.optJSONObject(i));
549 + mMerchantList.add(tempCouponset);
550 + }
551 +
552 + executorCouponsets.shutdownNow();
553 + future.set(mMerchantList);
554 + });
555 + }
556 + } else {
557 + future.set(new ArrayList<Merchant>());
558 + }
559 + } else if (String.valueOf(response.code()).startsWith("5")) {
560 + future.set(new ArrayList<Merchant>());
561 + } else {
562 +// future.set(new CouponsetsList());
563 + future.setException(new Throwable());
564 + }
565 + }
566 +
567 + @Override
568 + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
569 +// future.set(new CouponsetsList());
570 + future.setException(new Throwable());
571 + }
572 + });
573 + return future;
574 + }
575 +
388 private static ArrayList<BannerItem> mergeCampaignResults(ArrayList<Campaign> resultCampaigns, ArrayList<Campaign> resultPersonalizedCampaigns, ArrayList<Content> resultArticles) { 576 private static ArrayList<BannerItem> mergeCampaignResults(ArrayList<Campaign> resultCampaigns, ArrayList<Campaign> resultPersonalizedCampaigns, ArrayList<Content> resultArticles) {
389 ArrayList<BannerItem> allItems = new ArrayList<>(); 577 ArrayList<BannerItem> allItems = new ArrayList<>();
390 578
...@@ -503,8 +691,8 @@ public class WarplyManager { ...@@ -503,8 +691,8 @@ public class WarplyManager {
503 Campaign camp = new Campaign(); 691 Campaign camp = new Campaign();
504 NewCampaign tempNewCampaign = new NewCampaign(finalCampaignsJBody.optJSONObject(i)); 692 NewCampaign tempNewCampaign = new NewCampaign(finalCampaignsJBody.optJSONObject(i));
505 693
506 - camp.setIndexUrl(tempNewCampaign.getIndexUrl()); 694 + camp.setIndexUrl(tempNewCampaign.getCampaignUrl());
507 - camp.setLogoUrl(tempNewCampaign.getLogoUrl()); 695 + camp.setLogoUrl(tempNewCampaign.getBannerImageMobile());
508 camp.setMessage(tempNewCampaign.getMessage()); 696 camp.setMessage(tempNewCampaign.getMessage());
509 camp.setOfferCategory(tempNewCampaign.getCommunicationCategory()); 697 camp.setOfferCategory(tempNewCampaign.getCommunicationCategory());
510 camp.setSessionUUID(tempNewCampaign.getCommunicationUUID()); 698 camp.setSessionUUID(tempNewCampaign.getCommunicationUUID());
...@@ -598,8 +786,8 @@ public class WarplyManager { ...@@ -598,8 +786,8 @@ public class WarplyManager {
598 Campaign camp = new Campaign(); 786 Campaign camp = new Campaign();
599 NewCampaign tempNewCampaign = new NewCampaign(finalCampaignsJBody.optJSONObject(i)); 787 NewCampaign tempNewCampaign = new NewCampaign(finalCampaignsJBody.optJSONObject(i));
600 788
601 - camp.setIndexUrl(tempNewCampaign.getIndexUrl()); 789 + camp.setIndexUrl(tempNewCampaign.getCampaignUrl());
602 - camp.setLogoUrl(tempNewCampaign.getLogoUrl()); 790 + camp.setLogoUrl(tempNewCampaign.getBannerImageMobile());
603 camp.setMessage(tempNewCampaign.getMessage()); 791 camp.setMessage(tempNewCampaign.getMessage());
604 camp.setOfferCategory(tempNewCampaign.getCommunicationCategory()); 792 camp.setOfferCategory(tempNewCampaign.getCommunicationCategory());
605 camp.setSessionUUID(tempNewCampaign.getCommunicationUUID()); 793 camp.setSessionUUID(tempNewCampaign.getCommunicationUUID());
......