Panagiotis Triantafyllou

sm deals map fixes

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4.6rc65'
PUBLISH_VERSION = '4.5.4.6rc66'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -36,7 +36,11 @@ import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterManager;
import org.json.JSONArray;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
import ly.warp.sdk.R;
......@@ -73,7 +77,7 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe
private SupportMapFragment mMapView;
private MerchantList mMerchantList = new MerchantList();
private AlertDialog mAlertDialogNoShopsAvailable;
private Merchant mMerchant;
private Merchant mMerchant, mMerchantParent;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -194,16 +198,8 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe
}).start();
} else {
ArrayList<String> catuuids = new ArrayList<>();
catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "" : "adcace6cab6049c7b7271bc85bc2b26d"); //TODO: add live cat uuid
new Thread(() -> {
if (!Thread.currentThread().isInterrupted()) {
WarplyManager.getMerchantsMultilingual(new WarplyMerchantsRequest()
.setIsMultilingual(true)
.setCategories(catuuids)
, mMerchantsCallback);
}
Thread.currentThread().interrupt();
}).start();
catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "2a6adade35f1484994a3d4c8f006b909" : "adcace6cab6049c7b7271bc85bc2b26d");
WarplyManager.getMerchantsMultilingual(catuuids, mMerchantsDealsCallback);
}
}
......@@ -357,6 +353,70 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe
}
};
private final CallbackReceiver<MerchantList> mMerchantsDealsCallback = new CallbackReceiver<MerchantList>() {
@Override
public void onSuccess(MerchantList result) {
if (result.size() == 0) {
showNoShopsAvailableDialog();
return;
}
mMerchantList.clear();
mMerchantList.addAll(result);
// if (mClusterManager != null) {
// mMap.clear();
// mClusterManager.clearItems();
// if (result != null) {
// mClusterManager.addItems(result);
// }
// mClusterManager.cluster();
// }
int nonNullCoords = 0;
for (Merchant merchCoords : result) {
if (merchCoords.getLatitude() != 0.0 && merchCoords.getLongitude() != 0.0) {
nonNullCoords++;
} else {
mMerchantParent = merchCoords;
}
}
if (nonNullCoords == 0) {
showNoShopsAvailableDialog();
return;
}
if (mMerchantParent != null) {
for (Merchant merch : result) {
merch.setImg_preview(mMerchantParent.getImgPreview());
if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(merch.getLatitude(), merch.getLongitude()))
.anchor(0.5f, 0.5f)
.title(merch.getTitle())
.snippet(merch.getUuid()));
}
}
} else {
for (Merchant merch : result) {
if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(merch.getLatitude(), merch.getLongitude()))
.anchor(0.5f, 0.5f)
.title(merch.getTitle())
.snippet(merch.getUuid()));
}
}
}
}
@Override
public void onFailure(int errorCode) {
Log.v("SHOPS_ACTIVITY", String.valueOf(errorCode));
}
};
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
......
......@@ -71,7 +71,7 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic
private SupportMapFragment mSupportMapFragment;
private MerchantList mMerchantList = new MerchantList();
private AlertDialog mAlertDialogNoShopsAvailable;
private Merchant mMerchant;
private Merchant mMerchant, mMerchantParent;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -195,16 +195,8 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic
}).start();
} else {
ArrayList<String> catuuids = new ArrayList<>();
catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "" : "adcace6cab6049c7b7271bc85bc2b26d"); //TODO: add live cat uuid
new Thread(() -> {
if (!Thread.currentThread().isInterrupted()) {
WarplyManager.getMerchantsMultilingual(new WarplyMerchantsRequest()
.setIsMultilingual(true)
.setCategories(catuuids)
, mMerchantsCallback);
}
Thread.currentThread().interrupt();
}).start();
catuuids.add(WarplyProperty.getAppUuid(this).equals("0086a2088301440792091b9f814c2267") ? "2a6adade35f1484994a3d4c8f006b909" : "adcace6cab6049c7b7271bc85bc2b26d");
WarplyManager.getMerchantsMultilingual(catuuids, mMerchantsDealsCallback);
}
}
......@@ -375,6 +367,72 @@ public class ShopsHuaweiActivity extends FragmentActivity implements View.OnClic
}
};
private final CallbackReceiver<MerchantList> mMerchantsDealsCallback = new CallbackReceiver<MerchantList>() {
@Override
public void onSuccess(MerchantList result) {
if (result.size() == 0) {
showNoShopsAvailableDialog();
return;
}
mMerchantList.clear();
mMerchantList.addAll(result);
// if (mClusterManager != null) {
// mMap.clear();
// mClusterManager.clearItems();
// if (result != null) {
// mClusterManager.addItems(result);
// }
// mClusterManager.cluster();
// }
int nonNullCoords = 0;
for (Merchant merchCoords : result) {
if (merchCoords.getLatitude() != 0.0 && merchCoords.getLongitude() != 0.0) {
nonNullCoords++;
} else {
mMerchantParent = merchCoords;
}
}
if (nonNullCoords == 0) {
showNoShopsAvailableDialog();
return;
}
if (mMerchantParent != null) {
for (Merchant merch : result) {
merch.setImg_preview(mMerchantParent.getImgPreview());
if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(merch.getLatitude(), merch.getLongitude()))
.anchor(0.5f, 0.5f)
.title(merch.getTitle())
.snippet(merch.getUuid())
.clusterable(true));
}
}
} else {
for (Merchant merch : result) {
if (merch.getLatitude() != 0.0 && merch.getLongitude() != 0.0) {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(merch.getLatitude(), merch.getLongitude()))
.anchor(0.5f, 0.5f)
.title(merch.getTitle())
.snippet(merch.getUuid())
.clusterable(true));
}
}
}
}
@Override
public void onFailure(int errorCode) {
Log.v("SHOPS_ACTIVITY", String.valueOf(errorCode));
}
};
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
......
......@@ -2066,6 +2066,76 @@ public class WarplyManager {
});
}
public static void getMerchantsMultilingual(ArrayList<String> catuuids, final CallbackReceiver<MerchantList> receiver) {
WarpUtils.log("************* WARPLY Merchants Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Merchants Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
getMerchantsRetro(service, catuuids, new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseMerchants) {
if (responseMerchants.code() == 200 && responseMerchants.body() != null) {
JSONObject jobjMerchantsResponse = null;
try {
jobjMerchantsResponse = new JSONObject(responseMerchants.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjMerchantsResponse != null && jobjMerchantsResponse.has("status") && jobjMerchantsResponse.optString("status", "2").equals("1")) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
JSONArray jMerchantsBody = null;
try {
jMerchantsBody = jobjMerchantsResponse.optJSONObject("context").optJSONObject("MAPP_SHOPS").optJSONArray("result");
} catch (Exception e) {
e.printStackTrace();
}
if (jMerchantsBody != null) {
MerchantList mMerchantList = new MerchantList();
final ExecutorService executorShops = Executors.newFixedThreadPool(1);
JSONArray finalMerchantsJBody = jMerchantsBody;
executorShops.submit(() -> {
for (int i = 0; i < finalMerchantsJBody.length(); ++i) {
mMerchantList.add(new Merchant(finalMerchantsJBody.optJSONObject(i)));
}
new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mMerchantList));
executorShops.shutdownNow();
});
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(responseMerchants.code());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
});
}
public static void getUserCouponsWithCouponsets(final CallbackReceiver<CouponList> receiver) {
WarpUtils.log("************* WARPLY User Coupons Request ********************");
WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
......@@ -2424,6 +2494,49 @@ public class WarplyManager {
});
}
private static void getMerchantsRetro(ApiService service, ArrayList<String> catuuids, Callback<ResponseBody> callback) {
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParamsShops = new ArrayMap<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "retrieve_multilingual");
jsonParams.put("categories", new JSONArray(catuuids));
jsonParams.put("active", true);
jsonParams.put("location", null);
jsonParams.put("parent_uuids", null);
jsonParams.put("tags", null);
jsonParams.put("default_shown", null);
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParamsShops.put("shops", jsonParams);
RequestBody merchantsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsShops)).toString());
Call<ResponseBody> merchantsCall = service.getMerchants(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
merchantsRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp)
);
merchantsCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
callback.onResponse(call, response);
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
callback.onFailure(call, t);
}
});
}
private static void getUserCouponsRetro(ApiService service, Callback<ResponseBody> callback) {
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
......