Panagiotis Triantafyllou

map data request

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.5.4r10'
PUBLISH_VERSION = '4.5.5.4r11'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -23,7 +23,6 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.UnifiedCoupon;
import ly.warp.sdk.io.request.WarplyGetCampaignsRequest;
import ly.warp.sdk.utils.managers.WarplyManager;
public class BaseFragmentActivity extends FragmentActivity implements NavigationBarView.OnItemSelectedListener {
......
......@@ -11,18 +11,18 @@ import java.util.ArrayList;
*/
public class UnifiedCampaignModel implements Serializable {
private String id, title, affiliatedId, shortDescription, longDescription,
private String id, title, shortDescription, longDescription,
logoImagePath, bigLogoImagePath, dayText, imagePath, bigImagePath,
markerImagePath, details;
private int position, days;
markerImagePath, details, couponsetUuid, storeId;
private int position, affiliatedId;
private ArrayList<String> days;
private boolean isHot;
private ArrayList<UnifiedCampaignLocation> locations;
public UnifiedCampaignModel() {
this.id = "";
this.title = "";
this.affiliatedId = "";
this.affiliatedId = 0;
this.shortDescription = "";
this.longDescription = "";
this.logoImagePath = "";
......@@ -33,27 +33,39 @@ public class UnifiedCampaignModel implements Serializable {
this.markerImagePath = "";
this.details = "";
this.position = 0;
this.days = 0;
this.days = new ArrayList<String>();
this.isHot = false;
this.locations = new ArrayList<UnifiedCampaignLocation>();
this.couponsetUuid = "";
this.storeId = "";
}
public UnifiedCampaignModel(JSONObject jobj) {
if (jobj != null) {
this.couponsetUuid = jobj.optString("COUPONSET_UUID");
this.id = jobj.optString("id", "");
this.title = jobj.optString("title", "");
this.affiliatedId = jobj.optString("affiliatedId", "");
this.shortDescription = jobj.optString("shortDescription", "");
this.longDescription = jobj.optString("longDescription", "");
this.logoImagePath = jobj.optString("logoImagePath", "");
this.bigLogoImagePath = jobj.optString("bigLogoImagePath", "");
this.dayText = jobj.optString("dayText", "");
this.imagePath = jobj.optString("imagePath", "");
this.bigImagePath = jobj.optString("bigImagePath", "");
this.markerImagePath = jobj.optString("markerImagePath", "");
this.details = jobj.optString("details", "");
this.position = jobj.optInt("position", 0);
this.days = jobj.optInt("days", 0);
this.title = jobj.optString("title");
this.affiliatedId = jobj.optInt("affiliatedId", 0);
this.shortDescription = jobj.optString("shortDescription");
this.longDescription = jobj.optString("longDescription");
this.logoImagePath = jobj.optString("logoImagePath");
this.bigLogoImagePath = jobj.optString("bigLogoImagePath");
this.dayText = jobj.optString("dayText");
this.imagePath = jobj.optString("imagePath");
this.bigImagePath = jobj.optString("bigImagePath");
this.markerImagePath = jobj.optString("markerImagePath");
this.details = jobj.optString("details");
this.position = jobj.optInt("position");
this.days = new ArrayList<>();
JSONArray tempDays = new JSONArray();
tempDays = jobj.optJSONArray("days");
if (tempDays != null && tempDays.length() > 0) {
ArrayList<String> daysList = new ArrayList<>();
for (int i = 0; i < tempDays.length(); i++) {
daysList.add(tempDays.optString(i));
}
this.days.addAll(daysList);
}
this.isHot = jobj.optBoolean("isHot", false);
this.locations = new ArrayList<>();
JSONArray tempLocations = new JSONArray();
......@@ -65,13 +77,14 @@ public class UnifiedCampaignModel implements Serializable {
}
this.locations.addAll(locationsList);
}
this.storeId = jobj.optString("store_id");
}
}
public class UnifiedCampaignLocation {
private String id, title, address, municipality, telephone,
afiliateId, url, logoImage, pinLogoImage;
private int roadNumber;
url, logoImage, pinLogoImage;
private int roadNumber, afiliateId;
private double latitude = 0.0;
private double longitude = 0.0;
......@@ -81,7 +94,7 @@ public class UnifiedCampaignModel implements Serializable {
this.address = "";
this.municipality = "";
this.telephone = "";
this.afiliateId = "";
this.afiliateId = 0;
this.url = "";
this.logoImage = "";
this.pinLogoImage = "";
......@@ -93,15 +106,15 @@ public class UnifiedCampaignModel implements Serializable {
public UnifiedCampaignLocation(JSONObject jobj) {
if (jobj != null) {
this.id = jobj.optString("id", "");
this.title = jobj.optString("title", "");
this.address = jobj.optString("address", "");
this.municipality = jobj.optString("municipality", "");
this.telephone = jobj.optString("telephone", "");
this.afiliateId = jobj.optString("afiliateId", "");
this.url = jobj.optString("url", "");
this.logoImage = jobj.optString("logoImage", "");
this.pinLogoImage = jobj.optString("pinLogoImage", "");
this.roadNumber = jobj.optInt("roadNumber", 0);
this.title = jobj.optString("title");
this.address = jobj.optString("address");
this.municipality = jobj.optString("municipality");
this.telephone = jobj.optString("telephone");
this.afiliateId = jobj.optInt("afiliateId");
this.url = jobj.optString("url");
this.logoImage = jobj.optString("logoImage");
this.pinLogoImage = jobj.optString("pinLogoImage");
this.roadNumber = jobj.optInt("roadNumber");
this.latitude = jobj.optDouble("latitude", 0.0);
this.longitude = jobj.optDouble("longitude", 0.0);
}
......@@ -147,11 +160,11 @@ public class UnifiedCampaignModel implements Serializable {
this.telephone = telephone;
}
public String getAfiliateId() {
public int getAfiliateId() {
return afiliateId;
}
public void setAfiliateId(String afiliateId) {
public void setAfiliateId(int afiliateId) {
this.afiliateId = afiliateId;
}
......@@ -220,11 +233,11 @@ public class UnifiedCampaignModel implements Serializable {
this.title = title;
}
public String getAffiliatedId() {
public int getAffiliatedId() {
return affiliatedId;
}
public void setAffiliatedId(String affiliatedId) {
public void setAffiliatedId(int affiliatedId) {
this.affiliatedId = affiliatedId;
}
......@@ -308,11 +321,11 @@ public class UnifiedCampaignModel implements Serializable {
this.position = position;
}
public int getDays() {
public ArrayList<String> getDays() {
return days;
}
public void setDays(int days) {
public void setDays(ArrayList<String> days) {
this.days = days;
}
......@@ -331,4 +344,20 @@ public class UnifiedCampaignModel implements Serializable {
public void setLocations(ArrayList<UnifiedCampaignLocation> locations) {
this.locations = locations;
}
public String getCouponsetUuid() {
return couponsetUuid;
}
public void setCouponsetUuid(String couponsetUuid) {
this.couponsetUuid = couponsetUuid;
}
public String getStoreId() {
return storeId;
}
public void setStoreId(String storeId) {
this.storeId = storeId;
}
}
......
......@@ -5,10 +5,12 @@ import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
/**
* Created by Panagiotis Triantafyllou on 24/Νοε/2022.
......@@ -99,6 +101,10 @@ public interface ApiService {
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature);
@GET("/partners/cosmote/{env}/map_data/")
Call<ResponseBody> getMapData(@Path("env") String env,
@Query("language") String language);
@Headers("Content-Type: application/json")
@POST("/api/mobile/v2/{appUuid}/context/")
Call<ResponseBody> getCampaignsAvailability(@Path("appUuid") String appUuid,
......
......@@ -114,6 +114,7 @@ import ly.warp.sdk.io.models.TagsList;
import ly.warp.sdk.io.models.TelematicsHistory;
import ly.warp.sdk.io.models.TransactionsList;
import ly.warp.sdk.io.models.TripMetrics;
import ly.warp.sdk.io.models.UnifiedCampaignModel;
import ly.warp.sdk.io.models.UnifiedCoupon;
import ly.warp.sdk.io.models.WarplyPacingEventModel;
import ly.warp.sdk.io.request.CosmoteCouponSharingRequest;
......@@ -2112,6 +2113,79 @@ public class WarplyManager {
return future;
}
public static void getMapData(final CallbackReceiver<ArrayList<UnifiedCampaignModel>> receiver) {
WarpUtils.log("************* WARPLY Get Map Data Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Get Map Data Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
getMapDataRetro(service, receiver);
}
private static void getMapDataRetro(ApiService service, final CallbackReceiver<ArrayList<UnifiedCampaignModel>> receiver) {
String serviceEnv = WarplyProperty.getAppUuid(Warply.getWarplyContext()).equals("0086a2088301440792091b9f814c2267") ? "prod" : "dev";
Call<ResponseBody> call = service.getMapData(
serviceEnv,
WarplyProperty.getLanguage(Warply.getWarplyContext())
);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject jobjMapDataResponse = null;
try {
jobjMapDataResponse = new JSONObject(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjMapDataResponse != null && jobjMapDataResponse.has("status") && jobjMapDataResponse.optString("status", "2").equals("1")) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_map_data");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
JSONArray jMapDataBody = null;
try {
jMapDataBody = jobjMapDataResponse.optJSONObject("result").optJSONArray("offers");
} catch (Exception e) {
e.printStackTrace();
}
if (jMapDataBody != null) {
ArrayList<UnifiedCampaignModel> mMapDataList = new ArrayList<>();
final ExecutorService executorMapData = Executors.newFixedThreadPool(1);
JSONArray finalMapDataJBody = jMapDataBody;
executorMapData.submit(() -> {
for (int i = 0; i < finalMapDataJBody.length(); ++i) {
mMapDataList.add(new UnifiedCampaignModel(finalMapDataJBody.optJSONObject(i)));
}
executorMapData.shutdownNow();
new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mMapDataList));
});
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_map_data");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_map_data");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(response.code());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
receiver.onFailure(2);
}
});
}
public static void getCampaignsPersonalized(WarplyGetCampaignsRequest request, final CallbackReceiver<ArrayList<Campaign>> receiver) {
WarpUtils.log("************* WARPLY Get Campaigns Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active");
......@@ -4470,72 +4544,6 @@ public class WarplyManager {
}, null);
}
public static void makeGetRequest(String url) {
// Always run it in a new Thread, not in the main, ie Executors
// new Thread(() -> {
// makeGetRequest(session_uuid);
// }).start();
// Also add those two dependencies
// api 'com.squareup.retrofit2:retrofit:2.9.0'
// api 'com.squareup.okhttp3:okhttp:4.10.0'
// And uncomment the code inside ApiService.java
// OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// httpClient.followRedirects(false)
// .followSslRedirects(false);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(WarplyProperty.getBaseUrl(Warply.getWarplyContext()))
// .client(httpClient.build())
// .build();
//
// RetrofitInterface service = retrofit.create(RetrofitInterface.class);
// Call<ResponseBody> respo = service.getSingleCampaign(url);
// respo.enqueue(new Callback<ResponseBody>() {
// @Override
// public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_read_campaign_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// getCampaigns(new WarplyGetCampaignsRequest().setLanguage("en"), new CallbackReceiver<ArrayList<Campaign>>() {
// @Override
// public void onSuccess(ArrayList<Campaign> result) {
// OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
// WorkManager.getInstance(Warply.getWarplyContext()).enqueue(mywork);
// }
//
// @Override
// public void onFailure(int errorCode) {
//
// }
// });
// }
//
// @Override
// public void onFailure(Call<ResponseBody> call, Throwable t) {
// LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
// dynatraceEvent.setEventName("custom_success_read_campaign_loyalty");
// EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
//
// getCampaigns(new WarplyGetCampaignsRequest().setLanguage("en"), new CallbackReceiver<ArrayList<Campaign>>() {
// @Override
// public void onSuccess(ArrayList<Campaign> result) {
// OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
// WorkManager.getInstance(Warply.getWarplyContext()).enqueue(mywork);
// }
//
// @Override
// public void onFailure(int errorCode) {
//
// }
// });
// }
// });
}
private static boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) Warply.getWarplyContext().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
......