Panagiotis Triantafyllou

cupons request

...@@ -15,7 +15,10 @@ import android.widget.LinearLayout; ...@@ -15,7 +15,10 @@ import android.widget.LinearLayout;
15 import android.widget.TextView; 15 import android.widget.TextView;
16 16
17 import ly.warp.sdk.R; 17 import ly.warp.sdk.R;
18 +import ly.warp.sdk.db.WarplyDBHelper;
18 import ly.warp.sdk.fragments.BaseFragment; 19 import ly.warp.sdk.fragments.BaseFragment;
20 +import ly.warp.sdk.utils.WarpUtils;
21 +import ly.warp.sdk.utils.WarplyProperty;
19 22
20 23
21 public class BillPaymentActivity extends Activity implements View.OnClickListener { 24 public class BillPaymentActivity extends Activity implements View.OnClickListener {
...@@ -95,8 +98,24 @@ public class BillPaymentActivity extends Activity implements View.OnClickListene ...@@ -95,8 +98,24 @@ public class BillPaymentActivity extends Activity implements View.OnClickListene
95 mClLuckyDraw.setOnClickListener(view -> { 98 mClLuckyDraw.setOnClickListener(view -> {
96 if (BaseFragment.getUniqueCampaignList() != null && !BaseFragment.getUniqueCampaignList().isEmpty()) { 99 if (BaseFragment.getUniqueCampaignList() != null && !BaseFragment.getUniqueCampaignList().isEmpty()) {
97 if (BaseFragment.getUniqueCampaignList().containsKey("lucky_draw") && BaseFragment.getUniqueCampaignList().get("lucky_draw").size() > 0) { 100 if (BaseFragment.getUniqueCampaignList().containsKey("lucky_draw") && BaseFragment.getUniqueCampaignList().get("lucky_draw").size() > 0) {
98 - startActivity(WarpViewActivity.createIntentFromSessionUUID(this, 101 + String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
99 - BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID())); 102 +
103 + tempUrl = tempUrl
104 + + "?web_id=" + WarpUtils.getWebId(this)
105 + + "&app_uuid=" + WarplyProperty.getAppUuid(this)
106 + + "&api_key=" + WarpUtils.getApiKey(this)
107 + + "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
108 + + "&access_token=" + WarplyDBHelper.getInstance(this).getAuthValue("access_token")
109 + + "&refresh_token=" + WarplyDBHelper.getInstance(this).getAuthValue("refresh_token")
110 + + "&client_id=" + WarplyDBHelper.getInstance(this).getClientValue("client_id")
111 + + "&client_secret=" + WarplyDBHelper.getInstance(this).getClientValue("client_secret");
112 +
113 + if (BaseFragment.getConsumer() != null)
114 + tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
115 + else
116 + tempUrl = tempUrl + "&auth_token=";
117 +
118 + startActivity(WarpViewActivity.createIntentFromURL(this, tempUrl));
100 dialog.dismiss(); 119 dialog.dismiss();
101 } 120 }
102 } 121 }
......
...@@ -11,13 +11,16 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver; ...@@ -11,13 +11,16 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver;
11 import ly.warp.sdk.io.models.Campaign; 11 import ly.warp.sdk.io.models.Campaign;
12 import ly.warp.sdk.io.models.CampaignList; 12 import ly.warp.sdk.io.models.CampaignList;
13 import ly.warp.sdk.io.models.Consumer; 13 import ly.warp.sdk.io.models.Consumer;
14 +import ly.warp.sdk.io.models.CouponList;
14 import ly.warp.sdk.io.request.WarplyConsumerRequest; 15 import ly.warp.sdk.io.request.WarplyConsumerRequest;
15 import ly.warp.sdk.io.request.WarplyInboxRequest; 16 import ly.warp.sdk.io.request.WarplyInboxRequest;
17 +import ly.warp.sdk.io.request.WarplyUserCouponsRequest;
16 import ly.warp.sdk.utils.managers.WarplyManager; 18 import ly.warp.sdk.utils.managers.WarplyManager;
17 19
18 public class BaseFragment extends Fragment { 20 public class BaseFragment extends Fragment {
19 private static Consumer mConsumer; 21 private static Consumer mConsumer;
20 private static HashMap mUniqueCampaignList = new HashMap<String, CampaignList>(); 22 private static HashMap mUniqueCampaignList = new HashMap<String, CampaignList>();
23 + private static CouponList mCouponList;
21 24
22 @Override 25 @Override
23 public void onCreate(Bundle savedInstanceState) { 26 public void onCreate(Bundle savedInstanceState) {
...@@ -34,6 +37,12 @@ public class BaseFragment extends Fragment { ...@@ -34,6 +37,12 @@ public class BaseFragment extends Fragment {
34 Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver); 37 Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver);
35 } 38 }
36 }).start(); 39 }).start();
40 +
41 + new Thread(() -> {
42 + if (!Thread.currentThread().isInterrupted()) {
43 + WarplyManager.getUserCoupons(new WarplyUserCouponsRequest(), mUserCouponsReceiver);
44 + }
45 + }).start();
37 } 46 }
38 47
39 48
...@@ -50,6 +59,10 @@ public class BaseFragment extends Fragment { ...@@ -50,6 +59,10 @@ public class BaseFragment extends Fragment {
50 return mUniqueCampaignList; 59 return mUniqueCampaignList;
51 } 60 }
52 61
62 + public static CouponList getCouponList() {
63 + return mCouponList;
64 + }
65 +
53 private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() { 66 private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() {
54 @Override 67 @Override
55 public void onSuccess(Consumer result) { 68 public void onSuccess(Consumer result) {
...@@ -88,4 +101,18 @@ public class BaseFragment extends Fragment { ...@@ -88,4 +101,18 @@ public class BaseFragment extends Fragment {
88 } 101 }
89 }; 102 };
90 103
104 + private final CallbackReceiver<CouponList> mUserCouponsReceiver =
105 + new CallbackReceiver<CouponList>() {
106 + @Override
107 + public void onSuccess(CouponList result) {
108 + mCouponList = result;
109 + Thread.currentThread().interrupt();
110 + }
111 +
112 + @Override
113 + public void onFailure(int errorCode) {
114 + Thread.currentThread().interrupt();
115 + }
116 + };
117 +
91 } 118 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -21,8 +21,11 @@ import ly.warp.sdk.R; ...@@ -21,8 +21,11 @@ import ly.warp.sdk.R;
21 import ly.warp.sdk.activities.BillPaymentActivity; 21 import ly.warp.sdk.activities.BillPaymentActivity;
22 import ly.warp.sdk.activities.CouponInfoActivity; 22 import ly.warp.sdk.activities.CouponInfoActivity;
23 import ly.warp.sdk.activities.WarpViewActivity; 23 import ly.warp.sdk.activities.WarpViewActivity;
24 +import ly.warp.sdk.db.WarplyDBHelper;
24 import ly.warp.sdk.io.models.Coupon; 25 import ly.warp.sdk.io.models.Coupon;
25 import ly.warp.sdk.io.models.CouponList; 26 import ly.warp.sdk.io.models.CouponList;
27 +import ly.warp.sdk.utils.WarpUtils;
28 +import ly.warp.sdk.utils.WarplyProperty;
26 import ly.warp.sdk.views.adapters.HomeCampaignAdapter; 29 import ly.warp.sdk.views.adapters.HomeCampaignAdapter;
27 import ly.warp.sdk.views.adapters.HomeCouponAdapter; 30 import ly.warp.sdk.views.adapters.HomeCouponAdapter;
28 31
...@@ -78,9 +81,24 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener { ...@@ -78,9 +81,24 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
78 mRecyclerCampaigns.setAdapter(mAdapterCampaigns); 81 mRecyclerCampaigns.setAdapter(mAdapterCampaigns);
79 mAdapterCampaigns.getPositionClicks() 82 mAdapterCampaigns.getPositionClicks()
80 .doOnNext(campaign -> { 83 .doOnNext(campaign -> {
81 - getContext().startActivity( 84 + String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
82 - WarpViewActivity.createIntentFromSessionUUID(getContext(), 85 +
83 - campaign.getSessionUUID())); 86 + tempUrl = tempUrl
87 + + "?web_id=" + WarpUtils.getWebId(getContext())
88 + + "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
89 + + "&api_key=" + WarpUtils.getApiKey(getContext())
90 + + "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
91 + + "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
92 + + "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
93 + + "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
94 + + "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
95 +
96 + if (BaseFragment.getConsumer() != null)
97 + tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
98 + else
99 + tempUrl = tempUrl + "&auth_token=";
100 +
101 + startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
84 }) 102 })
85 .doOnError(error -> { 103 .doOnError(error -> {
86 }) 104 })
......
...@@ -17,6 +17,9 @@ import androidx.recyclerview.widget.RecyclerView; ...@@ -17,6 +17,9 @@ import androidx.recyclerview.widget.RecyclerView;
17 import ly.warp.sdk.R; 17 import ly.warp.sdk.R;
18 import ly.warp.sdk.activities.LoyaltyActivity; 18 import ly.warp.sdk.activities.LoyaltyActivity;
19 import ly.warp.sdk.activities.WarpViewActivity; 19 import ly.warp.sdk.activities.WarpViewActivity;
20 +import ly.warp.sdk.db.WarplyDBHelper;
21 +import ly.warp.sdk.utils.WarpUtils;
22 +import ly.warp.sdk.utils.WarplyProperty;
20 import ly.warp.sdk.views.adapters.ProfileCampaignAdapter; 23 import ly.warp.sdk.views.adapters.ProfileCampaignAdapter;
21 24
22 public class LoyaltyFragment extends BaseFragment implements View.OnClickListener { 25 public class LoyaltyFragment extends BaseFragment implements View.OnClickListener {
...@@ -69,9 +72,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene ...@@ -69,9 +72,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene
69 mRecyclerDeals.setAdapter(mAdapterDeals); 72 mRecyclerDeals.setAdapter(mAdapterDeals);
70 mAdapterDeals.getPositionClicks() 73 mAdapterDeals.getPositionClicks()
71 .doOnNext(deal -> { 74 .doOnNext(deal -> {
72 - getContext().startActivity( 75 + String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
73 - WarpViewActivity.createIntentFromSessionUUID(getContext(), 76 +
74 - deal.getSessionUUID())); 77 + tempUrl = tempUrl
78 + + "?web_id=" + WarpUtils.getWebId(getContext())
79 + + "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
80 + + "&api_key=" + WarpUtils.getApiKey(getContext())
81 + + "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
82 + + "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
83 + + "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
84 + + "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
85 + + "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
86 +
87 + if (BaseFragment.getConsumer() != null)
88 + tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
89 + else
90 + tempUrl = tempUrl + "&auth_token=";
91 +
92 + startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
75 }) 93 })
76 .doOnError(error -> { 94 .doOnError(error -> {
77 }) 95 })
...@@ -83,9 +101,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene ...@@ -83,9 +101,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene
83 mRecyclerGifts.setAdapter(mAdapterGifts); 101 mRecyclerGifts.setAdapter(mAdapterGifts);
84 mAdapterGifts.getPositionClicks() 102 mAdapterGifts.getPositionClicks()
85 .doOnNext(gift -> { 103 .doOnNext(gift -> {
86 - getContext().startActivity( 104 + String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
87 - WarpViewActivity.createIntentFromSessionUUID(getContext(), 105 +
88 - gift.getSessionUUID())); 106 + tempUrl = tempUrl
107 + + "?web_id=" + WarpUtils.getWebId(getContext())
108 + + "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
109 + + "&api_key=" + WarpUtils.getApiKey(getContext())
110 + + "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
111 + + "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
112 + + "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
113 + + "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
114 + + "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
115 +
116 + if (BaseFragment.getConsumer() != null)
117 + tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
118 + else
119 + tempUrl = tempUrl + "&auth_token=";
120 +
121 + startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
89 }) 122 })
90 .doOnError(error -> { 123 .doOnError(error -> {
91 }) 124 })
...@@ -97,9 +130,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene ...@@ -97,9 +130,24 @@ public class LoyaltyFragment extends BaseFragment implements View.OnClickListene
97 mRecyclerMore.setAdapter(mAdapterMore); 130 mRecyclerMore.setAdapter(mAdapterMore);
98 mAdapterMore.getPositionClicks() 131 mAdapterMore.getPositionClicks()
99 .doOnNext(more -> { 132 .doOnNext(more -> {
100 - getContext().startActivity( 133 + String tempUrl = BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getIndexUrl();
101 - WarpViewActivity.createIntentFromSessionUUID(getContext(), 134 +
102 - more.getSessionUUID())); 135 + tempUrl = tempUrl
136 + + "?web_id=" + WarpUtils.getWebId(getContext())
137 + + "&app_uuid=" + WarplyProperty.getAppUuid(getContext())
138 + + "&api_key=" + WarpUtils.getApiKey(getContext())
139 + + "&session_uuid=" + BaseFragment.getUniqueCampaignList().get("lucky_draw").get(0).getSessionUUID()
140 + + "&access_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("access_token")
141 + + "&refresh_token=" + WarplyDBHelper.getInstance(getContext()).getAuthValue("refresh_token")
142 + + "&client_id=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_id")
143 + + "&client_secret=" + WarplyDBHelper.getInstance(getContext()).getClientValue("client_secret");
144 +
145 + if (BaseFragment.getConsumer() != null)
146 + tempUrl = tempUrl + "&auth_token=" + (BaseFragment.getConsumer().getUuid());
147 + else
148 + tempUrl = tempUrl + "&auth_token=";
149 +
150 + startActivity(WarpViewActivity.createIntentFromURL(getContext(), tempUrl));
103 }) 151 })
104 .doOnError(error -> { 152 .doOnError(error -> {
105 }) 153 })
......
...@@ -46,6 +46,7 @@ public class Campaign implements Parcelable, Serializable { ...@@ -46,6 +46,7 @@ public class Campaign implements Parcelable, Serializable {
46 46
47 /* Constants used to export the campaign in JSON formal and vice versa */ 47 /* Constants used to export the campaign in JSON formal and vice versa */
48 48
49 + private static final String INDEX_URL = "index_url";
49 private static final String LOGO_URL = "logo_url"; 50 private static final String LOGO_URL = "logo_url";
50 private static final String ACTION = "action"; 51 private static final String ACTION = "action";
51 private static final String DELIVERED = "delivered"; 52 private static final String DELIVERED = "delivered";
...@@ -90,6 +91,7 @@ public class Campaign implements Parcelable, Serializable { ...@@ -90,6 +91,7 @@ public class Campaign implements Parcelable, Serializable {
90 private boolean show; 91 private boolean show;
91 private String deliveryMethod; 92 private String deliveryMethod;
92 private String displayType; 93 private String displayType;
94 + private String indexUrl;
93 private ArrayList<CampaignAction> actions = new ArrayList<>(); 95 private ArrayList<CampaignAction> actions = new ArrayList<>();
94 96
95 /** 97 /**
...@@ -109,6 +111,7 @@ public class Campaign implements Parcelable, Serializable { ...@@ -109,6 +111,7 @@ public class Campaign implements Parcelable, Serializable {
109 * @param json JSON Object used to create the Campaign 111 * @param json JSON Object used to create the Campaign
110 */ 112 */
111 public Campaign(JSONObject json) { 113 public Campaign(JSONObject json) {
114 + this.indexUrl = json.optString(INDEX_URL);
112 this.logoUrl = json.optString(LOGO_URL); 115 this.logoUrl = json.optString(LOGO_URL);
113 this.delivered = json.optDouble(DELIVERED); 116 this.delivered = json.optDouble(DELIVERED);
114 this.sessionUUID = json.optString(SESSION_UUID); 117 this.sessionUUID = json.optString(SESSION_UUID);
...@@ -147,7 +150,7 @@ public class Campaign implements Parcelable, Serializable { ...@@ -147,7 +150,7 @@ public class Campaign implements Parcelable, Serializable {
147 } 150 }
148 151
149 public Campaign(Parcel source) { 152 public Campaign(Parcel source) {
150 - 153 + this.indexUrl = source.readString();
151 this.action = source.readInt(); 154 this.action = source.readInt();
152 this.delivered = source.readDouble(); 155 this.delivered = source.readDouble();
153 this.expires = source.readDouble(); 156 this.expires = source.readDouble();
...@@ -173,7 +176,7 @@ public class Campaign implements Parcelable, Serializable { ...@@ -173,7 +176,7 @@ public class Campaign implements Parcelable, Serializable {
173 176
174 @Override 177 @Override
175 public void writeToParcel(Parcel dest, int flags) { 178 public void writeToParcel(Parcel dest, int flags) {
176 - 179 + dest.writeString(this.indexUrl);
177 dest.writeInt(this.action); 180 dest.writeInt(this.action);
178 dest.writeDouble(this.delivered); 181 dest.writeDouble(this.delivered);
179 dest.writeDouble(this.expires); 182 dest.writeDouble(this.expires);
...@@ -205,6 +208,7 @@ public class Campaign implements Parcelable, Serializable { ...@@ -205,6 +208,7 @@ public class Campaign implements Parcelable, Serializable {
205 public JSONObject toJSONObject() { 208 public JSONObject toJSONObject() {
206 JSONObject jObj = new JSONObject(); 209 JSONObject jObj = new JSONObject();
207 try { 210 try {
211 + jObj.putOpt(INDEX_URL, this.indexUrl);
208 jObj.putOpt(LOGO_URL, this.logoUrl); 212 jObj.putOpt(LOGO_URL, this.logoUrl);
209 jObj.putOpt(ACTION, this.action); 213 jObj.putOpt(ACTION, this.action);
210 jObj.putOpt(DELIVERED, this.delivered); 214 jObj.putOpt(DELIVERED, this.delivered);
...@@ -411,6 +415,10 @@ public class Campaign implements Parcelable, Serializable { ...@@ -411,6 +415,10 @@ public class Campaign implements Parcelable, Serializable {
411 return logoUrl; 415 return logoUrl;
412 } 416 }
413 417
418 + public String getIndexUrl() {
419 + return indexUrl;
420 + }
421 +
414 public String getExtraFields() { 422 public String getExtraFields() {
415 return extraFields; 423 return extraFields;
416 } 424 }
......