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"> | ... | ... |
| ... | @@ -404,16 +404,11 @@ public class CouponShareActivity extends Activity implements View.OnClickListene | ... | @@ -404,16 +404,11 @@ public class CouponShareActivity extends Activity implements View.OnClickListene |
| 404 | .concat(mCoupon.getCouponsetDetails().getName())); | 404 | .concat(mCoupon.getCouponsetDetails().getName())); |
| 405 | mPbLoading.setVisibility(View.VISIBLE); | 405 | mPbLoading.setVisibility(View.VISIBLE); |
| 406 | 406 | ||
| 407 | - new Thread(() -> { | 407 | + WarplyManager.cosmoteCouponSharing( |
| 408 | - if (!Thread.currentThread().isInterrupted()) { | 408 | + mCoupon.getCoupon(), |
| 409 | - WarplyManager.cosmoteCouponSharing(new CosmoteCouponSharingRequest() | 409 | + mSender, |
| 410 | - .setCoupon(mCoupon.getCoupon()) | 410 | + mEdtReceiver.getText().toString(), |
| 411 | - .setSender(mSender) | 411 | + mCouponSharingCallback); |
| 412 | - .setReceiver(mEdtReceiver.getText().toString()) | ||
| 413 | - , mCouponSharingCallback); | ||
| 414 | - } | ||
| 415 | - Thread.currentThread().interrupt(); | ||
| 416 | - }).start(); | ||
| 417 | }) | 412 | }) |
| 418 | .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogNegative, whichNegative) -> { | 413 | .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogNegative, whichNegative) -> { |
| 419 | mIsSharePressed = false; | 414 | mIsSharePressed = false; |
| ... | @@ -438,6 +433,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene | ... | @@ -438,6 +433,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene |
| 438 | private final CallbackReceiver<JSONObject> mCouponSharingCallback = new CallbackReceiver<JSONObject>() { | 433 | private final CallbackReceiver<JSONObject> mCouponSharingCallback = new CallbackReceiver<JSONObject>() { |
| 439 | @Override | 434 | @Override |
| 440 | public void onSuccess(JSONObject result) { | 435 | public void onSuccess(JSONObject result) { |
| 436 | + mPbLoading.setVisibility(View.GONE); | ||
| 441 | mIsSharePressed = false; | 437 | mIsSharePressed = false; |
| 442 | int status = result.optInt("status", 2); | 438 | int status = result.optInt("status", 2); |
| 443 | String message = result.optString("msg", ""); | 439 | String message = result.optString("msg", ""); |
| ... | @@ -446,31 +442,24 @@ public class CouponShareActivity extends Activity implements View.OnClickListene | ... | @@ -446,31 +442,24 @@ public class CouponShareActivity extends Activity implements View.OnClickListene |
| 446 | // WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver); | 442 | // WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver); |
| 447 | WarplyManagerHelper.removeCouponItem(mCoupon); | 443 | WarplyManagerHelper.removeCouponItem(mCoupon); |
| 448 | /* New Addition end */ | 444 | /* New Addition end */ |
| 449 | - } | ||
| 450 | 445 | ||
| 451 | - runOnUiThread(() -> { | 446 | + WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); |
| 452 | - mPbLoading.setVisibility(View.GONE); | 447 | + couponsChanged.setChanged(true); |
| 453 | - if (status == 1) { | 448 | + EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); |
| 454 | - WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); | 449 | + |
| 455 | - couponsChanged.setChanged(true); | 450 | + acceptSharingDialog(); |
| 456 | - EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); | 451 | + } else if (status == 4) |
| 457 | - | 452 | + wrongNumberDialog(message); |
| 458 | - acceptSharingDialog(); | 453 | + else |
| 459 | - } else if (status == 4) | 454 | + errorSharingDialog(); |
| 460 | - wrongNumberDialog(message); | ||
| 461 | - else | ||
| 462 | - errorSharingDialog(); | ||
| 463 | - }); | ||
| 464 | } | 455 | } |
| 465 | 456 | ||
| 466 | @Override | 457 | @Override |
| 467 | public void onFailure(int errorCode) { | 458 | public void onFailure(int errorCode) { |
| 468 | mIsSharePressed = false; | 459 | mIsSharePressed = false; |
| 469 | Log.v("COUPON_SHARE", String.valueOf(errorCode)); | 460 | Log.v("COUPON_SHARE", String.valueOf(errorCode)); |
| 470 | - runOnUiThread(() -> { | 461 | + mPbLoading.setVisibility(View.GONE); |
| 471 | - mPbLoading.setVisibility(View.GONE); | 462 | + errorSharingDialog(); |
| 472 | - errorSharingDialog(); | ||
| 473 | - }); | ||
| 474 | } | 463 | } |
| 475 | }; | 464 | }; |
| 476 | 465 | ... | ... |
| ... | @@ -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