Panagiotis Triantafyllou

new questionnaire flow

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4-cosbeta41'
PUBLISH_VERSION = '4.5.4-cosbeta42'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -152,6 +152,11 @@
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name="ly.warp.sdk.services.EventQuestionnaireService"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name="ly.warp.sdk.services.WarplyBeaconsRangingService"
android:exported="false" />
......
......@@ -33,8 +33,6 @@ import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
......@@ -56,11 +54,11 @@ import java.security.SecureRandom;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import ly.warp.sdk.R;
import ly.warp.sdk.Warply;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.request.WarplyUserCouponsRequest;
import ly.warp.sdk.services.EventQuestionnaireService;
import ly.warp.sdk.services.PushEventsClickedWorkerService;
import ly.warp.sdk.utils.WarpJSONParser;
import ly.warp.sdk.utils.WarpUtils;
......@@ -130,6 +128,8 @@ public class WarpViewActivity extends WarpBaseActivity {
public void onMessageEvent(WarplyEventBusManager event) {
// EventBus.getDefault().unregister(this);
if (event.getQuestionnaire() != null) {
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventQuestionnaireService.class).build();
WorkManager.getInstance(WarpViewActivity.this).enqueue(mywork);
setResult(RESULT_OK, new Intent());
finish();
}
......
package ly.warp.sdk.services;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyGetCampaignsRequest;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyManagerHelper;
import ly.warp.sdk.utils.managers.WarplyManager;
/**
* Created by Panagiotis Triantafyllou on 22/Ιουλ/2022.
*/
public class EventQuestionnaireService extends Worker {
public EventQuestionnaireService(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result doWork() {
WarplyManager.getConsumer(new WarplyConsumerRequest(), new CallbackReceiver<Consumer>() {
@Override
public void onSuccess(Consumer result) {
WarplyManagerHelper.setConsumer(result);
WarplyManager.getCampaigns(new WarplyGetCampaignsRequest().setLanguage("en"), new CallbackReceiver<CampaignList>() {
@Override
public void onSuccess(CampaignList result) {
WarpUtils.log("SUCCESS_QUESTIONNAIRE_EVENT");
}
@Override
public void onFailure(int errorCode) {
WarpUtils.log("ERROR_QUESTIONNAIRE_EVENT " + String.valueOf(errorCode));
}
});
}
@Override
public void onFailure(int errorCode) {
WarpUtils.log("ERROR_QUESTIONNAIRE_CONSUMER_EVENT " + String.valueOf(errorCode));
}
});
return Result.success();
}
}
......@@ -1374,15 +1374,57 @@ public class WarplyManager {
CampaignList campaignLoyaltyList = new CampaignList();
campaignLoyaltyList.clear();
for (Campaign camp : mNewCampaignList) {
try {
JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields());
if (extraFields != null) {
if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) {
if (camp.getOfferCategory().equals("questionnaire")) {
if (WarplyManagerHelper.getConsumer() != null) {
JSONObject profMetadata = WarpJSONParser.getJSONFromString(WarplyManagerHelper.getConsumer().getProfileMetadata());
if (profMetadata != null) {
if (!profMetadata.has("answered")) {
try {
JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields());
if (extraFields != null) {
if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) {
campaignLoyaltyList.add(camp);
}
}
} catch (Exception exception) {
campaignLoyaltyList.add(camp);
}
}
} else {
try {
JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields());
if (extraFields != null) {
if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) {
campaignLoyaltyList.add(camp);
}
}
} catch (Exception exception) {
campaignLoyaltyList.add(camp);
}
}
} else {
try {
JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields());
if (extraFields != null) {
if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) {
campaignLoyaltyList.add(camp);
}
}
} catch (Exception exception) {
campaignLoyaltyList.add(camp);
}
}
} catch (Exception exception) {
campaignLoyaltyList.add(camp);
} else {
try {
JSONObject extraFields = WarpJSONParser.getJSONFromString(camp.getExtraFields());
if (extraFields != null) {
if (extraFields.length() == 0 || !(extraFields.has("ccms_offer") || extraFields.has("type"))) {
campaignLoyaltyList.add(camp);
}
}
} catch (Exception exception) {
campaignLoyaltyList.add(camp);
}
}
}
WarplyManagerHelper.setCampaignList(mNewCampaignList);
......