Panagiotis Triantafyllou

possible fix in campaigns

......@@ -25,6 +25,8 @@
package ly.warp.sdk.io.callbacks;
import android.text.TextUtils;
import org.json.JSONObject;
import java.util.ArrayList;
......@@ -33,6 +35,7 @@ import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.NewCampaign;
import ly.warp.sdk.io.models.NewCampaignList;
import ly.warp.sdk.utils.WarpJSONParser;
/**
* Created by Panagiotis Triantafyllou on 12-May-22.
......@@ -67,12 +70,26 @@ public class NewCampaignsHook implements CallbackReceiver<JSONObject> {
camp.setSorting(newCamp.getSorting());
camp.setNew(newCamp.getIsNew());
camp.setType(newCamp.getCampaignType());
camp.setBannerImage(newCamp.getBannerImage());
camp.setBannerTitle(newCamp.getBannerTitle());
try {
camp.setExtraFields(newCamp.getExtraFields().toString());
if (!TextUtils.isEmpty(newCamp.getExtraFields().toString())) {
JSONObject extraFieldsResp = WarpJSONParser.getJSONFromString(newCamp.getExtraFields().toString());
if (extraFieldsResp != null) {
if (extraFieldsResp.has("Banner_title")) {
camp.setBannerTitle(extraFieldsResp.optString("Banner_title", ""));
}
if (extraFieldsResp.has("Banner_img")) {
camp.setBannerImage(extraFieldsResp.optString("Banner_img", ""));
}
}
} else {
camp.setBannerImage("");
camp.setBannerTitle("");
}
} catch (NullPointerException e) {
camp.setExtraFields("");
camp.setBannerImage("");
camp.setBannerTitle("");
e.printStackTrace();
}
......
......@@ -27,6 +27,7 @@ package ly.warp.sdk.io.models;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -36,6 +37,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarpJSONParser;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
......@@ -170,6 +172,20 @@ public class Campaign implements Parcelable, Serializable {
this.isNew = json.optBoolean(IS_NEW);
this.sorting = json.optInt(SORTING);
this.extraFields = json.optString(EXTRA_FIELDS);
if (!TextUtils.isEmpty(this.extraFields)) {
JSONObject extraFieldsResp = WarpJSONParser.getJSONFromString(this.extraFields);
if (extraFieldsResp != null) {
if (extraFieldsResp.has("Banner_title")) {
this.bannerTitle = extraFieldsResp.optString(BANNER_TITLE, "");
}
if (extraFieldsResp.has("Banner_img")) {
this.bannerImage = extraFieldsResp.optString(BANNER_IMAGE, "");
}
}
} else {
this.bannerImage = "";
this.bannerTitle = "";
}
this.type = json.optString(TYPE);
this.expired = json.optBoolean(EXPIRED);
this.show = json.optBoolean(SHOW);
......