Showing
5 changed files
with
174 additions
and
30 deletions
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <project version="4"> | 2 | <project version="4"> |
3 | <component name="CompilerConfiguration"> | 3 | <component name="CompilerConfiguration"> |
4 | - <bytecodeTargetLevel target="21" /> | 4 | + <bytecodeTargetLevel target="17" /> |
5 | </component> | 5 | </component> |
6 | </project> | 6 | </project> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -184,7 +184,7 @@ | ... | @@ -184,7 +184,7 @@ |
184 | </map> | 184 | </map> |
185 | </option> | 185 | </option> |
186 | </component> | 186 | </component> |
187 | - <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK"> | 187 | + <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="zulu-17" project-jdk-type="JavaSDK"> |
188 | <output url="file://$PROJECT_DIR$/build/classes" /> | 188 | <output url="file://$PROJECT_DIR$/build/classes" /> |
189 | </component> | 189 | </component> |
190 | <component name="ProjectType"> | 190 | <component name="ProjectType"> | ... | ... |
... | @@ -326,16 +326,11 @@ public class CouponShareActivity extends Activity implements View.OnClickListene | ... | @@ -326,16 +326,11 @@ public class CouponShareActivity extends Activity implements View.OnClickListene |
326 | .concat(mCoupon.getCouponsetDetails().getName())); | 326 | .concat(mCoupon.getCouponsetDetails().getName())); |
327 | mPbLoading.setVisibility(View.VISIBLE); | 327 | mPbLoading.setVisibility(View.VISIBLE); |
328 | 328 | ||
329 | - new Thread(() -> { | 329 | + WarplyManager.cosmoteCouponSharing( |
330 | - if (!Thread.currentThread().isInterrupted()) { | 330 | + mCoupon.getCoupon(), |
331 | - WarplyManager.cosmoteCouponSharing(new CosmoteCouponSharingRequest() | 331 | + mSender, |
332 | - .setCoupon(mCoupon.getCoupon()) | 332 | + mEdtReceiver.getText().toString(), |
333 | - .setSender(mSender) | 333 | + mCouponSharingCallback); |
334 | - .setReceiver(mEdtReceiver.getText().toString()) | ||
335 | - , mCouponSharingCallback); | ||
336 | - } | ||
337 | - Thread.currentThread().interrupt(); | ||
338 | - }).start(); | ||
339 | }) | 334 | }) |
340 | .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogNegative, whichNegative) -> { | 335 | .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogNegative, whichNegative) -> { |
341 | mIsSharePressed = false; | 336 | mIsSharePressed = false; |
... | @@ -360,6 +355,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene | ... | @@ -360,6 +355,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene |
360 | private final CallbackReceiver<JSONObject> mCouponSharingCallback = new CallbackReceiver<JSONObject>() { | 355 | private final CallbackReceiver<JSONObject> mCouponSharingCallback = new CallbackReceiver<JSONObject>() { |
361 | @Override | 356 | @Override |
362 | public void onSuccess(JSONObject result) { | 357 | public void onSuccess(JSONObject result) { |
358 | + mPbLoading.setVisibility(View.GONE); | ||
363 | mIsSharePressed = false; | 359 | mIsSharePressed = false; |
364 | int status = result.optInt("status", 2); | 360 | int status = result.optInt("status", 2); |
365 | String message = result.optString("msg", ""); | 361 | String message = result.optString("msg", ""); |
... | @@ -368,31 +364,24 @@ public class CouponShareActivity extends Activity implements View.OnClickListene | ... | @@ -368,31 +364,24 @@ public class CouponShareActivity extends Activity implements View.OnClickListene |
368 | // WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver); | 364 | // WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver); |
369 | WarplyManagerHelper.removeCouponItem(mCoupon); | 365 | WarplyManagerHelper.removeCouponItem(mCoupon); |
370 | /* New Addition end */ | 366 | /* New Addition end */ |
371 | - } | ||
372 | 367 | ||
373 | - runOnUiThread(() -> { | 368 | + WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); |
374 | - mPbLoading.setVisibility(View.GONE); | 369 | + couponsChanged.setChanged(true); |
375 | - if (status == 1) { | 370 | + EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); |
376 | - WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); | 371 | + |
377 | - couponsChanged.setChanged(true); | 372 | + acceptSharingDialog(); |
378 | - EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); | 373 | + } else if (status == 4) |
379 | - | 374 | + wrongNumberDialog(message); |
380 | - acceptSharingDialog(); | 375 | + else |
381 | - } else if (status == 4) | 376 | + errorSharingDialog(); |
382 | - wrongNumberDialog(message); | ||
383 | - else | ||
384 | - errorSharingDialog(); | ||
385 | - }); | ||
386 | } | 377 | } |
387 | 378 | ||
388 | @Override | 379 | @Override |
389 | public void onFailure(int errorCode) { | 380 | public void onFailure(int errorCode) { |
390 | mIsSharePressed = false; | 381 | mIsSharePressed = false; |
391 | Log.v("COUPON_SHARE", String.valueOf(errorCode)); | 382 | Log.v("COUPON_SHARE", String.valueOf(errorCode)); |
392 | - runOnUiThread(() -> { | 383 | + mPbLoading.setVisibility(View.GONE); |
393 | - mPbLoading.setVisibility(View.GONE); | 384 | + errorSharingDialog(); |
394 | - errorSharingDialog(); | ||
395 | - }); | ||
396 | } | 385 | } |
397 | }; | 386 | }; |
398 | 387 | ... | ... |
... | @@ -135,6 +135,18 @@ public interface ApiService { | ... | @@ -135,6 +135,18 @@ public interface ApiService { |
135 | @Header(WarpConstants.HEADER_SIGNATURE) String signature); | 135 | @Header(WarpConstants.HEADER_SIGNATURE) String signature); |
136 | 136 | ||
137 | @Headers("Content-Type: application/json") | 137 | @Headers("Content-Type: application/json") |
138 | + @POST("/oauth/{appUuid}/context") | ||
139 | + Call<ResponseBody> shareCoupon(@Path("appUuid") String appUuid, | ||
140 | + @Body RequestBody request, | ||
141 | + @Header(WarpConstants.HEADER_DATE) String timeStamp, | ||
142 | + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | ||
143 | + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, | ||
144 | + @Header(WarpConstants.HEADER_CHANNEL) String channel, | ||
145 | + @Header(WarpConstants.HEADER_WEB_ID) String webId, | ||
146 | + @Header(WarpConstants.HEADER_SIGNATURE) String signature, | ||
147 | + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); | ||
148 | + | ||
149 | + @Headers("Content-Type: application/json") | ||
138 | @POST("/api/mobile/v2/{appUuid}/context/") | 150 | @POST("/api/mobile/v2/{appUuid}/context/") |
139 | Call<ResponseBody> getCampaigns(@Path("appUuid") String appUuid, | 151 | Call<ResponseBody> getCampaigns(@Path("appUuid") String appUuid, |
140 | @Body RequestBody request, | 152 | @Body RequestBody request, | ... | ... |
... | @@ -5301,4 +5301,147 @@ public class WarplyManager { | ... | @@ -5301,4 +5301,147 @@ public class WarplyManager { |
5301 | } | 5301 | } |
5302 | }, executorService); | 5302 | }, executorService); |
5303 | } | 5303 | } |
5304 | + | ||
5305 | + public static void cosmoteCouponSharing(String coupon, String sender, String receiverMsisdn, final CallbackReceiver<JSONObject> receiver) { | ||
5306 | + WarpUtils.log("************* WARPLY Cosmote Coupon Sharing Request ********************"); | ||
5307 | + WarpUtils.log("[WARP Trace] WARPLY Cosmote Coupon Sharing Request is active"); | ||
5308 | + WarpUtils.log("**************************************************"); | ||
5309 | + | ||
5310 | + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); | ||
5311 | + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)); | ||
5312 | + | ||
5313 | + ListenableFuture<JSONObject> futureSharing = cosmoteSharingRetro(service, coupon, sender, receiverMsisdn); | ||
5314 | + | ||
5315 | + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureSharing); | ||
5316 | + ListenableFuture<JSONObject> mergedResultFuture = Futures.transformAsync( | ||
5317 | + allResultsFuture, | ||
5318 | + results -> { | ||
5319 | + JSONObject resultCoupons = (JSONObject) results.get(0); | ||
5320 | + return executorService.submit(() -> resultCoupons); | ||
5321 | + }, | ||
5322 | + executorService | ||
5323 | + ); | ||
5324 | + | ||
5325 | + Futures.addCallback(mergedResultFuture, new FutureCallback<JSONObject>() { | ||
5326 | + @Override | ||
5327 | + public void onSuccess(JSONObject mergedResult) { | ||
5328 | + executorService.shutdownNow(); | ||
5329 | + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult)); | ||
5330 | + } | ||
5331 | + | ||
5332 | + @Override | ||
5333 | + public void onFailure(Throwable throwable) { | ||
5334 | + executorService.shutdownNow(); | ||
5335 | + new Handler(Looper.getMainLooper()).post(() -> receiver.onFailure(2)); | ||
5336 | + } | ||
5337 | + }, executorService); | ||
5338 | + } | ||
5339 | + | ||
5340 | + private static /*void*/ ListenableFuture<JSONObject> cosmoteSharingRetro(ApiService service, String coupon, String sender, String receiver) { | ||
5341 | + SettableFuture<JSONObject> future = SettableFuture.create(); | ||
5342 | + | ||
5343 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
5344 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
5345 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
5346 | + | ||
5347 | + Map<String, Object> jsonParamsShare = new ArrayMap<>(); | ||
5348 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
5349 | + jsonParams.put("action", "share"); | ||
5350 | + jsonParams.put("coupon", coupon); | ||
5351 | + jsonParams.put("sender_msisdn", sender); | ||
5352 | + jsonParams.put("receiver_msisdn", receiver); | ||
5353 | + | ||
5354 | + jsonParamsShare.put("coupon", jsonParams); | ||
5355 | + RequestBody merchantsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsShare)).toString()); | ||
5356 | + | ||
5357 | + Call<ResponseBody> shareCall = service.shareCoupon( | ||
5358 | + WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
5359 | + merchantsRequest, | ||
5360 | + timeStamp, | ||
5361 | + "android:" + Warply.getWarplyContext().getPackageName(), | ||
5362 | + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
5363 | + "mobile", | ||
5364 | + webId, | ||
5365 | + WarpUtils.produceSignature(apiKey + timeStamp), | ||
5366 | + "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
5367 | + ); | ||
5368 | + | ||
5369 | + shareCall.enqueue(new Callback<ResponseBody>() { | ||
5370 | + @Override | ||
5371 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
5372 | + if (response.code() == 200 && response.body() != null) { | ||
5373 | + JSONObject jobjSharingResponse = null; | ||
5374 | + try { | ||
5375 | + jobjSharingResponse = new JSONObject(response.body().string()); | ||
5376 | + } catch (Exception e) { | ||
5377 | + e.printStackTrace(); | ||
5378 | + } | ||
5379 | + | ||
5380 | + if (jobjSharingResponse != null && jobjSharingResponse.has("status")) { | ||
5381 | + int status = jobjSharingResponse.optInt("status", 2); | ||
5382 | + JSONObject jResponse = new JSONObject(); | ||
5383 | + | ||
5384 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
5385 | + if (status == 1 || status == 3 || status == 4) { | ||
5386 | + dynatraceEvent.setEventName("custom_success_coupon_sharing_loyalty"); | ||
5387 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
5388 | + try { | ||
5389 | + jResponse.putOpt("status", status); | ||
5390 | + jResponse.putOpt("msg", jobjSharingResponse.optString("msg", "")); | ||
5391 | + } catch (JSONException e) { | ||
5392 | + throw new RuntimeException(e); | ||
5393 | + } | ||
5394 | + } else { | ||
5395 | + dynatraceEvent.setEventName("custom_error_coupon_sharing_loyalty"); | ||
5396 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
5397 | + try { | ||
5398 | + jResponse.putOpt("status", 2); | ||
5399 | + jResponse.putOpt("msg", jobjSharingResponse.optString("msg", "")); | ||
5400 | + } catch (JSONException e) { | ||
5401 | + throw new RuntimeException(e); | ||
5402 | + } | ||
5403 | + } | ||
5404 | + future.set(jResponse); | ||
5405 | + } else { | ||
5406 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
5407 | + dynatraceEvent.setEventName("custom_error_coupon_sharing_loyalty"); | ||
5408 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
5409 | + future.set(new JSONObject()); | ||
5410 | + } | ||
5411 | + } else if (response.code() == 401) { | ||
5412 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
5413 | + @Override | ||
5414 | + public void onSuccess(JSONObject result) { | ||
5415 | + int status = result.optInt("status", 2); | ||
5416 | + if (status == 1) | ||
5417 | + cosmoteSharingRetro(service, coupon, sender, receiver); | ||
5418 | + else { | ||
5419 | + future.setException(new Throwable()); | ||
5420 | + } | ||
5421 | + } | ||
5422 | + | ||
5423 | + @Override | ||
5424 | + public void onFailure(int errorCode) { | ||
5425 | + future.setException(new Throwable()); | ||
5426 | + } | ||
5427 | + }); | ||
5428 | + } else { | ||
5429 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
5430 | + dynatraceEvent.setEventName("custom_error_coupon_sharing_loyalty"); | ||
5431 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
5432 | + future.setException(new Throwable()); | ||
5433 | + } | ||
5434 | + } | ||
5435 | + | ||
5436 | + @Override | ||
5437 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
5438 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
5439 | + dynatraceEvent.setEventName("custom_error_coupon_sharing_loyalty"); | ||
5440 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
5441 | + future.setException(new Throwable()); | ||
5442 | + } | ||
5443 | + }); | ||
5444 | + | ||
5445 | + return future; | ||
5446 | + } | ||
5304 | } | 5447 | } | ... | ... |
-
Please register or login to post a comment