Panagiotis Triantafyllou

optimizations part2

......@@ -37,6 +37,7 @@ import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
import ly.warp.sdk.io.request.CosmoteSubmitOrderRequest;
import ly.warp.sdk.services.EventCampaignService;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyManagerHelper;
import ly.warp.sdk.utils.managers.WarplyAnalyticsManager;
import ly.warp.sdk.utils.managers.WarplyEventBusManager;
import ly.warp.sdk.utils.managers.WarplyManager;
......@@ -62,7 +63,9 @@ public class ContextualActivity extends Activity implements View.OnClickListener
private Consumer mConsumer;
private boolean mIsTermsPressed = false;
private String mSender = "";
private AlertDialog mAlertDialogAskActivate, mAlertDialogErrorActivating, mAlertDialogSuccessActivating;
private AlertDialog mAlertDialogAskActivate, mAlertDialogErrorActivating,
mAlertDialogSuccessActivating;
private Campaign mLoyalty;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -75,6 +78,15 @@ public class ContextualActivity extends Activity implements View.OnClickListener
mCCMS = (LoyaltyContextualOfferModel) getIntent().getSerializableExtra("ccms");
/* New Addition start */
for (Campaign cmp : WarplyManagerHelper.getCampaignListAll()) {
if (cmp.getSessionUUID().equals(mCCMS.getLoyaltyCampaignId())) {
mLoyalty = cmp;
break;
}
}
/* New Addition end */
mIvBack = findViewById(R.id.iv_contextual_back);
mTvCampaignTitle = findViewById(R.id.textView13);
mIvCampaignPhoto = findViewById(R.id.imageView6);
......@@ -317,22 +329,27 @@ public class ContextualActivity extends Activity implements View.OnClickListener
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
// runOnUiThread(() -> {
if (status == 1) {
successActivatingDialog();
/* New Addition start */
WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver);
/* New Addition end */
WarplyManager.getCampaigns(mCampaignsCallback);
} else
errorActivatingDialog();
// });
runOnUiThread(() -> {
if (status == 1) {
successActivatingDialog();
/* New Addition start */
WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver);
// WarplyManager.getCampaigns(mCampaignsCallback);
if (mLoyalty != null) {
WarplyManagerHelper.removeCampaignItem(mLoyalty);
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
WorkManager.getInstance(ContextualActivity.this).enqueue(mywork);
}
/* New Addition end */
} else
errorActivatingDialog();
});
}
@Override
public void onFailure(int errorCode) {
// runOnUiThread(() -> errorActivatingDialog());
errorActivatingDialog();
runOnUiThread(() -> errorActivatingDialog());
// errorActivatingDialog();
}
};
......@@ -350,16 +367,16 @@ public class ContextualActivity extends Activity implements View.OnClickListener
}
};
private CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() {
@Override
public void onSuccess(ArrayList<Campaign> result) {
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
WorkManager.getInstance(ContextualActivity.this).enqueue(mywork);
}
@Override
public void onFailure(int errorCode) {
}
};
// private CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() {
// @Override
// public void onSuccess(ArrayList<Campaign> result) {
// OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
// WorkManager.getInstance(ContextualActivity.this).enqueue(mywork);
// }
//
// @Override
// public void onFailure(int errorCode) {
//
// }
// };
}
......
......@@ -264,14 +264,18 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
showDialog(true, 1);
/* New Addition start */
// WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
/* New Addition end */
// WarplyManager.getCampaigns(mCampaignsCallback);
WarplyManagerHelper.addCouponItem(mCoupon);
WarplyManager.getCampaigns(mCampaignsCallback);
WarplyManagerHelper.removeCampaignItem(mLoyalty);
/* New Addition end */
/* New Addition start */
WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
couponsChanged.setChanged(true);
EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
WorkManager.getInstance(CouponsetInfoActivity.this).enqueue(mywork);
/* New Addition end */
} else {
showDialog(false, status);
......@@ -405,17 +409,17 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
// }
// };
private CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() {
@Override
public void onSuccess(ArrayList<Campaign> result) {
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
WorkManager.getInstance(CouponsetInfoActivity.this).enqueue(mywork);
}
@Override
public void onFailure(int errorCode) {
}
};
// private CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() {
// @Override
// public void onSuccess(ArrayList<Campaign> result) {
// OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
// WorkManager.getInstance(CouponsetInfoActivity.this).enqueue(mywork);
// }
//
// @Override
// public void onFailure(int errorCode) {
//
// }
// };
}
......
......@@ -1343,6 +1343,12 @@ public class WarplyManagerHelper {
return mCampaignListAll;
}
public static void removeCampaignItem(Campaign cmp) {
if (mCampaignListAll != null && !mCampaignListAll.isEmpty()) {
mCampaignListAll.remove(cmp);
}
}
public static void setCouponList(CouponList couponList) {
LoyaltyBadgeModel badge = new LoyaltyBadgeModel();
CouponList cpnlist = new CouponList();
......
......@@ -5304,18 +5304,18 @@ public class WarplyManager {
dynatraceEvent.setEventName("custom_success_read_campaign_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
getCampaigns(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) {
}
});
// getCampaigns(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
......@@ -5325,18 +5325,18 @@ public class WarplyManager {
dynatraceEvent.setEventName("custom_success_read_campaign_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
getCampaigns(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) {
}
});
// getCampaigns(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) {
//
// }
// });
}
}
}, null);
......