Showing
8 changed files
with
664 additions
and
95 deletions
... | @@ -3,15 +3,15 @@ | ... | @@ -3,15 +3,15 @@ |
3 | # The app uuid the warply sdk need to connect to the engage server | 3 | # The app uuid the warply sdk need to connect to the engage server |
4 | # dev f83dfde1145e4c2da69793abb2f579af | 4 | # dev f83dfde1145e4c2da69793abb2f579af |
5 | # prod 0086a2088301440792091b9f814c2267 | 5 | # prod 0086a2088301440792091b9f814c2267 |
6 | -Uuid=0086a2088301440792091b9f814c2267 | 6 | +Uuid=f83dfde1145e4c2da69793abb2f579af |
7 | 7 | ||
8 | # If we need to see logs in Logcat | 8 | # If we need to see logs in Logcat |
9 | -Debug=false | 9 | +Debug=true |
10 | 10 | ||
11 | # Production or Development environment of the engage server | 11 | # Production or Development environment of the engage server |
12 | # Production: https://engage.warp.ly | 12 | # Production: https://engage.warp.ly |
13 | # Development: https://engage-stage.warp.ly | 13 | # Development: https://engage-stage.warp.ly |
14 | -BaseURL=https://engage.warp.ly | 14 | +BaseURL=https://engage-stage.warp.ly |
15 | 15 | ||
16 | # For Verify Ticket request | 16 | # For Verify Ticket request |
17 | VerifyURL=/partners/cosmote/verify | 17 | VerifyURL=/partners/cosmote/verify |
... | @@ -39,7 +39,7 @@ PushIcon=ic_notify | ... | @@ -39,7 +39,7 @@ PushIcon=ic_notify |
39 | SendPackages=false | 39 | SendPackages=false |
40 | 40 | ||
41 | # The app language | 41 | # The app language |
42 | -Language=el | 42 | +Language=en |
43 | 43 | ||
44 | # The merchant id for some requests | 44 | # The merchant id for some requests |
45 | MerchantId=20113 | 45 | MerchantId=20113 | ... | ... |
... | @@ -36,7 +36,7 @@ public class SplashActivity extends BaseActivity { | ... | @@ -36,7 +36,7 @@ public class SplashActivity extends BaseActivity { |
36 | public void onWarplyReady() { | 36 | public void onWarplyReady() { |
37 | if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) { | 37 | if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) { |
38 | WarplyManager.getCosmoteUser(new WarplyCosmoteUserRequest() | 38 | WarplyManager.getCosmoteUser(new WarplyCosmoteUserRequest() |
39 | - .setGuid("6010490808"), //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons, prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282 | 39 | + .setGuid("7000000831"), //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons, prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282 |
40 | mLoginReceiver); | 40 | mLoginReceiver); |
41 | } else { | 41 | } else { |
42 | startNextActivity(); | 42 | startNextActivity(); | ... | ... |
... | @@ -65,6 +65,7 @@ dependencies { | ... | @@ -65,6 +65,7 @@ dependencies { |
65 | api 'com.github.siyamed:android-shape-imageview:0.9.3' | 65 | api 'com.github.siyamed:android-shape-imageview:0.9.3' |
66 | implementation 'org.greenrobot:eventbus:3.3.1' | 66 | implementation 'org.greenrobot:eventbus:3.3.1' |
67 | api 'org.apmem.tools:layouts:1.10' | 67 | api 'org.apmem.tools:layouts:1.10' |
68 | + api 'com.google.guava:guava:30.1-android' | ||
68 | 69 | ||
69 | //------------------------------ Firebase -----------------------------// | 70 | //------------------------------ Firebase -----------------------------// |
70 | api platform('com.google.firebase:firebase-bom:29.0.3') | 71 | api platform('com.google.firebase:firebase-bom:29.0.3') | ... | ... |
... | @@ -50,9 +50,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation | ... | @@ -50,9 +50,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation |
50 | 50 | ||
51 | mBottomNavigationView = findViewById(R.id.bt_tabs); | 51 | mBottomNavigationView = findViewById(R.id.bt_tabs); |
52 | 52 | ||
53 | -// WarplyManager.getUserCouponsWithCouponsets(new WarplyUserCouponsRequest(), mUserCouponsReceiver); | ||
54 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); | 53 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); |
55 | - WarplyManager.getCampaigns(new WarplyGetCampaignsRequest().setLanguage("en"), mCampaignsCallback); | 54 | + WarplyManager.getCampaigns(mCampaignsCallback); |
56 | WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); | 55 | WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); |
57 | } | 56 | } |
58 | 57 | ||
... | @@ -123,7 +122,7 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation | ... | @@ -123,7 +122,7 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation |
123 | private final CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() { | 122 | private final CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() { |
124 | @Override | 123 | @Override |
125 | public void onSuccess(ArrayList<Campaign> result) { | 124 | public void onSuccess(ArrayList<Campaign> result) { |
126 | - Toast.makeText(BaseFragmentActivity.this, "Campaigns Success", Toast.LENGTH_SHORT).show(); | 125 | + Toast.makeText(BaseFragmentActivity.this, "Campaigns Success " + String.valueOf(result.size()), Toast.LENGTH_SHORT).show(); |
127 | } | 126 | } |
128 | 127 | ||
129 | @Override | 128 | @Override | ... | ... |
... | @@ -74,6 +74,8 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -74,6 +74,8 @@ public class Campaign implements Parcelable, Serializable { |
74 | private static final String CAMPAIGN_TYPE_SETTINGS = "campaign_type_settings"; | 74 | private static final String CAMPAIGN_TYPE_SETTINGS = "campaign_type_settings"; |
75 | private static final String BANNER_IMAGE = "Banner_img"; | 75 | private static final String BANNER_IMAGE = "Banner_img"; |
76 | private static final String BANNER_TITLE = "Banner_title"; | 76 | private static final String BANNER_TITLE = "Banner_title"; |
77 | + private static final String CATEGORY_ID = "category_id"; | ||
78 | + private static final String COUPON_AVAILABILITY = "coupon_availability"; | ||
77 | 79 | ||
78 | /* Member variables of the Campaign object */ | 80 | /* Member variables of the Campaign object */ |
79 | 81 | ||
... | @@ -103,7 +105,8 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -103,7 +105,8 @@ public class Campaign implements Parcelable, Serializable { |
103 | private String campaignTypeSettings; | 105 | private String campaignTypeSettings; |
104 | private String bannerImage; | 106 | private String bannerImage; |
105 | private String bannerTitle; | 107 | private String bannerTitle; |
106 | - private UnifiedCampaignModel unifiedCampaign; | 108 | + private String categoryId; |
109 | + private Integer couponAvailability; | ||
107 | 110 | ||
108 | /** | 111 | /** |
109 | * Basic constructor used to create an object from a String, representing a | 112 | * Basic constructor used to create an object from a String, representing a |
... | @@ -143,7 +146,8 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -143,7 +146,8 @@ public class Campaign implements Parcelable, Serializable { |
143 | this.campaignTypeSettings = ""; | 146 | this.campaignTypeSettings = ""; |
144 | this.bannerImage = ""; | 147 | this.bannerImage = ""; |
145 | this.bannerTitle = ""; | 148 | this.bannerTitle = ""; |
146 | - this.unifiedCampaign = new UnifiedCampaignModel(); | 149 | + this.couponAvailability = null; |
150 | + this.categoryId = ""; | ||
147 | } | 151 | } |
148 | 152 | ||
149 | /** | 153 | /** |
... | @@ -204,6 +208,8 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -204,6 +208,8 @@ public class Campaign implements Parcelable, Serializable { |
204 | } else { | 208 | } else { |
205 | this.actions = null; | 209 | this.actions = null; |
206 | } | 210 | } |
211 | + this.categoryId = json.optString(CATEGORY_ID); | ||
212 | + this.couponAvailability = json.optInt(COUPON_AVAILABILITY); | ||
207 | } | 213 | } |
208 | 214 | ||
209 | public Campaign(Parcel source) { | 215 | public Campaign(Parcel source) { |
... | @@ -231,6 +237,8 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -231,6 +237,8 @@ public class Campaign implements Parcelable, Serializable { |
231 | this.actions = source.readArrayList(CampaignAction.class.getClassLoader()); | 237 | this.actions = source.readArrayList(CampaignAction.class.getClassLoader()); |
232 | this.busId = source.readString(); | 238 | this.busId = source.readString(); |
233 | this.campaignTypeSettings = source.readString(); | 239 | this.campaignTypeSettings = source.readString(); |
240 | + this.categoryId = source.readString(); | ||
241 | + this.couponAvailability = source.readInt(); | ||
234 | } | 242 | } |
235 | 243 | ||
236 | @Override | 244 | @Override |
... | @@ -259,6 +267,8 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -259,6 +267,8 @@ public class Campaign implements Parcelable, Serializable { |
259 | dest.writeList(this.actions); | 267 | dest.writeList(this.actions); |
260 | dest.writeString(this.busId); | 268 | dest.writeString(this.busId); |
261 | dest.writeString(this.campaignTypeSettings); | 269 | dest.writeString(this.campaignTypeSettings); |
270 | + dest.writeInt(this.couponAvailability); | ||
271 | + dest.writeString(this.categoryId); | ||
262 | } | 272 | } |
263 | 273 | ||
264 | /** | 274 | /** |
... | @@ -293,6 +303,8 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -293,6 +303,8 @@ public class Campaign implements Parcelable, Serializable { |
293 | jObj.putOpt(DISPLAY_TYPE, this.displayType); | 303 | jObj.putOpt(DISPLAY_TYPE, this.displayType); |
294 | jObj.put(BUS_ID, this.busId); | 304 | jObj.put(BUS_ID, this.busId); |
295 | jObj.put(CAMPAIGN_TYPE_SETTINGS, this.campaignTypeSettings); | 305 | jObj.put(CAMPAIGN_TYPE_SETTINGS, this.campaignTypeSettings); |
306 | + jObj.putOpt(COUPON_AVAILABILITY, this.couponAvailability); | ||
307 | + jObj.putOpt(CATEGORY_ID, this.categoryId); | ||
296 | } catch (JSONException e) { | 308 | } catch (JSONException e) { |
297 | if (WarpConstants.DEBUG) { | 309 | if (WarpConstants.DEBUG) { |
298 | e.printStackTrace(); | 310 | e.printStackTrace(); |
... | @@ -366,6 +378,23 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -366,6 +378,23 @@ public class Campaign implements Parcelable, Serializable { |
366 | // Getters | 378 | // Getters |
367 | // ================================================================================ | 379 | // ================================================================================ |
368 | 380 | ||
381 | + | ||
382 | + public String getCategoryId() { | ||
383 | + return categoryId; | ||
384 | + } | ||
385 | + | ||
386 | + public void setCategoryId(String categoryId) { | ||
387 | + this.categoryId = categoryId; | ||
388 | + } | ||
389 | + | ||
390 | + public Integer getCouponAvailability() { | ||
391 | + return couponAvailability; | ||
392 | + } | ||
393 | + | ||
394 | + public void setCouponAvailability(Integer couponAvailability) { | ||
395 | + this.couponAvailability = couponAvailability; | ||
396 | + } | ||
397 | + | ||
369 | /** | 398 | /** |
370 | * @return The loyalty action of the Campaign, used if custom actions are | 399 | * @return The loyalty action of the Campaign, used if custom actions are |
371 | * implemented | 400 | * implemented |
... | @@ -630,14 +659,6 @@ public class Campaign implements Parcelable, Serializable { | ... | @@ -630,14 +659,6 @@ public class Campaign implements Parcelable, Serializable { |
630 | this.bannerTitle = bannerTitle; | 659 | this.bannerTitle = bannerTitle; |
631 | } | 660 | } |
632 | 661 | ||
633 | - public UnifiedCampaignModel getUnifiedCampaign() { | ||
634 | - return unifiedCampaign; | ||
635 | - } | ||
636 | - | ||
637 | - public void setUnifiedCampaign(UnifiedCampaignModel unifiedCampaign) { | ||
638 | - this.unifiedCampaign = unifiedCampaign; | ||
639 | - } | ||
640 | - | ||
641 | @Override | 662 | @Override |
642 | public int describeContents() { | 663 | public int describeContents() { |
643 | return 0; | 664 | return 0; | ... | ... |
... | @@ -79,6 +79,21 @@ public class NewCampaignList extends ArrayList<NewCampaign> { | ... | @@ -79,6 +79,21 @@ public class NewCampaignList extends ArrayList<NewCampaign> { |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | + public NewCampaignList(JSONObject campaignListJSONObject) { | ||
83 | + campaignListJSONObject = campaignListJSONObject.optJSONObject(JSON_KEY_CONTEXT); | ||
84 | + if (campaignListJSONObject == null) | ||
85 | + return; | ||
86 | + JSONObject jsonObject = campaignListJSONObject.optJSONObject(JSON_KEY_MAPP); | ||
87 | + if(jsonObject == null) | ||
88 | + return;; | ||
89 | + JSONArray jArray = jsonObject.optJSONArray(JSON_KEY_MAPP_VALUE); | ||
90 | + if (jArray != null) { | ||
91 | + for (int i = 0, lim = jArray.length(); i < lim; ++i) { | ||
92 | + add(new NewCampaign(jArray.optJSONObject(i))); | ||
93 | + } | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
82 | @NonNull | 97 | @NonNull |
83 | public String getRequestSignature() { | 98 | public String getRequestSignature() { |
84 | return mRequestSignature; | 99 | return mRequestSignature; | ... | ... |
... | @@ -89,20 +89,31 @@ public interface ApiService { | ... | @@ -89,20 +89,31 @@ public interface ApiService { |
89 | @Header(WarpConstants.HEADER_SIGNATURE) String signature); | 89 | @Header(WarpConstants.HEADER_SIGNATURE) String signature); |
90 | 90 | ||
91 | @Headers("Content-Type: application/json") | 91 | @Headers("Content-Type: application/json") |
92 | + @POST("/api/mobile/v2/{appUuid}/context/") | ||
93 | + Call<ResponseBody> getCampaigns(@Path("appUuid") String appUuid, | ||
94 | + @Body RequestBody request, | ||
95 | + @Header(WarpConstants.HEADER_DATE) String timeStamp, | ||
96 | + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | ||
97 | + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, | ||
98 | + @Header(WarpConstants.HEADER_CHANNEL) String channel, | ||
99 | + @Header(WarpConstants.HEADER_WEB_ID) String webId, | ||
100 | + @Header(WarpConstants.HEADER_SIGNATURE) String signature); | ||
101 | + | ||
102 | + @Headers("Content-Type: application/json") | ||
92 | @POST("/oauth/{appUuid}/context") | 103 | @POST("/oauth/{appUuid}/context") |
93 | - Call<ResponseBody> sendTelematicsData(@Path("appUuid") String appUuid, | 104 | + Call<ResponseBody> getCampaignsPersonalized(@Path("appUuid") String appUuid, |
94 | - @Body RequestBody request, | 105 | + @Body RequestBody request, |
95 | - @Header(WarpConstants.HEADER_DATE) String timeStamp, | 106 | + @Header(WarpConstants.HEADER_DATE) String timeStamp, |
96 | - @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | 107 | + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, |
97 | - @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, | 108 | + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, |
98 | - @Header(WarpConstants.HEADER_CHANNEL) String channel, | 109 | + @Header(WarpConstants.HEADER_CHANNEL) String channel, |
99 | - @Header(WarpConstants.HEADER_WEB_ID) String webId, | 110 | + @Header(WarpConstants.HEADER_WEB_ID) String webId, |
100 | - @Header(WarpConstants.HEADER_SIGNATURE) String signature, | 111 | + @Header(WarpConstants.HEADER_SIGNATURE) String signature, |
101 | - @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); | 112 | + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); |
102 | 113 | ||
103 | @Headers("Content-Type: application/json") | 114 | @Headers("Content-Type: application/json") |
104 | @POST("/oauth/{appUuid}/context") | 115 | @POST("/oauth/{appUuid}/context") |
105 | - Call<ResponseBody> cancelUnifiedCoupon(@Path("appUuid") String appUuid, | 116 | + Call<ResponseBody> sendTelematicsData(@Path("appUuid") String appUuid, |
106 | @Body RequestBody request, | 117 | @Body RequestBody request, |
107 | @Header(WarpConstants.HEADER_DATE) String timeStamp, | 118 | @Header(WarpConstants.HEADER_DATE) String timeStamp, |
108 | @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | 119 | @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, |
... | @@ -114,19 +125,19 @@ public interface ApiService { | ... | @@ -114,19 +125,19 @@ public interface ApiService { |
114 | 125 | ||
115 | @Headers("Content-Type: application/json") | 126 | @Headers("Content-Type: application/json") |
116 | @POST("/oauth/{appUuid}/context") | 127 | @POST("/oauth/{appUuid}/context") |
117 | - Call<ResponseBody> getTelematicsHistoy(@Path("appUuid") String appUuid, | 128 | + Call<ResponseBody> cancelUnifiedCoupon(@Path("appUuid") String appUuid, |
118 | - @Body RequestBody request, | 129 | + @Body RequestBody request, |
119 | - @Header(WarpConstants.HEADER_DATE) String timeStamp, | 130 | + @Header(WarpConstants.HEADER_DATE) String timeStamp, |
120 | - @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | 131 | + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, |
121 | - @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, | 132 | + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, |
122 | - @Header(WarpConstants.HEADER_CHANNEL) String channel, | 133 | + @Header(WarpConstants.HEADER_CHANNEL) String channel, |
123 | - @Header(WarpConstants.HEADER_WEB_ID) String webId, | 134 | + @Header(WarpConstants.HEADER_WEB_ID) String webId, |
124 | - @Header(WarpConstants.HEADER_SIGNATURE) String signature, | 135 | + @Header(WarpConstants.HEADER_SIGNATURE) String signature, |
125 | - @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); | 136 | + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); |
126 | 137 | ||
127 | @Headers("Content-Type: application/json") | 138 | @Headers("Content-Type: application/json") |
128 | @POST("/oauth/{appUuid}/context") | 139 | @POST("/oauth/{appUuid}/context") |
129 | - Call<ResponseBody> getTripMetrics(@Path("appUuid") String appUuid, | 140 | + Call<ResponseBody> getTelematicsHistoy(@Path("appUuid") String appUuid, |
130 | @Body RequestBody request, | 141 | @Body RequestBody request, |
131 | @Header(WarpConstants.HEADER_DATE) String timeStamp, | 142 | @Header(WarpConstants.HEADER_DATE) String timeStamp, |
132 | @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | 143 | @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, |
... | @@ -138,7 +149,7 @@ public interface ApiService { | ... | @@ -138,7 +149,7 @@ public interface ApiService { |
138 | 149 | ||
139 | @Headers("Content-Type: application/json") | 150 | @Headers("Content-Type: application/json") |
140 | @POST("/oauth/{appUuid}/context") | 151 | @POST("/oauth/{appUuid}/context") |
141 | - Call<ResponseBody> rateTrip(@Path("appUuid") String appUuid, | 152 | + Call<ResponseBody> getTripMetrics(@Path("appUuid") String appUuid, |
142 | @Body RequestBody request, | 153 | @Body RequestBody request, |
143 | @Header(WarpConstants.HEADER_DATE) String timeStamp, | 154 | @Header(WarpConstants.HEADER_DATE) String timeStamp, |
144 | @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | 155 | @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, |
... | @@ -148,6 +159,18 @@ public interface ApiService { | ... | @@ -148,6 +159,18 @@ public interface ApiService { |
148 | @Header(WarpConstants.HEADER_SIGNATURE) String signature, | 159 | @Header(WarpConstants.HEADER_SIGNATURE) String signature, |
149 | @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); | 160 | @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); |
150 | 161 | ||
162 | + @Headers("Content-Type: application/json") | ||
163 | + @POST("/oauth/{appUuid}/context") | ||
164 | + Call<ResponseBody> rateTrip(@Path("appUuid") String appUuid, | ||
165 | + @Body RequestBody request, | ||
166 | + @Header(WarpConstants.HEADER_DATE) String timeStamp, | ||
167 | + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | ||
168 | + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, | ||
169 | + @Header(WarpConstants.HEADER_CHANNEL) String channel, | ||
170 | + @Header(WarpConstants.HEADER_WEB_ID) String webId, | ||
171 | + @Header(WarpConstants.HEADER_SIGNATURE) String signature, | ||
172 | + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); | ||
173 | + | ||
151 | // =========================================================== | 174 | // =========================================================== |
152 | // Getter & Setter | 175 | // Getter & Setter |
153 | // =========================================================== | 176 | // =========================================================== | ... | ... |
... | @@ -34,6 +34,7 @@ import android.os.Build; | ... | @@ -34,6 +34,7 @@ import android.os.Build; |
34 | import android.os.Handler; | 34 | import android.os.Handler; |
35 | import android.os.Looper; | 35 | import android.os.Looper; |
36 | import android.os.SystemClock; | 36 | import android.os.SystemClock; |
37 | +import android.text.TextUtils; | ||
37 | import android.text.format.DateFormat; | 38 | import android.text.format.DateFormat; |
38 | import android.util.ArrayMap; | 39 | import android.util.ArrayMap; |
39 | 40 | ||
... | @@ -41,6 +42,13 @@ import androidx.annotation.NonNull; | ... | @@ -41,6 +42,13 @@ import androidx.annotation.NonNull; |
41 | import androidx.work.OneTimeWorkRequest; | 42 | import androidx.work.OneTimeWorkRequest; |
42 | import androidx.work.WorkManager; | 43 | import androidx.work.WorkManager; |
43 | 44 | ||
45 | +import com.google.common.util.concurrent.FutureCallback; | ||
46 | +import com.google.common.util.concurrent.Futures; | ||
47 | +import com.google.common.util.concurrent.ListenableFuture; | ||
48 | +import com.google.common.util.concurrent.ListeningExecutorService; | ||
49 | +import com.google.common.util.concurrent.MoreExecutors; | ||
50 | +import com.google.common.util.concurrent.SettableFuture; | ||
51 | + | ||
44 | import org.greenrobot.eventbus.EventBus; | 52 | import org.greenrobot.eventbus.EventBus; |
45 | import org.json.JSONArray; | 53 | import org.json.JSONArray; |
46 | import org.json.JSONException; | 54 | import org.json.JSONException; |
... | @@ -52,6 +60,7 @@ import java.util.ArrayList; | ... | @@ -52,6 +60,7 @@ import java.util.ArrayList; |
52 | import java.util.Collections; | 60 | import java.util.Collections; |
53 | import java.util.Date; | 61 | import java.util.Date; |
54 | import java.util.LinkedHashSet; | 62 | import java.util.LinkedHashSet; |
63 | +import java.util.List; | ||
55 | import java.util.Map; | 64 | import java.util.Map; |
56 | import java.util.Set; | 65 | import java.util.Set; |
57 | import java.util.concurrent.ExecutorService; | 66 | import java.util.concurrent.ExecutorService; |
... | @@ -90,6 +99,7 @@ import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel; | ... | @@ -90,6 +99,7 @@ import ly.warp.sdk.io.models.LoyaltySDKDynatraceEventModel; |
90 | import ly.warp.sdk.io.models.Merchant; | 99 | import ly.warp.sdk.io.models.Merchant; |
91 | import ly.warp.sdk.io.models.MerchantCategoriesList; | 100 | import ly.warp.sdk.io.models.MerchantCategoriesList; |
92 | import ly.warp.sdk.io.models.MerchantList; | 101 | import ly.warp.sdk.io.models.MerchantList; |
102 | +import ly.warp.sdk.io.models.NewCampaign; | ||
93 | import ly.warp.sdk.io.models.PacingDetails; | 103 | import ly.warp.sdk.io.models.PacingDetails; |
94 | import ly.warp.sdk.io.models.PointsList; | 104 | import ly.warp.sdk.io.models.PointsList; |
95 | import ly.warp.sdk.io.models.ProductList; | 105 | import ly.warp.sdk.io.models.ProductList; |
... | @@ -150,7 +160,6 @@ import ly.warp.sdk.io.request.WarplyVerifyTicketRequest; | ... | @@ -150,7 +160,6 @@ import ly.warp.sdk.io.request.WarplyVerifyTicketRequest; |
150 | import ly.warp.sdk.io.volley.ApiClient; | 160 | import ly.warp.sdk.io.volley.ApiClient; |
151 | import ly.warp.sdk.io.volley.ApiService; | 161 | import ly.warp.sdk.io.volley.ApiService; |
152 | import ly.warp.sdk.services.EventCampaignService; | 162 | import ly.warp.sdk.services.EventCampaignService; |
153 | -import ly.warp.sdk.services.EventCouponsService; | ||
154 | import ly.warp.sdk.services.EventUnifiedCouponsService; | 163 | import ly.warp.sdk.services.EventUnifiedCouponsService; |
155 | import ly.warp.sdk.services.WarplyHealthService; | 164 | import ly.warp.sdk.services.WarplyHealthService; |
156 | import ly.warp.sdk.utils.WarpJSONParser; | 165 | import ly.warp.sdk.utils.WarpJSONParser; |
... | @@ -1519,57 +1528,15 @@ public class WarplyManager { | ... | @@ -1519,57 +1528,15 @@ public class WarplyManager { |
1519 | } | 1528 | } |
1520 | } | 1529 | } |
1521 | 1530 | ||
1522 | - if (camp.getOfferCategory().equals("questionnaire")) { | 1531 | + try { |
1523 | -// if (WarplyManagerHelper.getConsumerInternal() != null) { | 1532 | + JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); |
1524 | -// JSONObject profMetadata = WarpJSONParser.getJSONFromString(WarplyManagerHelper.getConsumerInternal().getProfileMetadata()); | 1533 | + if (extraFields != null) { |
1525 | -// if (profMetadata != null) { | 1534 | + if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { |
1526 | -// if (!profMetadata.has("answered")) { | 1535 | + campaignLoyaltyList.add(camp); |
1527 | -// try { | ||
1528 | -// JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1529 | -// if (extraFields != null) { | ||
1530 | -// if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { | ||
1531 | -// campaignLoyaltyList.add(camp); | ||
1532 | -// } | ||
1533 | -// } | ||
1534 | -// } catch (Exception exception) { | ||
1535 | -// campaignLoyaltyList.add(camp); | ||
1536 | -// } | ||
1537 | -// } | ||
1538 | -// } else { | ||
1539 | -// try { | ||
1540 | -// JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1541 | -// if (extraFields != null) { | ||
1542 | -// if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { | ||
1543 | -// campaignLoyaltyList.add(camp); | ||
1544 | -// } | ||
1545 | -// } | ||
1546 | -// } catch (Exception exception) { | ||
1547 | -// campaignLoyaltyList.add(camp); | ||
1548 | -// } | ||
1549 | -// } | ||
1550 | -// } else { | ||
1551 | -// try { | ||
1552 | -// JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1553 | -// if (extraFields != null) { | ||
1554 | -// if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { | ||
1555 | -// campaignLoyaltyList.add(camp); | ||
1556 | -// } | ||
1557 | -// } | ||
1558 | -// } catch (Exception exception) { | ||
1559 | -// campaignLoyaltyList.add(camp); | ||
1560 | -// } | ||
1561 | -// } | ||
1562 | - } else { | ||
1563 | - try { | ||
1564 | - JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1565 | - if (extraFields != null) { | ||
1566 | - if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { | ||
1567 | - campaignLoyaltyList.add(camp); | ||
1568 | - } | ||
1569 | } | 1536 | } |
1570 | - } catch (Exception exception) { | ||
1571 | - campaignLoyaltyList.add(camp); | ||
1572 | } | 1537 | } |
1538 | + } catch (Exception exception) { | ||
1539 | + campaignLoyaltyList.add(camp); | ||
1573 | } | 1540 | } |
1574 | } | 1541 | } |
1575 | WarplyManagerHelper.setCarouselList(campaignCarouselList); | 1542 | WarplyManagerHelper.setCarouselList(campaignCarouselList); |
... | @@ -1598,6 +1565,441 @@ public class WarplyManager { | ... | @@ -1598,6 +1565,441 @@ public class WarplyManager { |
1598 | request.getSignature())); | 1565 | request.getSignature())); |
1599 | } | 1566 | } |
1600 | 1567 | ||
1568 | + private static ArrayList<Campaign> mergeCampaignResults(ArrayList<Campaign> resultCampaigns, ArrayList<Campaign> resultPersonalizedCampaigns) { | ||
1569 | + ArrayList<Campaign> newCampaignList = new ArrayList<Campaign>(); | ||
1570 | + ArrayList<Campaign> campaignLoyaltyList = new ArrayList<>(); | ||
1571 | + newCampaignList.clear(); | ||
1572 | + if (resultCampaigns != null && resultCampaigns.size() > 0) | ||
1573 | + newCampaignList.addAll(resultCampaigns); | ||
1574 | + if (resultPersonalizedCampaigns != null && resultPersonalizedCampaigns.size() > 0) | ||
1575 | + newCampaignList.addAll(resultPersonalizedCampaigns); | ||
1576 | + | ||
1577 | + if (newCampaignList != null && newCampaignList.size() > 0) { | ||
1578 | + Collections.sort(newCampaignList, (obj1, obj2) -> Integer.compare(obj1.getSorting(), obj2.getSorting())); | ||
1579 | + WarplyManagerHelper.setCampaignList(newCampaignList); | ||
1580 | + campaignLoyaltyList.clear(); | ||
1581 | + ArrayList<Campaign> campaignCarouselList = new ArrayList<>(); | ||
1582 | + campaignCarouselList.clear(); | ||
1583 | + for (Campaign camp : newCampaignList) { | ||
1584 | + JSONObject campMetadata = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1585 | + if (campMetadata != null) { | ||
1586 | + if (campMetadata.has("carousel")) { | ||
1587 | + campaignCarouselList.add(camp); | ||
1588 | + } | ||
1589 | + } | ||
1590 | + | ||
1591 | + try { | ||
1592 | + JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1593 | + if (extraFields != null) { | ||
1594 | + if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { | ||
1595 | + campaignLoyaltyList.add(camp); | ||
1596 | + } | ||
1597 | + } | ||
1598 | + } catch (Exception exception) { | ||
1599 | + campaignLoyaltyList.add(camp); | ||
1600 | + } | ||
1601 | + } | ||
1602 | + WarplyManagerHelper.setCarouselList(campaignCarouselList); | ||
1603 | + | ||
1604 | + Set<Campaign> set = new LinkedHashSet<>(campaignLoyaltyList); | ||
1605 | + campaignLoyaltyList.clear(); | ||
1606 | + campaignLoyaltyList.addAll(set); | ||
1607 | + } | ||
1608 | + | ||
1609 | + return campaignLoyaltyList; | ||
1610 | + } | ||
1611 | + | ||
1612 | + public static void getCampaigns(final CallbackReceiver<ArrayList<Campaign>> receiver) { | ||
1613 | + WarpUtils.log("************* WARPLY Get Campaigns Request ********************"); | ||
1614 | + WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active"); | ||
1615 | + WarpUtils.log("**************************************************"); | ||
1616 | + | ||
1617 | + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); | ||
1618 | + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2)); | ||
1619 | + | ||
1620 | + ListenableFuture<ArrayList<Campaign>> futureCampaigns = getCampaignsRetro(service); | ||
1621 | + ListenableFuture<ArrayList<Campaign>> futurePersonalizedCampaigns = getCampaignsPersonalizedRetro(service); | ||
1622 | + | ||
1623 | + ListenableFuture<List<ArrayList<Campaign>>> allResultsFuture = Futures.allAsList(futureCampaigns, futurePersonalizedCampaigns); | ||
1624 | + ListenableFuture<ArrayList<Campaign>> mergedResultFuture = Futures.transformAsync( | ||
1625 | + allResultsFuture, | ||
1626 | + results -> { | ||
1627 | + ArrayList<Campaign> resultCampaigns = results.get(0); | ||
1628 | + ArrayList<Campaign> resultPersonalizedCampaigns = results.get(1); | ||
1629 | + return executorService.submit(() -> mergeCampaignResults(resultCampaigns, resultPersonalizedCampaigns)); | ||
1630 | + }, | ||
1631 | + executorService | ||
1632 | + ); | ||
1633 | + | ||
1634 | + Futures.addCallback(mergedResultFuture, new FutureCallback<ArrayList<Campaign>>() { | ||
1635 | + @Override | ||
1636 | + public void onSuccess(ArrayList<Campaign> mergedResult) { | ||
1637 | + executorService.shutdownNow(); | ||
1638 | + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult)); | ||
1639 | + } | ||
1640 | + | ||
1641 | + @Override | ||
1642 | + public void onFailure(Throwable throwable) { | ||
1643 | + receiver.onFailure(2); | ||
1644 | + } | ||
1645 | + }, executorService); | ||
1646 | + | ||
1647 | +// getCampaignsRetro(service, new CallbackReceiver<ArrayList<Campaign>>() { | ||
1648 | +// @Override | ||
1649 | +// public void onSuccess(ArrayList<Campaign> result) { | ||
1650 | +// getCampaignsPersonalizedRetro(service, new CallbackReceiver<ArrayList<Campaign>>() { | ||
1651 | +// @Override | ||
1652 | +// public void onSuccess(ArrayList<Campaign> resultPersonalized) { | ||
1653 | +// final ExecutorService executorShops = Executors.newFixedThreadPool(1); | ||
1654 | +// executorShops.submit(() -> { | ||
1655 | +// ArrayList<Campaign> newCampaignList = new ArrayList<Campaign>(); | ||
1656 | +// newCampaignList.clear(); | ||
1657 | +// newCampaignList.addAll(result); | ||
1658 | +// newCampaignList.addAll(resultPersonalized); | ||
1659 | +// Collections.sort(newCampaignList, (obj1, obj2) -> Integer.compare(obj1.getSorting(), obj2.getSorting())); | ||
1660 | +// WarplyManagerHelper.setCampaignList(newCampaignList); | ||
1661 | +// ArrayList<Campaign> campaignLoyaltyList = new ArrayList<>(); | ||
1662 | +// campaignLoyaltyList.clear(); | ||
1663 | +// ArrayList<Campaign> campaignCarouselList = new ArrayList<>(); | ||
1664 | +// campaignCarouselList.clear(); | ||
1665 | +// for (Campaign camp : newCampaignList) { | ||
1666 | +// JSONObject campMetadata = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1667 | +// if (campMetadata != null) { | ||
1668 | +// if (campMetadata.has("carousel")) { | ||
1669 | +// campaignCarouselList.add(camp); | ||
1670 | +// } | ||
1671 | +// } | ||
1672 | +// | ||
1673 | +// try { | ||
1674 | +// JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields()); | ||
1675 | +// if (extraFields != null) { | ||
1676 | +// if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) { | ||
1677 | +// campaignLoyaltyList.add(camp); | ||
1678 | +// } | ||
1679 | +// } | ||
1680 | +// } catch (Exception exception) { | ||
1681 | +// campaignLoyaltyList.add(camp); | ||
1682 | +// } | ||
1683 | +// } | ||
1684 | +// WarplyManagerHelper.setCarouselList(campaignCarouselList); | ||
1685 | +// | ||
1686 | +// Set<Campaign> set = new LinkedHashSet<>(campaignLoyaltyList); | ||
1687 | +// campaignLoyaltyList.clear(); | ||
1688 | +// campaignLoyaltyList.addAll(set); | ||
1689 | +// executorShops.shutdownNow(); | ||
1690 | +// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(campaignLoyaltyList));//resultPersonalized | ||
1691 | +// }); | ||
1692 | +// } | ||
1693 | +// | ||
1694 | +// @Override | ||
1695 | +// public void onFailure(int errorCode) { | ||
1696 | +// receiver.onFailure(errorCode); | ||
1697 | +// } | ||
1698 | +// }); | ||
1699 | +// } | ||
1700 | +// | ||
1701 | +// @Override | ||
1702 | +// public void onFailure(int errorCode) { | ||
1703 | +// receiver.onFailure(errorCode); | ||
1704 | +// } | ||
1705 | +// }); | ||
1706 | + } | ||
1707 | + | ||
1708 | + private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsRetro(ApiService service/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) { | ||
1709 | + SettableFuture<ArrayList<Campaign>> future = SettableFuture.create(); | ||
1710 | + | ||
1711 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
1712 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
1713 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
1714 | + | ||
1715 | + Map<String, Object> jsonParamsCampaigns = new ArrayMap<>(); | ||
1716 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
1717 | + jsonParams.put("action", "retrieve"); | ||
1718 | + jsonParams.put("filters", new JSONObject()); | ||
1719 | + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); | ||
1720 | + | ||
1721 | + jsonParamsCampaigns.put("campaigns", jsonParams); | ||
1722 | + RequestBody campaignsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); | ||
1723 | + | ||
1724 | + Call<ResponseBody> campaignsCall = service.getCampaigns( | ||
1725 | + WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
1726 | + campaignsRequest, | ||
1727 | + timeStamp, | ||
1728 | + "android:" + Warply.getWarplyContext().getPackageName(), | ||
1729 | + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
1730 | + "mobile", | ||
1731 | + webId, | ||
1732 | + WarpUtils.produceSignature(apiKey + timeStamp) | ||
1733 | + ); | ||
1734 | + | ||
1735 | + campaignsCall.enqueue(new Callback<ResponseBody>() { | ||
1736 | + @Override | ||
1737 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
1738 | + if (response.code() == 200 && response.body() != null) { | ||
1739 | + JSONObject jobjCampaignsResponse = null; | ||
1740 | + try { | ||
1741 | + jobjCampaignsResponse = new JSONObject(response.body().string()); | ||
1742 | + } catch (Exception e) { | ||
1743 | + e.printStackTrace(); | ||
1744 | + } | ||
1745 | + | ||
1746 | + if (jobjCampaignsResponse != null && jobjCampaignsResponse.has("status") && jobjCampaignsResponse.optString("status", "2").equals("1")) { | ||
1747 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1748 | + dynatraceEvent.setEventName("custom_success_campaigns_loyalty"); | ||
1749 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1750 | + | ||
1751 | + JSONArray jCampaignsBody = null; | ||
1752 | + try { | ||
1753 | + jCampaignsBody = jobjCampaignsResponse.optJSONObject("context").optJSONObject("MAPP_CAMPAIGNING").optJSONArray("campaigns"); | ||
1754 | + } catch (Exception e) { | ||
1755 | + e.printStackTrace(); | ||
1756 | + } | ||
1757 | + | ||
1758 | + if (jCampaignsBody != null) { | ||
1759 | + ArrayList<NewCampaign> tempCampaigns = new ArrayList<>(); | ||
1760 | + ArrayList<Campaign> mCampaignsList = new ArrayList<>(); | ||
1761 | + | ||
1762 | + final ExecutorService executorShops = Executors.newFixedThreadPool(1); | ||
1763 | + JSONArray finalCampaignsJBody = jCampaignsBody; | ||
1764 | + executorShops.submit(() -> { | ||
1765 | + for (int i = 0; i < finalCampaignsJBody.length(); ++i) { | ||
1766 | + tempCampaigns.add(new NewCampaign(finalCampaignsJBody.optJSONObject(i))); | ||
1767 | + } | ||
1768 | + for (NewCampaign newCamp : tempCampaigns) { | ||
1769 | + Campaign camp = new Campaign(); | ||
1770 | + camp.setIndexUrl(newCamp.getIndexUrl()); | ||
1771 | + camp.setLogoUrl(newCamp.getLogoUrl()); | ||
1772 | + camp.setMessage(newCamp.getMessage()); | ||
1773 | + camp.setOfferCategory(newCamp.getCommunicationCategory()); | ||
1774 | + camp.setSessionUUID(newCamp.getCommunicationUUID()); | ||
1775 | + camp.setTitle(newCamp.getTitle()); | ||
1776 | + camp.setSubtitle(newCamp.getSubtitle()); | ||
1777 | + camp.setSorting(newCamp.getSorting()); | ||
1778 | + camp.setNew(newCamp.getIsNew()); | ||
1779 | + camp.setType(newCamp.getCampaignType()); | ||
1780 | + try { | ||
1781 | + camp.setExtraFields(newCamp.getExtraFields().toString()); | ||
1782 | + if (!TextUtils.isEmpty(newCamp.getExtraFields().toString())) { | ||
1783 | + JSONObject extraFieldsResp = WarpJSONParser.getJSONFromString(newCamp.getExtraFields().toString()); | ||
1784 | + if (extraFieldsResp != null) { | ||
1785 | + if (extraFieldsResp.has("Banner_title")) { | ||
1786 | + camp.setBannerTitle(extraFieldsResp.optString("Banner_title", "")); | ||
1787 | + } | ||
1788 | + if (extraFieldsResp.has("Banner_img")) { | ||
1789 | + camp.setBannerImage(extraFieldsResp.optString("Banner_img", "")); | ||
1790 | + } | ||
1791 | + } | ||
1792 | + } else { | ||
1793 | + camp.setBannerImage(""); | ||
1794 | + camp.setBannerTitle(""); | ||
1795 | + } | ||
1796 | + } catch (NullPointerException e) { | ||
1797 | + camp.setExtraFields(""); | ||
1798 | + camp.setBannerImage(""); | ||
1799 | + camp.setBannerTitle(""); | ||
1800 | + e.printStackTrace(); | ||
1801 | + } | ||
1802 | + | ||
1803 | + try { | ||
1804 | + camp.setCampaignTypeSettings(newCamp.getSettings().toString()); | ||
1805 | + } catch (NullPointerException e) { | ||
1806 | + camp.setCampaignTypeSettings(""); | ||
1807 | + e.printStackTrace(); | ||
1808 | + } | ||
1809 | + mCampaignsList.add(camp); | ||
1810 | + } | ||
1811 | + | ||
1812 | + executorShops.shutdownNow(); | ||
1813 | +// receiver.onSuccess(mCampaignsList); | ||
1814 | + future.set(mCampaignsList); | ||
1815 | + }); | ||
1816 | + } | ||
1817 | + } else { | ||
1818 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1819 | + dynatraceEvent.setEventName("custom_error_campaigns_loyalty"); | ||
1820 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1821 | +// receiver.onFailure(2); | ||
1822 | + future.set(new ArrayList<Campaign>()); | ||
1823 | + } | ||
1824 | + } else { | ||
1825 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1826 | + dynatraceEvent.setEventName("custom_error_campaigns_loyalty"); | ||
1827 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1828 | +// receiver.onFailure(response.code()); | ||
1829 | + future.set(new ArrayList<Campaign>()); | ||
1830 | + } | ||
1831 | + } | ||
1832 | + | ||
1833 | + @Override | ||
1834 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
1835 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1836 | + dynatraceEvent.setEventName("custom_error_campaigns_loyalty"); | ||
1837 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1838 | +// receiver.onFailure(2); | ||
1839 | + future.set(new ArrayList<Campaign>()); | ||
1840 | + } | ||
1841 | + }); | ||
1842 | + | ||
1843 | + return future; | ||
1844 | + } | ||
1845 | + | ||
1846 | + private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsPersonalizedRetro(ApiService service/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) { | ||
1847 | + SettableFuture<ArrayList<Campaign>> future = SettableFuture.create(); | ||
1848 | + | ||
1849 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
1850 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
1851 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
1852 | + | ||
1853 | + Map<String, Object> jsonParamsCampaigns = new ArrayMap<>(); | ||
1854 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
1855 | + jsonParams.put("action", "retrieve"); | ||
1856 | + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); | ||
1857 | + | ||
1858 | + jsonParamsCampaigns.put("campaigns", jsonParams); | ||
1859 | + RequestBody campaignsPersonalizedRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString()); | ||
1860 | + | ||
1861 | + Call<ResponseBody> campaignsPersonalizedCall = service.getCampaignsPersonalized( | ||
1862 | + WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
1863 | + campaignsPersonalizedRequest, | ||
1864 | + timeStamp, | ||
1865 | + "android:" + Warply.getWarplyContext().getPackageName(), | ||
1866 | + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
1867 | + "mobile", | ||
1868 | + webId, | ||
1869 | + WarpUtils.produceSignature(apiKey + timeStamp), | ||
1870 | + "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
1871 | + ); | ||
1872 | + | ||
1873 | + campaignsPersonalizedCall.enqueue(new Callback<ResponseBody>() { | ||
1874 | + @Override | ||
1875 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
1876 | + if (response.code() == 200 && response.body() != null) { | ||
1877 | + JSONObject jobjCampaignsResponse = null; | ||
1878 | + try { | ||
1879 | + jobjCampaignsResponse = new JSONObject(response.body().string()); | ||
1880 | + } catch (Exception e) { | ||
1881 | + e.printStackTrace(); | ||
1882 | + } | ||
1883 | + | ||
1884 | + if (jobjCampaignsResponse != null && jobjCampaignsResponse.has("status") && jobjCampaignsResponse.optString("status", "2").equals("1")) { | ||
1885 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1886 | + dynatraceEvent.setEventName("custom_success_campaigns_loyalty"); | ||
1887 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1888 | + | ||
1889 | + JSONArray jCampaignsBody = null; | ||
1890 | + try { | ||
1891 | + jCampaignsBody = jobjCampaignsResponse.optJSONObject("context").optJSONObject("MAPP_CAMPAIGNING").optJSONArray("campaigns"); | ||
1892 | + } catch (Exception e) { | ||
1893 | + e.printStackTrace(); | ||
1894 | + } | ||
1895 | + | ||
1896 | + if (jCampaignsBody != null) { | ||
1897 | + ArrayList<NewCampaign> tempCampaigns = new ArrayList<>(); | ||
1898 | + ArrayList<Campaign> mCampaignsList = new ArrayList<>(); | ||
1899 | + | ||
1900 | + final ExecutorService executorShops = Executors.newFixedThreadPool(1); | ||
1901 | + JSONArray finalCampaignsJBody = jCampaignsBody; | ||
1902 | + executorShops.submit(() -> { | ||
1903 | + for (int i = 0; i < finalCampaignsJBody.length(); ++i) { | ||
1904 | + tempCampaigns.add(new NewCampaign(finalCampaignsJBody.optJSONObject(i))); | ||
1905 | + } | ||
1906 | + for (NewCampaign newCamp : tempCampaigns) { | ||
1907 | + Campaign camp = new Campaign(); | ||
1908 | + camp.setIndexUrl(newCamp.getIndexUrl()); | ||
1909 | + camp.setLogoUrl(newCamp.getLogoUrl()); | ||
1910 | + camp.setMessage(newCamp.getMessage()); | ||
1911 | + camp.setOfferCategory(newCamp.getCommunicationCategory()); | ||
1912 | + camp.setSessionUUID(newCamp.getCommunicationUUID()); | ||
1913 | + camp.setTitle(newCamp.getTitle()); | ||
1914 | + camp.setSubtitle(newCamp.getSubtitle()); | ||
1915 | + camp.setSorting(newCamp.getSorting()); | ||
1916 | + camp.setNew(newCamp.getIsNew()); | ||
1917 | + camp.setType(newCamp.getCampaignType()); | ||
1918 | + try { | ||
1919 | + camp.setExtraFields(newCamp.getExtraFields().toString()); | ||
1920 | + if (!TextUtils.isEmpty(newCamp.getExtraFields().toString())) { | ||
1921 | + JSONObject extraFieldsResp = WarpJSONParser.getJSONFromString(newCamp.getExtraFields().toString()); | ||
1922 | + if (extraFieldsResp != null) { | ||
1923 | + if (extraFieldsResp.has("Banner_title")) { | ||
1924 | + camp.setBannerTitle(extraFieldsResp.optString("Banner_title", "")); | ||
1925 | + } | ||
1926 | + if (extraFieldsResp.has("Banner_img")) { | ||
1927 | + camp.setBannerImage(extraFieldsResp.optString("Banner_img", "")); | ||
1928 | + } | ||
1929 | + } | ||
1930 | + } else { | ||
1931 | + camp.setBannerImage(""); | ||
1932 | + camp.setBannerTitle(""); | ||
1933 | + } | ||
1934 | + } catch (NullPointerException e) { | ||
1935 | + camp.setExtraFields(""); | ||
1936 | + camp.setBannerImage(""); | ||
1937 | + camp.setBannerTitle(""); | ||
1938 | + e.printStackTrace(); | ||
1939 | + } | ||
1940 | + | ||
1941 | + try { | ||
1942 | + camp.setCampaignTypeSettings(newCamp.getSettings().toString()); | ||
1943 | + } catch (NullPointerException e) { | ||
1944 | + camp.setCampaignTypeSettings(""); | ||
1945 | + e.printStackTrace(); | ||
1946 | + } | ||
1947 | + mCampaignsList.add(camp); | ||
1948 | + } | ||
1949 | + | ||
1950 | + executorShops.shutdownNow(); | ||
1951 | +// receiver.onSuccess(mCampaignsList); | ||
1952 | + future.set(mCampaignsList); | ||
1953 | + }); | ||
1954 | + } | ||
1955 | + } else { | ||
1956 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1957 | + dynatraceEvent.setEventName("custom_error_campaigns_personalized_loyalty"); | ||
1958 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1959 | +// receiver.onFailure(2); | ||
1960 | + future.set(new ArrayList<Campaign>()); | ||
1961 | + } | ||
1962 | + } else if (response.code() == 401) { | ||
1963 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
1964 | + @Override | ||
1965 | + public void onSuccess(JSONObject result) { | ||
1966 | + int status = result.optInt("status", 2); | ||
1967 | + if (status == 1) | ||
1968 | + getCampaignsPersonalizedRetro(service/*, receiver*/); | ||
1969 | + else { | ||
1970 | +// receiver.onFailure(status); | ||
1971 | + future.set(new ArrayList<Campaign>()); | ||
1972 | + } | ||
1973 | + } | ||
1974 | + | ||
1975 | + @Override | ||
1976 | + public void onFailure(int errorCode) { | ||
1977 | +// receiver.onFailure(errorCode); | ||
1978 | + future.set(new ArrayList<Campaign>()); | ||
1979 | + } | ||
1980 | + }); | ||
1981 | + } else { | ||
1982 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1983 | + dynatraceEvent.setEventName("custom_error_campaigns_personalized_loyalty"); | ||
1984 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1985 | +// receiver.onFailure(response.code()); | ||
1986 | + future.set(new ArrayList<Campaign>()); | ||
1987 | + } | ||
1988 | + } | ||
1989 | + | ||
1990 | + @Override | ||
1991 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
1992 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
1993 | + dynatraceEvent.setEventName("custom_error_campaigns_personalized_loyalty"); | ||
1994 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
1995 | +// receiver.onFailure(2); | ||
1996 | + future.set(new ArrayList<Campaign>()); | ||
1997 | + } | ||
1998 | + }); | ||
1999 | + | ||
2000 | + return future; | ||
2001 | + } | ||
2002 | + | ||
1601 | public static void getCampaignsPersonalized(WarplyGetCampaignsRequest request, final CallbackReceiver<ArrayList<Campaign>> receiver) { | 2003 | public static void getCampaignsPersonalized(WarplyGetCampaignsRequest request, final CallbackReceiver<ArrayList<Campaign>> receiver) { |
1602 | WarpUtils.log("************* WARPLY Get Campaigns Request ********************"); | 2004 | WarpUtils.log("************* WARPLY Get Campaigns Request ********************"); |
1603 | WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active"); | 2005 | WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active"); |
... | @@ -3037,7 +3439,25 @@ public class WarplyManager { | ... | @@ -3037,7 +3439,25 @@ public class WarplyManager { |
3037 | couponsetsCall.enqueue(new Callback<ResponseBody>() { | 3439 | couponsetsCall.enqueue(new Callback<ResponseBody>() { |
3038 | @Override | 3440 | @Override |
3039 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 3441 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
3040 | - callback.onResponse(call, response); | 3442 | + if (response.code() == 401) { |
3443 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
3444 | + @Override | ||
3445 | + public void onSuccess(JSONObject result) { | ||
3446 | + int status = result.optInt("status", 2); | ||
3447 | + if (status == 1) | ||
3448 | + getCouponsetsRetro(service, isFiltered, callback); | ||
3449 | + else | ||
3450 | + callback.onFailure(call, new Throwable()); | ||
3451 | + } | ||
3452 | + | ||
3453 | + @Override | ||
3454 | + public void onFailure(int errorCode) { | ||
3455 | + callback.onFailure(call, new Throwable()); | ||
3456 | + } | ||
3457 | + }); | ||
3458 | + } else { | ||
3459 | + callback.onResponse(call, response); | ||
3460 | + } | ||
3041 | } | 3461 | } |
3042 | 3462 | ||
3043 | @Override | 3463 | @Override |
... | @@ -3107,7 +3527,25 @@ public class WarplyManager { | ... | @@ -3107,7 +3527,25 @@ public class WarplyManager { |
3107 | telematicsCall.enqueue(new Callback<ResponseBody>() { | 3527 | telematicsCall.enqueue(new Callback<ResponseBody>() { |
3108 | @Override | 3528 | @Override |
3109 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 3529 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
3110 | - callback.onResponse(call, response); | 3530 | + if (response.code() == 401) { |
3531 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
3532 | + @Override | ||
3533 | + public void onSuccess(JSONObject result) { | ||
3534 | + int status = result.optInt("status", 2); | ||
3535 | + if (status == 1) | ||
3536 | + sendTelematicsData(service, accelerationTimestamps, callback); | ||
3537 | + else | ||
3538 | + callback.onFailure(call, new Throwable()); | ||
3539 | + } | ||
3540 | + | ||
3541 | + @Override | ||
3542 | + public void onFailure(int errorCode) { | ||
3543 | + callback.onFailure(call, new Throwable()); | ||
3544 | + } | ||
3545 | + }); | ||
3546 | + } else { | ||
3547 | + callback.onResponse(call, response); | ||
3548 | + } | ||
3111 | } | 3549 | } |
3112 | 3550 | ||
3113 | @Override | 3551 | @Override |
... | @@ -3145,7 +3583,25 @@ public class WarplyManager { | ... | @@ -3145,7 +3583,25 @@ public class WarplyManager { |
3145 | telematicsCall.enqueue(new Callback<ResponseBody>() { | 3583 | telematicsCall.enqueue(new Callback<ResponseBody>() { |
3146 | @Override | 3584 | @Override |
3147 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 3585 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
3148 | - callback.onResponse(call, response); | 3586 | + if (response.code() == 401) { |
3587 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
3588 | + @Override | ||
3589 | + public void onSuccess(JSONObject result) { | ||
3590 | + int status = result.optInt("status", 2); | ||
3591 | + if (status == 1) | ||
3592 | + cancelUnifiedCoupon(service, transactionID, callback); | ||
3593 | + else | ||
3594 | + callback.onFailure(call, new Throwable()); | ||
3595 | + } | ||
3596 | + | ||
3597 | + @Override | ||
3598 | + public void onFailure(int errorCode) { | ||
3599 | + callback.onFailure(call, new Throwable()); | ||
3600 | + } | ||
3601 | + }); | ||
3602 | + } else { | ||
3603 | + callback.onResponse(call, response); | ||
3604 | + } | ||
3149 | } | 3605 | } |
3150 | 3606 | ||
3151 | @Override | 3607 | @Override |
... | @@ -3182,7 +3638,25 @@ public class WarplyManager { | ... | @@ -3182,7 +3638,25 @@ public class WarplyManager { |
3182 | telematicsCall.enqueue(new Callback<ResponseBody>() { | 3638 | telematicsCall.enqueue(new Callback<ResponseBody>() { |
3183 | @Override | 3639 | @Override |
3184 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 3640 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
3185 | - callback.onResponse(call, response); | 3641 | + if (response.code() == 401) { |
3642 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
3643 | + @Override | ||
3644 | + public void onSuccess(JSONObject result) { | ||
3645 | + int status = result.optInt("status", 2); | ||
3646 | + if (status == 1) | ||
3647 | + getTelematicsHistory(service, callback); | ||
3648 | + else | ||
3649 | + callback.onFailure(call, new Throwable()); | ||
3650 | + } | ||
3651 | + | ||
3652 | + @Override | ||
3653 | + public void onFailure(int errorCode) { | ||
3654 | + callback.onFailure(call, new Throwable()); | ||
3655 | + } | ||
3656 | + }); | ||
3657 | + } else { | ||
3658 | + callback.onResponse(call, response); | ||
3659 | + } | ||
3186 | } | 3660 | } |
3187 | 3661 | ||
3188 | @Override | 3662 | @Override |
... | @@ -3220,7 +3694,25 @@ public class WarplyManager { | ... | @@ -3220,7 +3694,25 @@ public class WarplyManager { |
3220 | telematicsCall.enqueue(new Callback<ResponseBody>() { | 3694 | telematicsCall.enqueue(new Callback<ResponseBody>() { |
3221 | @Override | 3695 | @Override |
3222 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 3696 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
3223 | - callback.onResponse(call, response); | 3697 | + if (response.code() == 401) { |
3698 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
3699 | + @Override | ||
3700 | + public void onSuccess(JSONObject result) { | ||
3701 | + int status = result.optInt("status", 2); | ||
3702 | + if (status == 1) | ||
3703 | + getTripMetrics(service, tripId, callback); | ||
3704 | + else | ||
3705 | + callback.onFailure(call, new Throwable()); | ||
3706 | + } | ||
3707 | + | ||
3708 | + @Override | ||
3709 | + public void onFailure(int errorCode) { | ||
3710 | + callback.onFailure(call, new Throwable()); | ||
3711 | + } | ||
3712 | + }); | ||
3713 | + } else { | ||
3714 | + callback.onResponse(call, response); | ||
3715 | + } | ||
3224 | } | 3716 | } |
3225 | 3717 | ||
3226 | @Override | 3718 | @Override |
... | @@ -3259,7 +3751,25 @@ public class WarplyManager { | ... | @@ -3259,7 +3751,25 @@ public class WarplyManager { |
3259 | telematicsCall.enqueue(new Callback<ResponseBody>() { | 3751 | telematicsCall.enqueue(new Callback<ResponseBody>() { |
3260 | @Override | 3752 | @Override |
3261 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | 3753 | public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { |
3262 | - callback.onResponse(call, response); | 3754 | + if (response.code() == 401) { |
3755 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
3756 | + @Override | ||
3757 | + public void onSuccess(JSONObject result) { | ||
3758 | + int status = result.optInt("status", 2); | ||
3759 | + if (status == 1) | ||
3760 | + rateTrip(service, tripId, isPositive, callback); | ||
3761 | + else | ||
3762 | + callback.onFailure(call, new Throwable()); | ||
3763 | + } | ||
3764 | + | ||
3765 | + @Override | ||
3766 | + public void onFailure(int errorCode) { | ||
3767 | + callback.onFailure(call, new Throwable()); | ||
3768 | + } | ||
3769 | + }); | ||
3770 | + } else { | ||
3771 | + callback.onResponse(call, response); | ||
3772 | + } | ||
3263 | } | 3773 | } |
3264 | 3774 | ||
3265 | @Override | 3775 | @Override | ... | ... |
-
Please register or login to post a comment