Showing
4 changed files
with
254 additions
and
23 deletions
| ... | @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' | ... | @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' |
| 2 | 2 | ||
| 3 | ext { | 3 | ext { |
| 4 | PUBLISH_GROUP_ID = 'ly.warp' | 4 | PUBLISH_GROUP_ID = 'ly.warp' |
| 5 | - PUBLISH_VERSION = '4.5.4.6rc65' | 5 | + PUBLISH_VERSION = '4.5.4.6rc66' |
| 6 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' | 6 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' |
| 7 | } | 7 | } |
| 8 | 8 | ... | ... |
| ... | @@ -36,7 +36,11 @@ import com.google.android.material.bottomsheet.BottomSheetDialog; | ... | @@ -36,7 +36,11 @@ import com.google.android.material.bottomsheet.BottomSheetDialog; |
| 36 | import com.google.maps.android.clustering.Cluster; | 36 | import com.google.maps.android.clustering.Cluster; |
| 37 | import com.google.maps.android.clustering.ClusterManager; | 37 | import com.google.maps.android.clustering.ClusterManager; |
| 38 | 38 | ||
| 39 | +import org.json.JSONArray; | ||
| 40 | + | ||
| 39 | import java.util.ArrayList; | 41 | import java.util.ArrayList; |
| 42 | +import java.util.concurrent.ExecutorService; | ||
| 43 | +import java.util.concurrent.Executors; | ||
| 40 | 44 | ||
| 41 | import io.github.inflationx.viewpump.ViewPumpContextWrapper; | 45 | import io.github.inflationx.viewpump.ViewPumpContextWrapper; |
| 42 | import ly.warp.sdk.R; | 46 | import ly.warp.sdk.R; |
| ... | @@ -73,7 +77,7 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe | ... | @@ -73,7 +77,7 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe |
| 73 | private SupportMapFragment mMapView; | 77 | private SupportMapFragment mMapView; |
| 74 | private MerchantList mMerchantList = new MerchantList(); | 78 | private MerchantList mMerchantList = new MerchantList(); |
| 75 | private AlertDialog mAlertDialogNoShopsAvailable; | 79 | private AlertDialog mAlertDialogNoShopsAvailable; |
| 76 | - private Merchant mMerchant; | 80 | + private Merchant mMerchant, mMerchantParent; |
| 77 | 81 | ||
| 78 | // =========================================================== | 82 | // =========================================================== |
| 79 | // Methods for/from SuperClass/Interfaces | 83 | // Methods for/from SuperClass/Interfaces |
| ... | @@ -194,16 +198,8 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe | ... | @@ -194,16 +198,8 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe |
| 194 | }).start(); | 198 | }).start(); |
| 195 | } else { | 199 | } else { |
| 196 | ArrayList<String> catuuids = new ArrayList<>(); | 200 | ArrayList<String> catuuids = new ArrayList<>(); |
| 197 | - catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "" : "adcace6cab6049c7b7271bc85bc2b26d"); //TODO: add live cat uuid | 201 | + catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "2a6adade35f1484994a3d4c8f006b909" : "adcace6cab6049c7b7271bc85bc2b26d"); |
| 198 | - new Thread(() -> { | 202 | + WarplyManager.getMerchantsMultilingual(catuuids, mMerchantsDealsCallback); |
| 199 | - if (!Thread.currentThread().isInterrupted()) { | ||
| 200 | - WarplyManager.getMerchantsMultilingual(new WarplyMerchantsRequest() | ||
| 201 | - .setIsMultilingual(true) | ||
| 202 | - .setCategories(catuuids) | ||
| 203 | - , mMerchantsCallback); | ||
| 204 | - } | ||
| 205 | - Thread.currentThread().interrupt(); | ||
| 206 | - }).start(); | ||
| 207 | } | 203 | } |
| 208 | } | 204 | } |
| 209 | 205 | ||
| ... | @@ -357,6 +353,70 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe | ... | @@ -357,6 +353,70 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe |
| 357 | } | 353 | } |
| 358 | }; | 354 | }; |
| 359 | 355 | ||
| 356 | + private final CallbackReceiver<MerchantList> mMerchantsDealsCallback = new CallbackReceiver<MerchantList>() { | ||
| 357 | + @Override | ||
| 358 | + public void onSuccess(MerchantList result) { | ||
| 359 | + if (result.size() == 0) { | ||
| 360 | + showNoShopsAvailableDialog(); | ||
| 361 | + return; | ||
| 362 | + } | ||
| 363 | + | ||
| 364 | + mMerchantList.clear(); | ||
| 365 | + mMerchantList.addAll(result); | ||
| 366 | + | ||
| 367 | + // if (mClusterManager != null) { | ||
| 368 | +// mMap.clear(); | ||
| 369 | +// mClusterManager.clearItems(); | ||
| 370 | +// if (result != null) { | ||
| 371 | +// mClusterManager.addItems(result); | ||
| 372 | +// } | ||
| 373 | +// mClusterManager.cluster(); | ||
| 374 | +// } | ||
| 375 | + | ||
| 376 | + int nonNullCoords = 0; | ||
| 377 | + for (Merchant merchCoords : result) { | ||
| 378 | + if (merchCoords.getLatitude() != 0.0 && merchCoords.getLongitude() != 0.0) { | ||
| 379 | + nonNullCoords++; | ||
| 380 | + } else { | ||
| 381 | + mMerchantParent = merchCoords; | ||
| 382 | + } | ||
| 383 | + } | ||
| 384 | + | ||
| 385 | + if (nonNullCoords == 0) { | ||
| 386 | + showNoShopsAvailableDialog(); | ||
| 387 | + return; | ||
| 388 | + } | ||
| 389 | + | ||
| 390 | + if (mMerchantParent != null) { | ||
| 391 | + for (Merchant merch : result) { | ||
| 392 | + merch.setImg_preview(mMerchantParent.getImgPreview()); | ||
| 393 | + if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) { | ||
| 394 | + mMap.addMarker(new MarkerOptions() | ||
| 395 | + .position(new LatLng(merch.getLatitude(), merch.getLongitude())) | ||
| 396 | + .anchor(0.5f, 0.5f) | ||
| 397 | + .title(merch.getTitle()) | ||
| 398 | + .snippet(merch.getUuid())); | ||
| 399 | + } | ||
| 400 | + } | ||
| 401 | + } else { | ||
| 402 | + for (Merchant merch : result) { | ||
| 403 | + if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) { | ||
| 404 | + mMap.addMarker(new MarkerOptions() | ||
| 405 | + .position(new LatLng(merch.getLatitude(), merch.getLongitude())) | ||
| 406 | + .anchor(0.5f, 0.5f) | ||
| 407 | + .title(merch.getTitle()) | ||
| 408 | + .snippet(merch.getUuid())); | ||
| 409 | + } | ||
| 410 | + } | ||
| 411 | + } | ||
| 412 | + } | ||
| 413 | + | ||
| 414 | + @Override | ||
| 415 | + public void onFailure(int errorCode) { | ||
| 416 | + Log.v("SHOPS_ACTIVITY", String.valueOf(errorCode)); | ||
| 417 | + } | ||
| 418 | + }; | ||
| 419 | + | ||
| 360 | // =========================================================== | 420 | // =========================================================== |
| 361 | // Inner and Anonymous Classes | 421 | // Inner and Anonymous Classes |
| 362 | // =========================================================== | 422 | // =========================================================== | ... | ... |
| ... | @@ -71,7 +71,7 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic | ... | @@ -71,7 +71,7 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic |
| 71 | private SupportMapFragment mSupportMapFragment; | 71 | private SupportMapFragment mSupportMapFragment; |
| 72 | private MerchantList mMerchantList = new MerchantList(); | 72 | private MerchantList mMerchantList = new MerchantList(); |
| 73 | private AlertDialog mAlertDialogNoShopsAvailable; | 73 | private AlertDialog mAlertDialogNoShopsAvailable; |
| 74 | - private Merchant mMerchant; | 74 | + private Merchant mMerchant, mMerchantParent; |
| 75 | 75 | ||
| 76 | // =========================================================== | 76 | // =========================================================== |
| 77 | // Methods for/from SuperClass/Interfaces | 77 | // Methods for/from SuperClass/Interfaces |
| ... | @@ -195,16 +195,8 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic | ... | @@ -195,16 +195,8 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic |
| 195 | }).start(); | 195 | }).start(); |
| 196 | } else { | 196 | } else { |
| 197 | ArrayList<String> catuuids = new ArrayList<>(); | 197 | ArrayList<String> catuuids = new ArrayList<>(); |
| 198 | - catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "" : "adcace6cab6049c7b7271bc85bc2b26d"); //TODO: add live cat uuid | 198 | + catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "2a6adade35f1484994a3d4c8f006b909" : "adcace6cab6049c7b7271bc85bc2b26d"); |
| 199 | - new Thread(() -> { | 199 | + WarplyManager.getMerchantsMultilingual(catuuids, mMerchantsDealsCallback); |
| 200 | - if (!Thread.currentThread().isInterrupted()) { | ||
| 201 | - WarplyManager.getMerchantsMultilingual(new WarplyMerchantsRequest() | ||
| 202 | - .setIsMultilingual(true) | ||
| 203 | - .setCategories(catuuids) | ||
| 204 | - , mMerchantsCallback); | ||
| 205 | - } | ||
| 206 | - Thread.currentThread().interrupt(); | ||
| 207 | - }).start(); | ||
| 208 | } | 200 | } |
| 209 | } | 201 | } |
| 210 | 202 | ||
| ... | @@ -375,6 +367,72 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic | ... | @@ -375,6 +367,72 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic |
| 375 | } | 367 | } |
| 376 | }; | 368 | }; |
| 377 | 369 | ||
| 370 | + private final CallbackReceiver<MerchantList> mMerchantsDealsCallback = new CallbackReceiver<MerchantList>() { | ||
| 371 | + @Override | ||
| 372 | + public void onSuccess(MerchantList result) { | ||
| 373 | + if (result.size() == 0) { | ||
| 374 | + showNoShopsAvailableDialog(); | ||
| 375 | + return; | ||
| 376 | + } | ||
| 377 | + | ||
| 378 | + mMerchantList.clear(); | ||
| 379 | + mMerchantList.addAll(result); | ||
| 380 | + | ||
| 381 | + // if (mClusterManager != null) { | ||
| 382 | +// mMap.clear(); | ||
| 383 | +// mClusterManager.clearItems(); | ||
| 384 | +// if (result != null) { | ||
| 385 | +// mClusterManager.addItems(result); | ||
| 386 | +// } | ||
| 387 | +// mClusterManager.cluster(); | ||
| 388 | +// } | ||
| 389 | + | ||
| 390 | + int nonNullCoords = 0; | ||
| 391 | + for (Merchant merchCoords : result) { | ||
| 392 | + if (merchCoords.getLatitude() != 0.0 && merchCoords.getLongitude() != 0.0) { | ||
| 393 | + nonNullCoords++; | ||
| 394 | + } else { | ||
| 395 | + mMerchantParent = merchCoords; | ||
| 396 | + } | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + if (nonNullCoords == 0) { | ||
| 400 | + showNoShopsAvailableDialog(); | ||
| 401 | + return; | ||
| 402 | + } | ||
| 403 | + | ||
| 404 | + if (mMerchantParent != null) { | ||
| 405 | + for (Merchant merch : result) { | ||
| 406 | + merch.setImg_preview(mMerchantParent.getImgPreview()); | ||
| 407 | + if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) { | ||
| 408 | + mMap.addMarker(new MarkerOptions() | ||
| 409 | + .position(new LatLng(merch.getLatitude(), merch.getLongitude())) | ||
| 410 | + .anchor(0.5f, 0.5f) | ||
| 411 | + .title(merch.getTitle()) | ||
| 412 | + .snippet(merch.getUuid()) | ||
| 413 | + .clusterable(true)); | ||
| 414 | + } | ||
| 415 | + } | ||
| 416 | + } else { | ||
| 417 | + for (Merchant merch : result) { | ||
| 418 | + if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) { | ||
| 419 | + mMap.addMarker(new MarkerOptions() | ||
| 420 | + .position(new LatLng(merch.getLatitude(), merch.getLongitude())) | ||
| 421 | + .anchor(0.5f, 0.5f) | ||
| 422 | + .title(merch.getTitle()) | ||
| 423 | + .snippet(merch.getUuid()) | ||
| 424 | + .clusterable(true)); | ||
| 425 | + } | ||
| 426 | + } | ||
| 427 | + } | ||
| 428 | + } | ||
| 429 | + | ||
| 430 | + @Override | ||
| 431 | + public void onFailure(int errorCode) { | ||
| 432 | + Log.v("SHOPS_ACTIVITY", String.valueOf(errorCode)); | ||
| 433 | + } | ||
| 434 | + }; | ||
| 435 | + | ||
| 378 | // =========================================================== | 436 | // =========================================================== |
| 379 | // Inner and Anonymous Classes | 437 | // Inner and Anonymous Classes |
| 380 | // =========================================================== | 438 | // =========================================================== | ... | ... |
| ... | @@ -2066,6 +2066,76 @@ public class WarplyManager { | ... | @@ -2066,6 +2066,76 @@ public class WarplyManager { |
| 2066 | }); | 2066 | }); |
| 2067 | } | 2067 | } |
| 2068 | 2068 | ||
| 2069 | + public static void getMerchantsMultilingual(ArrayList<String> catuuids, final CallbackReceiver<MerchantList> receiver) { | ||
| 2070 | + WarpUtils.log("************* WARPLY Merchants Request ********************"); | ||
| 2071 | + WarpUtils.log("[WARP Trace] WARPLY Merchants Request is active"); | ||
| 2072 | + WarpUtils.log("**************************************************"); | ||
| 2073 | + | ||
| 2074 | + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); | ||
| 2075 | + | ||
| 2076 | + getMerchantsRetro(service, catuuids, new Callback<ResponseBody>() { | ||
| 2077 | + @Override | ||
| 2078 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) { | ||
| 2079 | + if (responseMerchants.code() == 200 && responseMerchants.body() != null) { | ||
| 2080 | + JSONObject jobjMerchantsResponse = null; | ||
| 2081 | + try { | ||
| 2082 | + jobjMerchantsResponse = new JSONObject(responseMerchants.body().string()); | ||
| 2083 | + } catch (Exception e) { | ||
| 2084 | + e.printStackTrace(); | ||
| 2085 | + } | ||
| 2086 | + | ||
| 2087 | + if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) { | ||
| 2088 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 2089 | + dynatraceEvent.setEventName("custom_success_shops_loyalty"); | ||
| 2090 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 2091 | + | ||
| 2092 | + JSONArray jMerchantsBody = null; | ||
| 2093 | + try { | ||
| 2094 | + jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result"); | ||
| 2095 | + } catch (Exception e) { | ||
| 2096 | + e.printStackTrace(); | ||
| 2097 | + } | ||
| 2098 | + | ||
| 2099 | + if (jMerchantsBody != null) { | ||
| 2100 | + MerchantList mMerchantList = new MerchantList(); | ||
| 2101 | + | ||
| 2102 | + final ExecutorService executorShops = Executors.newFixedThreadPool(1); | ||
| 2103 | + JSONArray finalMerchantsJBody = jMerchantsBody; | ||
| 2104 | + executorShops.submit(() -> { | ||
| 2105 | + for (int i = 0; i < finalMerchantsJBody.length(); ++i) { | ||
| 2106 | + mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i))); | ||
| 2107 | + } | ||
| 2108 | + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mMerchantList)); | ||
| 2109 | + executorShops.shutdownNow(); | ||
| 2110 | + }); | ||
| 2111 | + } | ||
| 2112 | + } else { | ||
| 2113 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 2114 | + dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 2115 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 2116 | + | ||
| 2117 | + receiver.onFailure(2); | ||
| 2118 | + } | ||
| 2119 | + } else { | ||
| 2120 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 2121 | + dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 2122 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 2123 | + | ||
| 2124 | + receiver.onFailure(responseMerchants.code()); | ||
| 2125 | + } | ||
| 2126 | + } | ||
| 2127 | + | ||
| 2128 | + @Override | ||
| 2129 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 2130 | + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | ||
| 2131 | + dynatraceEvent.setEventName("custom_error_shops_loyalty"); | ||
| 2132 | + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent)); | ||
| 2133 | + | ||
| 2134 | + receiver.onFailure(2); | ||
| 2135 | + } | ||
| 2136 | + }); | ||
| 2137 | + } | ||
| 2138 | + | ||
| 2069 | public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) { | 2139 | public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) { |
| 2070 | WarpUtils.log("************* WARPLY User Coupons Request ********************"); | 2140 | WarpUtils.log("************* WARPLY User Coupons Request ********************"); |
| 2071 | WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active"); | 2141 | WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active"); |
| ... | @@ -2424,6 +2494,49 @@ public class WarplyManager { | ... | @@ -2424,6 +2494,49 @@ public class WarplyManager { |
| 2424 | }); | 2494 | }); |
| 2425 | } | 2495 | } |
| 2426 | 2496 | ||
| 2497 | + private static void getMerchantsRetro(ApiService service, ArrayList<String> catuuids, Callback<ResponseBody> callback) { | ||
| 2498 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
| 2499 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
| 2500 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
| 2501 | + | ||
| 2502 | + Map<String, Object> jsonParamsShops = new ArrayMap<>(); | ||
| 2503 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
| 2504 | + jsonParams.put("action", "retrieve_multilingual"); | ||
| 2505 | + jsonParams.put("categories", new JSONArray(catuuids)); | ||
| 2506 | + jsonParams.put("active", true); | ||
| 2507 | + jsonParams.put("location", null); | ||
| 2508 | + jsonParams.put("parent_uuids", null); | ||
| 2509 | + jsonParams.put("tags", null); | ||
| 2510 | + jsonParams.put("default_shown", null); | ||
| 2511 | + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); | ||
| 2512 | + | ||
| 2513 | + jsonParamsShops.put("shops", jsonParams); | ||
| 2514 | + RequestBody merchantsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsShops)).toString()); | ||
| 2515 | + | ||
| 2516 | + Call<ResponseBody> merchantsCall = service.getMerchants( | ||
| 2517 | + WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
| 2518 | + merchantsRequest, | ||
| 2519 | + timeStamp, | ||
| 2520 | + "android:" + Warply.getWarplyContext().getPackageName(), | ||
| 2521 | + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
| 2522 | + "mobile", | ||
| 2523 | + webId, | ||
| 2524 | + WarpUtils.produceSignature(apiKey + timeStamp) | ||
| 2525 | + ); | ||
| 2526 | + | ||
| 2527 | + merchantsCall.enqueue(new Callback<ResponseBody>() { | ||
| 2528 | + @Override | ||
| 2529 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
| 2530 | + callback.onResponse(call, response); | ||
| 2531 | + } | ||
| 2532 | + | ||
| 2533 | + @Override | ||
| 2534 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 2535 | + callback.onFailure(call, t); | ||
| 2536 | + } | ||
| 2537 | + }); | ||
| 2538 | + } | ||
| 2539 | + | ||
| 2427 | private static void getUserCouponsRetro(ApiService service, Callback<ResponseBody> callback) { | 2540 | private static void getUserCouponsRetro(ApiService service, Callback<ResponseBody> callback) { |
| 2428 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | 2541 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); |
| 2429 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | 2542 | String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ... | ... |
-
Please register or login to post a comment