Panagiotis Triantafyllou

cupons request

......@@ -15,7 +15,10 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import ly.warp.sdk.R;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.fragments.BaseFragment;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyProperty;
public class BillPaymentActivity extends Activity implements View.OnClickListener {
......@@ -95,8 +98,24 @@ public class BillPaymentActivity extends Activity implements View.OnClickListene
mClLuckyDraw.setOnClickListener(view -> {
if (BaseFragment.getUniqueCampaignList() != null && !BaseFragment.getUniqueCampaignList().isEmpty()) {
if (BaseFragment.getUniqueCampaignList().containsKey("lucky_draw") && BaseFragment.getUniqueCampaignList().get("lucky_draw").size() > 0) {
startActivity(WarpViewActivity.createIntentFromSessionUUID(this,
BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()));
String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
tempUrl = tempUrl
+ "?web_id=" + WarpUtils.getWebId(this)
+ "&app_uuid=" + WarplyProperty.getAppUuid(this)
+ "&api_key=" + WarpUtils.getApiKey(this)
+ "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
+ "&access_token=" + WarplyDBHelper.getInstance(this).getAuthValue("access_token")
+ "&refresh_token=" + WarplyDBHelper.getInstance(this).getAuthValue("refresh_token")
+ "&client_id=" + WarplyDBHelper.getInstance(this).getClientValue("client_id")
+ "&client_secret=" + WarplyDBHelper.getInstance(this).getClientValue("client_secret");
if (BaseFragment.getConsumer() != null)
tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
else
tempUrl = tempUrl + "&auth_token=";
startActivity(WarpViewActivity.createIntentFromURL(this, tempUrl));
dialog.dismiss();
}
}
......
......@@ -11,13 +11,16 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyInboxRequest;
import ly.warp.sdk.io.request.WarplyUserCouponsRequest;
import ly.warp.sdk.utils.managers.WarplyManager;
public class BaseFragment extends Fragment {
private static Consumer mConsumer;
private static HashMap mUniqueCampaignList = new HashMap<String, CampaignList>();
private static CouponList mCouponList;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -34,6 +37,12 @@ public class BaseFragment extends Fragment {
Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver);
}
}).start();
new Thread(() -> {
if (!Thread.currentThread().isInterrupted()) {
WarplyManager.getUserCoupons(new WarplyUserCouponsRequest(), mUserCouponsReceiver);
}
}).start();
}
......@@ -50,6 +59,10 @@ public class BaseFragment extends Fragment {
return mUniqueCampaignList;
}
public static CouponList getCouponList() {
return mCouponList;
}
private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() {
@Override
public void onSuccess(Consumer result) {
......@@ -88,4 +101,18 @@ public class BaseFragment extends Fragment {
}
};
private final CallbackReceiver<CouponList> mUserCouponsReceiver =
new CallbackReceiver<CouponList>() {
@Override
public void onSuccess(CouponList result) {
mCouponList = result;
Thread.currentThread().interrupt();
}
@Override
public void onFailure(int errorCode) {
Thread.currentThread().interrupt();
}
};
}
\ No newline at end of file
......
......@@ -21,8 +21,11 @@ import ly.warp.sdk.R;
import ly.warp.sdk.activities.BillPaymentActivity;
import ly.warp.sdk.activities.CouponInfoActivity;
import ly.warp.sdk.activities.WarpViewActivity;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.views.adapters.HomeCampaignAdapter;
import ly.warp.sdk.views.adapters.HomeCouponAdapter;
......@@ -78,9 +81,24 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
mRecyclerCampaigns.setAdapter(mAdapterCampaigns);
mAdapterCampaigns.getPositionClicks()
.doOnNext(campaign -> {
getContext().startActivity(
WarpViewActivity.createIntentFromSessionUUID(getContext(),
campaign.getSessionUUID()));
String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
tempUrl = tempUrl
+ "?web_id=" + WarpUtils.getWebId(getContext())
+ "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
+ "&api_key=" + WarpUtils.getApiKey(getContext())
+ "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
+ "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
+ "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
+ "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
+ "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
if (BaseFragment.getConsumer() != null)
tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
else
tempUrl = tempUrl + "&auth_token=";
startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
})
.doOnError(error -> {
})
......
......@@ -17,6 +17,9 @@ import androidx.recyclerview.widget.RecyclerView;
import ly.warp.sdk.R;
import ly.warp.sdk.activities.LoyaltyActivity;
import ly.warp.sdk.activities.WarpViewActivity;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.views.adapters.ProfileCampaignAdapter;
public class LoyaltyFragment extends BaseFragment implements View.OnClickListener {
......@@ -69,9 +72,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene
mRecyclerDeals.setAdapter(mAdapterDeals);
mAdapterDeals.getPositionClicks()
.doOnNext(deal -> {
getContext().startActivity(
WarpViewActivity.createIntentFromSessionUUID(getContext(),
deal.getSessionUUID()));
String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
tempUrl = tempUrl
+ "?web_id=" + WarpUtils.getWebId(getContext())
+ "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
+ "&api_key=" + WarpUtils.getApiKey(getContext())
+ "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
+ "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
+ "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
+ "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
+ "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
if (BaseFragment.getConsumer() != null)
tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
else
tempUrl = tempUrl + "&auth_token=";
startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
})
.doOnError(error -> {
})
......@@ -83,9 +101,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene
mRecyclerGifts.setAdapter(mAdapterGifts);
mAdapterGifts.getPositionClicks()
.doOnNext(gift -> {
getContext().startActivity(
WarpViewActivity.createIntentFromSessionUUID(getContext(),
gift.getSessionUUID()));
String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
tempUrl = tempUrl
+ "?web_id=" + WarpUtils.getWebId(getContext())
+ "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
+ "&api_key=" + WarpUtils.getApiKey(getContext())
+ "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
+ "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
+ "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
+ "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
+ "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
if (BaseFragment.getConsumer() != null)
tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
else
tempUrl = tempUrl + "&auth_token=";
startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
})
.doOnError(error -> {
})
......@@ -97,9 +130,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene
mRecyclerMore.setAdapter(mAdapterMore);
mAdapterMore.getPositionClicks()
.doOnNext(more -> {
getContext().startActivity(
WarpViewActivity.createIntentFromSessionUUID(getContext(),
more.getSessionUUID()));
String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
tempUrl = tempUrl
+ "?web_id=" + WarpUtils.getWebId(getContext())
+ "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
+ "&api_key=" + WarpUtils.getApiKey(getContext())
+ "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
+ "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
+ "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
+ "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
+ "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
if (BaseFragment.getConsumer() != null)
tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
else
tempUrl = tempUrl + "&auth_token=";
startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
})
.doOnError(error -> {
})
......
......@@ -46,6 +46,7 @@ public class Campaign implements Parcelable, Serializable {
/* Constants used to export the campaign in JSON formal and vice versa */
private static final String INDEX_URL = "index_url";
private static final String LOGO_URL = "logo_url";
private static final String ACTION = "action";
private static final String DELIVERED = "delivered";
......@@ -90,6 +91,7 @@ public class Campaign implements Parcelable, Serializable {
private boolean show;
private String deliveryMethod;
private String displayType;
private String indexUrl;
private ArrayList<CampaignAction> actions = new ArrayList<>();
/**
......@@ -109,6 +111,7 @@ public class Campaign implements Parcelable, Serializable {
* @param json JSON Object used to create the Campaign
*/
public Campaign(JSONObject json) {
this.indexUrl = json.optString(INDEX_URL);
this.logoUrl = json.optString(LOGO_URL);
this.delivered = json.optDouble(DELIVERED);
this.sessionUUID = json.optString(SESSION_UUID);
......@@ -147,7 +150,7 @@ public class Campaign implements Parcelable, Serializable {
}
public Campaign(Parcel source) {
this.indexUrl = source.readString();
this.action = source.readInt();
this.delivered = source.readDouble();
this.expires = source.readDouble();
......@@ -173,7 +176,7 @@ public class Campaign implements Parcelable, Serializable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.indexUrl);
dest.writeInt(this.action);
dest.writeDouble(this.delivered);
dest.writeDouble(this.expires);
......@@ -205,6 +208,7 @@ public class Campaign implements Parcelable, Serializable {
public JSONObject toJSONObject() {
JSONObject jObj = new JSONObject();
try {
jObj.putOpt(INDEX_URL, this.indexUrl);
jObj.putOpt(LOGO_URL, this.logoUrl);
jObj.putOpt(ACTION, this.action);
jObj.putOpt(DELIVERED, this.delivered);
......@@ -411,6 +415,10 @@ public class Campaign implements Parcelable, Serializable {
return logoUrl;
}
public String getIndexUrl() {
return indexUrl;
}
public String getExtraFields() {
return extraFields;
}
......