Panagiotis Triantafyllou

additions part1

1 package ly.warp.sdk.activities; 1 package ly.warp.sdk.activities;
2 2
3 import android.app.Activity; 3 import android.app.Activity;
4 +import android.content.ActivityNotFoundException;
4 import android.content.Intent; 5 import android.content.Intent;
6 +import android.net.Uri;
5 import android.os.Bundle; 7 import android.os.Bundle;
6 import android.os.Parcelable; 8 import android.os.Parcelable;
9 +import android.text.TextUtils;
7 import android.util.TypedValue; 10 import android.util.TypedValue;
8 import android.view.LayoutInflater; 11 import android.view.LayoutInflater;
9 import android.view.View; 12 import android.view.View;
...@@ -27,10 +30,10 @@ import java.util.List; ...@@ -27,10 +30,10 @@ import java.util.List;
27 import java.util.Map; 30 import java.util.Map;
28 31
29 import ly.warp.sdk.R; 32 import ly.warp.sdk.R;
30 -import ly.warp.sdk.io.adapters.BannerAdapter; 33 +import ly.warp.sdk.io.adapters.CarouselAdapter;
31 import ly.warp.sdk.io.adapters.CouponsetAdapter; 34 import ly.warp.sdk.io.adapters.CouponsetAdapter;
32 import ly.warp.sdk.io.callbacks.CallbackReceiver; 35 import ly.warp.sdk.io.callbacks.CallbackReceiver;
33 -import ly.warp.sdk.io.models.BannerItem; 36 +import ly.warp.sdk.io.models.CarouselItem;
34 import ly.warp.sdk.io.models.Coupon; 37 import ly.warp.sdk.io.models.Coupon;
35 import ly.warp.sdk.io.models.Couponset; 38 import ly.warp.sdk.io.models.Couponset;
36 import ly.warp.sdk.io.models.User; 39 import ly.warp.sdk.io.models.User;
...@@ -57,7 +60,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -57,7 +60,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
57 /* View Pager */ 60 /* View Pager */
58 // private ViewPager2 mBannerViewPager; 61 // private ViewPager2 mBannerViewPager;
59 private RecyclerView mRvBannerViewPager; 62 private RecyclerView mRvBannerViewPager;
60 - private BannerAdapter mBannerAdapter; 63 + private CarouselAdapter mBannerAdapter;
61 /* Pagination */ 64 /* Pagination */
62 // private LinearLayout mDotsContainer; 65 // private LinearLayout mDotsContainer;
63 // private List<ImageView> mDots; 66 // private List<ImageView> mDots;
...@@ -87,8 +90,8 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -87,8 +90,8 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
87 mSectionsLoading.setVisibility(View.VISIBLE); 90 mSectionsLoading.setVisibility(View.VISIBLE);
88 91
89 WarplyManager.getCoupons(mCouponsCallback); 92 WarplyManager.getCoupons(mCouponsCallback);
90 - WarplyManager.getCampaigns(mCampaignsCallback); 93 + WarplyManager.getCarousel(mCarouselCallback);
91 - WarplyManager.getCouponsets(mCouponsetsCallback); 94 + WarplyManager.getCouponsets(null, null, mCouponsetsCallback);
92 } 95 }
93 96
94 @Override 97 @Override
...@@ -201,15 +204,16 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -201,15 +204,16 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
201 mRvBannerViewPager.setLayoutManager(layoutManager); 204 mRvBannerViewPager.setLayoutManager(layoutManager);
202 mRvBannerViewPager.setHasFixedSize(true); 205 mRvBannerViewPager.setHasFixedSize(true);
203 206
204 - mBannerAdapter = new BannerAdapter(this, WarplyManagerHelper.getBannerList()); 207 + mBannerAdapter = new CarouselAdapter(this, WarplyManagerHelper.getCarouselList());
205 - mBannerAdapter.setOnBannerCampaignClickListener(campaign -> { 208 + mBannerAdapter.setOnBannerClickListener(carouselItem -> {
206 - startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(campaign))); 209 +// startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(carouselItem.getUrl())));
207 - }); 210 +
208 - mBannerAdapter.setOnBannerContentClickListener(article -> { 211 + if (!TextUtils.isEmpty(carouselItem.getUrl())) {
209 - if (article != null && article.getExtraFields() != null) { 212 + if (carouselItem.getUrl().contains("Offers?")) {
210 - String couponsetUuid = article.getExtraFields().optString("url_link", null); 213 + //TODO: category uuid
211 - if (couponsetUuid != null && !couponsetUuid.isEmpty()) { 214 + } else if (carouselItem.getUrl().contains("singleOffer")) {
212 - Couponset matchedCouponset = findCouponsetByUuid(couponsetUuid); 215 + if (!TextUtils.isEmpty(carouselItem.getUuid())) {
216 + Couponset matchedCouponset = findCouponsetByUuid(carouselItem.getUuid());
213 if (matchedCouponset != null) { 217 if (matchedCouponset != null) {
214 Intent myIntent = new Intent(HomeActivity.this, SingleCouponsetActivity.class); 218 Intent myIntent = new Intent(HomeActivity.this, SingleCouponsetActivity.class);
215 myIntent.putExtra(SingleCouponsetActivity.EXTRA_OFFER_ITEM, (Parcelable) matchedCouponset); 219 myIntent.putExtra(SingleCouponsetActivity.EXTRA_OFFER_ITEM, (Parcelable) matchedCouponset);
...@@ -217,6 +221,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -217,6 +221,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
217 } 221 }
218 } 222 }
219 } 223 }
224 + }
220 }); 225 });
221 226
222 /* View Pager */ 227 /* View Pager */
...@@ -343,15 +348,15 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -343,15 +348,15 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
343 return null; 348 return null;
344 } 349 }
345 350
346 - private final CallbackReceiver<ArrayList<BannerItem>> mCampaignsCallback = new CallbackReceiver<ArrayList<BannerItem>>() { 351 + private final CallbackReceiver<ArrayList<CarouselItem>> mCarouselCallback = new CallbackReceiver<ArrayList<CarouselItem>>() {
347 @Override 352 @Override
348 - public void onSuccess(ArrayList<BannerItem> result) { 353 + public void onSuccess(ArrayList<CarouselItem> result) {
349 mPbLoading.setVisibility(View.GONE); 354 mPbLoading.setVisibility(View.GONE);
350 if (result != null && !result.isEmpty()) { 355 if (result != null && !result.isEmpty()) {
351 // Preloads the campaigns' images 356 // Preloads the campaigns' images
352 result.forEach(bannerItem -> { 357 result.forEach(bannerItem -> {
353 Glide.with(getApplicationContext()) 358 Glide.with(getApplicationContext())
354 - .load(bannerItem.isCampaign() ? bannerItem.getCampaign().getLogoUrl() : bannerItem.getContent().getImgPreview()) 359 + .load(bannerItem.getAppImg())
355 .diskCacheStrategy(DiskCacheStrategy.DATA) 360 .diskCacheStrategy(DiskCacheStrategy.DATA)
356 .preload(); 361 .preload();
357 }); 362 });
......
1 package ly.warp.sdk.activities; 1 package ly.warp.sdk.activities;
2 2
3 import android.app.Activity; 3 import android.app.Activity;
4 +import android.content.ActivityNotFoundException;
4 import android.content.ClipData; 5 import android.content.ClipData;
5 import android.content.ClipboardManager; 6 import android.content.ClipboardManager;
6 import android.content.Context; 7 import android.content.Context;
7 import android.content.Intent; 8 import android.content.Intent;
9 +import android.net.Uri;
8 import android.os.Bundle; 10 import android.os.Bundle;
9 import android.text.TextUtils; 11 import android.text.TextUtils;
10 import android.view.View; 12 import android.view.View;
...@@ -45,7 +47,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen ...@@ -45,7 +47,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
45 private TextView mTvSmallDescription; 47 private TextView mTvSmallDescription;
46 private TextView mTvFullDescription; 48 private TextView mTvFullDescription;
47 private TextView mTvEndDate; 49 private TextView mTvEndDate;
48 - private LinearLayout mLlDate, mLlShopsButton; 50 + private LinearLayout mLlDate, mLlShopsButton, mLlWebsiteButton;
49 private TextView mTvValue; 51 private TextView mTvValue;
50 private TextView mTvMoreButton; 52 private TextView mTvMoreButton;
51 private ImageView mIvImage; 53 private ImageView mIvImage;
...@@ -107,6 +109,20 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen ...@@ -107,6 +109,20 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
107 Intent myIntent = new Intent(SingleCouponActivity.this, ShopsActivity.class); 109 Intent myIntent = new Intent(SingleCouponActivity.this, ShopsActivity.class);
108 myIntent.putExtra(SingleCouponActivity.EXTRA_MERCHANT_UUID, mOfferItem.getMerchantUuid()); 110 myIntent.putExtra(SingleCouponActivity.EXTRA_MERCHANT_UUID, mOfferItem.getMerchantUuid());
109 startActivity(myIntent); 111 startActivity(myIntent);
112 + return;
113 + }
114 + if (v.getId() == R.id.ll_website) {
115 + if (mOfferItem != null && mOfferItem.getMerchantDetails() != null
116 + && !TextUtils.isEmpty(mOfferItem.getMerchantDetails().getWebsite())
117 + && mOfferItem.getMerchantDetails().getWebsite().length() > 8) {
118 + try {
119 + Intent intent = new Intent(Intent.ACTION_VIEW);
120 + intent.setData(Uri.parse(mOfferItem.getMerchantDetails().getWebsite()));
121 + startActivity(intent);
122 + } catch (ActivityNotFoundException e) {
123 + e.printStackTrace();
124 + }
125 + }
110 } 126 }
111 } 127 }
112 128
...@@ -121,6 +137,9 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen ...@@ -121,6 +137,9 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
121 mLlShopsButton = findViewById(R.id.ll_shops); 137 mLlShopsButton = findViewById(R.id.ll_shops);
122 mLlShopsButton.setOnClickListener(this); 138 mLlShopsButton.setOnClickListener(this);
123 139
140 + mLlWebsiteButton = findViewById(R.id.ll_website);
141 + mLlWebsiteButton.setOnClickListener(this);
142 +
124 // Initialize views 143 // Initialize views
125 mTvSmallDescription = findViewById(R.id.tv_coupon_small_description); 144 mTvSmallDescription = findViewById(R.id.tv_coupon_small_description);
126 mTvFullDescription = findViewById(R.id.tv_coupon_full_description); 145 mTvFullDescription = findViewById(R.id.tv_coupon_full_description);
...@@ -202,8 +221,8 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen ...@@ -202,8 +221,8 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
202 .into(mIvImage); 221 .into(mIvImage);
203 } 222 }
204 223
205 - if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getAdmin_name() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getAdmin_name())) 224 + if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getMerchantAdminName() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getMerchantAdminName()))
206 - mTvMerchantName.setText(mOfferItem.getCouponsetDetails().getAdmin_name()); 225 + mTvMerchantName.setText(mOfferItem.getCouponsetDetails().getMerchantAdminName());
207 if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getName() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getName())) 226 if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getName() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getName()))
208 mTvValue.setText(mOfferItem.getCouponsetDetails().getName()); 227 mTvValue.setText(mOfferItem.getCouponsetDetails().getName());
209 if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getShort_description() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getShort_description())) 228 if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getShort_description() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getShort_description()))
......
...@@ -3,6 +3,8 @@ package ly.warp.sdk.activities; ...@@ -3,6 +3,8 @@ package ly.warp.sdk.activities;
3 import android.app.Activity; 3 import android.app.Activity;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 +import android.os.Handler;
7 +import android.os.Looper;
6 import android.os.Parcelable; 8 import android.os.Parcelable;
7 import android.text.TextUtils; 9 import android.text.TextUtils;
8 import android.view.View; 10 import android.view.View;
...@@ -198,8 +200,8 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis ...@@ -198,8 +200,8 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
198 .into(mIvImage); 200 .into(mIvImage);
199 } 201 }
200 202
201 - if (!TextUtils.isEmpty(mOfferItem.getAdmin_name())) 203 + if (!TextUtils.isEmpty(mOfferItem.getMerchantAdminName()))
202 - mTvMerchantName.setText(mOfferItem.getAdmin_name()); 204 + mTvMerchantName.setText(mOfferItem.getMerchantAdminName());
203 if (!TextUtils.isEmpty(mOfferItem.getName())) 205 if (!TextUtils.isEmpty(mOfferItem.getName()))
204 mTvValue.setText(mOfferItem.getName()); 206 mTvValue.setText(mOfferItem.getName());
205 if (!TextUtils.isEmpty(mOfferItem.getShort_description())) 207 if (!TextUtils.isEmpty(mOfferItem.getShort_description()))
...@@ -339,17 +341,18 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis ...@@ -339,17 +341,18 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
339 @Override 341 @Override
340 public void onSuccess(JSONObject result) { 342 public void onSuccess(JSONObject result) {
341 mPbLoading.setVisibility(View.GONE); 343 mPbLoading.setVisibility(View.GONE);
342 - Toast.makeText(SingleCouponsetActivity.this, "RETRIEVE SUCCESS", Toast.LENGTH_SHORT).show();
343 -// Coupon coupon = new Coupon();
344 -// coupon.setCoupon(result.optString("coupon", ""));
345 -// coupon.setExpiration(result.optString("expiration", ""));
346 -// coupon.setCouponsetDetails(mOfferItem);
347 -// Intent myIntent = new Intent(SingleCouponsetActivity.this, SingleCouponActivity.class);
348 -// myIntent.putExtra(SingleCouponActivity.EXTRA_OFFER_ITEM, (Parcelable) coupon);
349 -// startActivity(myIntent);
350 -
351 mRedeemButton.setVisibility(View.GONE); 344 mRedeemButton.setVisibility(View.GONE);
352 mSuccessButton.setVisibility(View.VISIBLE); 345 mSuccessButton.setVisibility(View.VISIBLE);
346 +
347 + new Handler(Looper.getMainLooper()).postDelayed(() -> {
348 + Coupon coupon = new Coupon();
349 + coupon.setCoupon(result.optString("coupon", ""));
350 + coupon.setExpiration(result.optString("expiration", ""));
351 + coupon.setCouponsetDetails(mOfferItem);
352 + Intent myIntent = new Intent(SingleCouponsetActivity.this, SingleCouponActivity.class);
353 + myIntent.putExtra(SingleCouponActivity.EXTRA_OFFER_ITEM, (Parcelable) coupon);
354 + startActivity(myIntent);
355 + }, 500);
353 } 356 }
354 357
355 @Override 358 @Override
......
1 +package ly.warp.sdk.io.adapters;
2 +
3 +import android.content.Context;
4 +import android.util.TypedValue;
5 +import android.view.LayoutInflater;
6 +import android.view.View;
7 +import android.view.ViewGroup;
8 +import android.widget.ImageView;
9 +
10 +import androidx.annotation.NonNull;
11 +import androidx.recyclerview.widget.RecyclerView;
12 +
13 +import com.bumptech.glide.Glide;
14 +import com.bumptech.glide.load.engine.DiskCacheStrategy;
15 +import com.bumptech.glide.load.resource.bitmap.CenterCrop;
16 +
17 +import java.util.ArrayList;
18 +
19 +import ly.warp.sdk.R;
20 +import ly.warp.sdk.io.models.CarouselItem;
21 +import ly.warp.sdk.utils.TopRoundedCornersTransformation;
22 +
23 +public class CarouselAdapter extends RecyclerView.Adapter<CarouselAdapter.BannerViewHolder> {
24 +
25 + private final Context mContext;
26 + private final ArrayList<CarouselItem> mBannerItems;
27 + private OnBannerClickListener mListenerBanner;
28 +
29 + public interface OnBannerClickListener {
30 + void onBannerClick(CarouselItem item);
31 + }
32 +
33 + public CarouselAdapter(Context context, ArrayList<CarouselItem> carouselItems) {
34 + this.mContext = context;
35 + this.mBannerItems = carouselItems;
36 + }
37 +
38 + public void setOnBannerClickListener(OnBannerClickListener listener) {
39 + this.mListenerBanner = listener;
40 + }
41 +
42 + @NonNull
43 + @Override
44 + public BannerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
45 + View view = LayoutInflater.from(mContext).inflate(R.layout.item_banner, parent, false);
46 + return new BannerViewHolder(view);
47 + }
48 +
49 + @Override
50 + public void onBindViewHolder(@NonNull BannerViewHolder holder, int position) {
51 + CarouselItem bannerItem = mBannerItems.get(position);
52 +
53 + int radiusInPixels = (int) TypedValue.applyDimension(
54 + TypedValue.COMPLEX_UNIT_DIP, 13,
55 + mContext.getResources().getDisplayMetrics());
56 +
57 + if (bannerItem != null) {
58 + Glide.with(mContext)
59 +// .setDefaultRequestOptions(
60 +// RequestOptions
61 +// .placeholderOf(R.drawable.demo_logo)
62 +// .error(R.drawable.demo_logo))
63 + .load(bannerItem.getAppImg())
64 + .diskCacheStrategy(DiskCacheStrategy.DATA)
65 + .transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true))
66 + .into(holder.imageView);
67 +
68 + holder.itemView.setOnClickListener(v -> {
69 + if (mListenerBanner != null) {
70 + mListenerBanner.onBannerClick(bannerItem);
71 + }
72 + });
73 + }
74 + }
75 +
76 + @Override
77 + public int getItemCount() {
78 + return mBannerItems.size();
79 + }
80 +
81 + static class BannerViewHolder extends RecyclerView.ViewHolder {
82 + ImageView imageView;
83 +
84 + BannerViewHolder(@NonNull View itemView) {
85 + super(itemView);
86 + imageView = itemView.findViewById(R.id.iv_banner);
87 + }
88 + }
89 +}
...@@ -170,7 +170,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView ...@@ -170,7 +170,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
170 llDateExpired.setVisibility(View.GONE); 170 llDateExpired.setVisibility(View.GONE);
171 } 171 }
172 172
173 - tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getAdmin_name()) ? couponItem.getCouponsetDetails().getAdmin_name().trim() : ""); 173 + tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getMerchantAdminName()) ? couponItem.getCouponsetDetails().getMerchantAdminName().trim() : "");
174 tvTitle.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getName()) ? couponItem.getCouponsetDetails().getName().trim() : ""); 174 tvTitle.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getName()) ? couponItem.getCouponsetDetails().getName().trim() : "");
175 tvDescription.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getShort_description()) ? couponItem.getCouponsetDetails().getShort_description().trim() : ""); 175 tvDescription.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getShort_description()) ? couponItem.getCouponsetDetails().getShort_description().trim() : "");
176 if (couponItem.getExpiration() != null && !couponItem.getExpiration().isEmpty()) { 176 if (couponItem.getExpiration() != null && !couponItem.getExpiration().isEmpty()) {
...@@ -205,7 +205,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView ...@@ -205,7 +205,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
205 } 205 }
206 } 206 }
207 207
208 - loadMerchantLogo(couponItem.getMerchantDetails().getImgPreview(), couponItem.getStatus()); 208 + loadMerchantLogo(couponItem.getMerchantDetails().getAppImgPreview(), couponItem.getStatus());
209 } 209 }
210 210
211 private String formatValidityDate(String endDate) { 211 private String formatValidityDate(String endDate) {
...@@ -267,10 +267,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView ...@@ -267,10 +267,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
267 .transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true)) 267 .transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true))
268 .into(ivLogo); 268 .into(ivLogo);
269 } 269 }
270 -
271 - ivLogo.setVisibility(View.VISIBLE);
272 - } else {
273 - ivLogo.setVisibility(View.GONE);
274 } 270 }
275 } 271 }
276 } 272 }
......
...@@ -104,10 +104,10 @@ public class CouponsetAdapter extends RecyclerView.Adapter<CouponsetAdapter.Coup ...@@ -104,10 +104,10 @@ public class CouponsetAdapter extends RecyclerView.Adapter<CouponsetAdapter.Coup
104 tvValidity.setVisibility(View.GONE); 104 tvValidity.setVisibility(View.GONE);
105 } 105 }
106 106
107 - loadCouponsetImage(couponset.getImgPreview()); 107 + loadCouponsetImage(couponset.getAppImgPreview());
108 108
109 - if (couponset.getMerchant() != null && couponset.getMerchant().getImgPreview() != null) { 109 + if (couponset.getMerchantDetails() != null && couponset.getMerchantDetails().getPreviewImg() != null) {
110 - loadMerchantLogo(couponset.getMerchant().getImgPreview()); 110 + loadMerchantLogo(couponset.getMerchantDetails().getPreviewImg());
111 } else { 111 } else {
112 ivLogo.setVisibility(View.GONE); 112 ivLogo.setVisibility(View.GONE);
113 } 113 }
......
1 +package ly.warp.sdk.io.models;
2 +
3 +import android.os.Parcel;
4 +import android.os.Parcelable;
5 +
6 +import org.json.JSONObject;
7 +
8 +import java.io.Serializable;
9 +
10 +/**
11 + * Model representing a single item from the carousel (get_carousel) API response.
12 + */
13 +public class CarouselItem implements Parcelable, Serializable {
14 +
15 + private static final long serialVersionUID = 7812345678901234567L;
16 +
17 + private static final String APP_IMG = "app_img";
18 + private static final String APP_URL = "app_url";
19 + private static final String ENTITY = "entity";
20 + private static final String NAME = "name";
21 + private static final String URL = "url";
22 + private static final String UUID = "uuid";
23 + private static final String WEB_IMG = "web_img";
24 + private static final String WEB_IMG_RESPONSIVE = "web_img_responsive";
25 +
26 + private String appImg;
27 + private String appUrl;
28 + private String entity;
29 + private String name;
30 + private String url;
31 + private String uuid;
32 + private String webImg;
33 + private String webImgResponsive;
34 +
35 + private static String optNullableString(JSONObject json, String key) {
36 + return json.isNull(key) ? null : json.optString(key);
37 + }
38 +
39 + public CarouselItem() {
40 + this.appImg = null;
41 + this.appUrl = null;
42 + this.entity = null;
43 + this.name = null;
44 + this.url = null;
45 + this.uuid = null;
46 + this.webImg = null;
47 + this.webImgResponsive = null;
48 + }
49 +
50 + public CarouselItem(JSONObject json) {
51 + if (json != null) {
52 + this.appImg = optNullableString(json, APP_IMG);
53 + this.appUrl = optNullableString(json, APP_URL);
54 + this.entity = optNullableString(json, ENTITY);
55 + this.name = optNullableString(json, NAME);
56 + this.url = optNullableString(json, URL);
57 + this.uuid = optNullableString(json, UUID);
58 + this.webImg = optNullableString(json, WEB_IMG);
59 + this.webImgResponsive = optNullableString(json, WEB_IMG_RESPONSIVE);
60 + }
61 + }
62 +
63 + public CarouselItem(Parcel source) {
64 + this.appImg = source.readString();
65 + this.appUrl = source.readString();
66 + this.entity = source.readString();
67 + this.name = source.readString();
68 + this.url = source.readString();
69 + this.uuid = source.readString();
70 + this.webImg = source.readString();
71 + this.webImgResponsive = source.readString();
72 + }
73 +
74 + @Override
75 + public void writeToParcel(Parcel dest, int flags) {
76 + dest.writeString(this.appImg);
77 + dest.writeString(this.appUrl);
78 + dest.writeString(this.entity);
79 + dest.writeString(this.name);
80 + dest.writeString(this.url);
81 + dest.writeString(this.uuid);
82 + dest.writeString(this.webImg);
83 + dest.writeString(this.webImgResponsive);
84 + }
85 +
86 + @Override
87 + public int describeContents() {
88 + return 0;
89 + }
90 +
91 + public static final Creator<CarouselItem> CREATOR = new Creator<CarouselItem>() {
92 + @Override
93 + public CarouselItem createFromParcel(Parcel source) {
94 + return new CarouselItem(source);
95 + }
96 +
97 + @Override
98 + public CarouselItem[] newArray(int size) {
99 + return new CarouselItem[size];
100 + }
101 + };
102 +
103 + // ================================================================================
104 + // Getters
105 + // ================================================================================
106 +
107 + public String getAppImg() {
108 + return appImg;
109 + }
110 +
111 + public String getAppUrl() {
112 + return appUrl;
113 + }
114 +
115 + public String getEntity() {
116 + return entity;
117 + }
118 +
119 + public String getName() {
120 + return name;
121 + }
122 +
123 + public String getUrl() {
124 + return url;
125 + }
126 +
127 + public String getUuid() {
128 + return uuid;
129 + }
130 +
131 + public String getWebImg() {
132 + return webImg;
133 + }
134 +
135 + public String getWebImgResponsive() {
136 + return webImgResponsive;
137 + }
138 +
139 + // ================================================================================
140 + // Setters
141 + // ================================================================================
142 +
143 + public void setAppImg(String appImg) {
144 + this.appImg = appImg;
145 + }
146 +
147 + public void setAppUrl(String appUrl) {
148 + this.appUrl = appUrl;
149 + }
150 +
151 + public void setEntity(String entity) {
152 + this.entity = entity;
153 + }
154 +
155 + public void setName(String name) {
156 + this.name = name;
157 + }
158 +
159 + public void setUrl(String url) {
160 + this.url = url;
161 + }
162 +
163 + public void setUuid(String uuid) {
164 + this.uuid = uuid;
165 + }
166 +
167 + public void setWebImg(String webImg) {
168 + this.webImg = webImg;
169 + }
170 +
171 + public void setWebImgResponsive(String webImgResponsive) {
172 + this.webImgResponsive = webImgResponsive;
173 + }
174 +}
...@@ -92,6 +92,13 @@ public class Couponset implements Parcelable, Serializable { ...@@ -92,6 +92,13 @@ public class Couponset implements Parcelable, Serializable {
92 private static final String OFFER_CATEGORY = "offer_category"; 92 private static final String OFFER_CATEGORY = "offer_category";
93 private static final String TAGGING = "tagging"; 93 private static final String TAGGING = "tagging";
94 private static final String REGIONS = "regions"; 94 private static final String REGIONS = "regions";
95 + private static final String MERCHANT_ADMIN_NAME = "merchant_admin_name";
96 + private static final String MERCHANT_IMG_PREVIEW = "merchant_img_preview";
97 + private static final String MERCHANT_DETAILS = "merchant_details";
98 + private static final String MERCHANT_WEBSITE = "merchant_website";
99 + private static final String SCORE = "score";
100 + private static final String APP_IMG_PREVIEW = "app_img_preview";
101 + private static final String APP_IMGS = "app_imgs";
95 102
96 /* Member variables of the Couponset object */ 103 /* Member variables of the Couponset object */
97 104
...@@ -141,6 +148,13 @@ public class Couponset implements Parcelable, Serializable { ...@@ -141,6 +148,13 @@ public class Couponset implements Parcelable, Serializable {
141 private JSONObject tagging; 148 private JSONObject tagging;
142 private JSONArray regions; 149 private JSONArray regions;
143 private Merchant merchant; 150 private Merchant merchant;
151 + private String merchantAdminName;
152 + private String merchantImgPreview;
153 + private String merchantWebsite;
154 + private MerchantDetails merchantDetails;
155 + private int score;
156 + private String appImgPreview;
157 + private JSONArray appImgs;
144 158
145 /** 159 /**
146 * Helper method to get a nullable String from a JSONObject. 160 * Helper method to get a nullable String from a JSONObject.
...@@ -197,6 +211,13 @@ public class Couponset implements Parcelable, Serializable { ...@@ -197,6 +211,13 @@ public class Couponset implements Parcelable, Serializable {
197 this.tagging = null; 211 this.tagging = null;
198 this.regions = null; 212 this.regions = null;
199 this.merchant = null; 213 this.merchant = null;
214 + this.merchantAdminName = null;
215 + this.merchantImgPreview = null;
216 + this.merchantWebsite = null;
217 + this.merchantDetails = null;
218 + this.score = 0;
219 + this.appImgPreview = null;
220 + this.appImgs = null;
200 } 221 }
201 222
202 public Couponset(boolean isUniversal) { 223 public Couponset(boolean isUniversal) {
...@@ -233,6 +254,13 @@ public class Couponset implements Parcelable, Serializable { ...@@ -233,6 +254,13 @@ public class Couponset implements Parcelable, Serializable {
233 this.offerCategory = null; 254 this.offerCategory = null;
234 this.tagging = null; 255 this.tagging = null;
235 this.regions = null; 256 this.regions = null;
257 + this.merchantAdminName = null;
258 + this.merchantImgPreview = null;
259 + this.merchantWebsite = null;
260 + this.merchantDetails = null;
261 + this.score = 0;
262 + this.appImgPreview = null;
263 + this.appImgs = null;
236 } 264 }
237 265
238 /** 266 /**
...@@ -301,6 +329,14 @@ public class Couponset implements Parcelable, Serializable { ...@@ -301,6 +329,14 @@ public class Couponset implements Parcelable, Serializable {
301 this.offerCategory = optNullableString(json, OFFER_CATEGORY); 329 this.offerCategory = optNullableString(json, OFFER_CATEGORY);
302 this.tagging = json.optJSONObject(TAGGING); 330 this.tagging = json.optJSONObject(TAGGING);
303 this.regions = json.optJSONArray(REGIONS); 331 this.regions = json.optJSONArray(REGIONS);
332 + this.merchantAdminName = optNullableString(json, MERCHANT_ADMIN_NAME);
333 + this.merchantImgPreview = optNullableString(json, MERCHANT_IMG_PREVIEW);
334 + this.merchantWebsite = optNullableString(json, MERCHANT_WEBSITE);
335 + JSONObject merchantDetailsJson = json.optJSONObject(MERCHANT_DETAILS);
336 + this.merchantDetails = merchantDetailsJson != null ? new MerchantDetails(merchantDetailsJson) : null;
337 + this.score = json.optInt(SCORE, 0);
338 + this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
339 + this.appImgs = json.optJSONArray(APP_IMGS);
304 } 340 }
305 } 341 }
306 342
...@@ -324,6 +360,7 @@ public class Couponset implements Parcelable, Serializable { ...@@ -324,6 +360,7 @@ public class Couponset implements Parcelable, Serializable {
324 this.active = json.optBoolean(ACTIVE); 360 this.active = json.optBoolean(ACTIVE);
325 this.buyable = json.optBoolean(BUYABLE); 361 this.buyable = json.optBoolean(BUYABLE);
326 this.name = optNullableString(json, NAME); 362 this.name = optNullableString(json, NAME);
363 + this.description = optNullableString(json, DESCRIPTION);
327 this.short_description = optNullableString(json, SHORT_DESCRIPTION); 364 this.short_description = optNullableString(json, SHORT_DESCRIPTION);
328 this.discount = optNullableString(json, DISCOUNT); 365 this.discount = optNullableString(json, DISCOUNT);
329 this.category = optNullableString(json, CATEGORY); 366 this.category = optNullableString(json, CATEGORY);
...@@ -343,6 +380,14 @@ public class Couponset implements Parcelable, Serializable { ...@@ -343,6 +380,14 @@ public class Couponset implements Parcelable, Serializable {
343 this.offerCategory = optNullableString(json, OFFER_CATEGORY); 380 this.offerCategory = optNullableString(json, OFFER_CATEGORY);
344 this.tagging = json.optJSONObject(TAGGING); 381 this.tagging = json.optJSONObject(TAGGING);
345 this.regions = json.optJSONArray(REGIONS); 382 this.regions = json.optJSONArray(REGIONS);
383 + this.merchantAdminName = optNullableString(json, MERCHANT_ADMIN_NAME);
384 + this.merchantImgPreview = optNullableString(json, MERCHANT_IMG_PREVIEW);
385 + this.merchantWebsite = optNullableString(json, MERCHANT_WEBSITE);
386 + JSONObject merchantDetailsJson = json.optJSONObject(MERCHANT_DETAILS);
387 + this.merchantDetails = merchantDetailsJson != null ? new MerchantDetails(merchantDetailsJson) : null;
388 + this.score = json.optInt(SCORE, 0);
389 + this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
390 + this.appImgs = json.optJSONArray(APP_IMGS);
346 } 391 }
347 } 392 }
348 393
...@@ -438,6 +483,19 @@ public class Couponset implements Parcelable, Serializable { ...@@ -438,6 +483,19 @@ public class Couponset implements Parcelable, Serializable {
438 } catch (JSONException e) { 483 } catch (JSONException e) {
439 this.regions = null; 484 this.regions = null;
440 } 485 }
486 + this.merchant = source.readParcelable(Merchant.class.getClassLoader());
487 + this.merchantAdminName = source.readString();
488 + this.merchantImgPreview = source.readString();
489 + this.merchantWebsite = source.readString();
490 + this.merchantDetails = source.readParcelable(MerchantDetails.class.getClassLoader());
491 + this.score = source.readInt();
492 + this.appImgPreview = source.readString();
493 + try {
494 + String appImgsStr = source.readString();
495 + this.appImgs = appImgsStr != null ? new JSONArray(appImgsStr) : null;
496 + } catch (JSONException e) {
497 + this.appImgs = null;
498 + }
441 } 499 }
442 500
443 @Override 501 @Override
...@@ -487,6 +545,14 @@ public class Couponset implements Parcelable, Serializable { ...@@ -487,6 +545,14 @@ public class Couponset implements Parcelable, Serializable {
487 dest.writeString(this.offerCategory); 545 dest.writeString(this.offerCategory);
488 dest.writeString(this.tagging != null ? this.tagging.toString() : null); 546 dest.writeString(this.tagging != null ? this.tagging.toString() : null);
489 dest.writeString(this.regions != null ? this.regions.toString() : null); 547 dest.writeString(this.regions != null ? this.regions.toString() : null);
548 + dest.writeParcelable(this.merchant, flags);
549 + dest.writeString(this.merchantAdminName);
550 + dest.writeString(this.merchantImgPreview);
551 + dest.writeString(this.merchantWebsite);
552 + dest.writeParcelable(this.merchantDetails, flags);
553 + dest.writeInt(this.score);
554 + dest.writeString(this.appImgPreview);
555 + dest.writeString(this.appImgs != null ? this.appImgs.toString() : null);
490 } 556 }
491 557
492 /** 558 /**
...@@ -541,6 +607,13 @@ public class Couponset implements Parcelable, Serializable { ...@@ -541,6 +607,13 @@ public class Couponset implements Parcelable, Serializable {
541 jObj.put(OFFER_CATEGORY, this.offerCategory != null ? this.offerCategory : JSONObject.NULL); 607 jObj.put(OFFER_CATEGORY, this.offerCategory != null ? this.offerCategory : JSONObject.NULL);
542 jObj.put(TAGGING, this.tagging != null ? this.tagging : JSONObject.NULL); 608 jObj.put(TAGGING, this.tagging != null ? this.tagging : JSONObject.NULL);
543 jObj.put(REGIONS, this.regions != null ? this.regions : JSONObject.NULL); 609 jObj.put(REGIONS, this.regions != null ? this.regions : JSONObject.NULL);
610 + jObj.put(MERCHANT_ADMIN_NAME, this.merchantAdminName != null ? this.merchantAdminName : JSONObject.NULL);
611 + jObj.put(MERCHANT_IMG_PREVIEW, this.merchantImgPreview != null ? this.merchantImgPreview : JSONObject.NULL);
612 + jObj.put(MERCHANT_WEBSITE, this.merchantWebsite != null ? this.merchantWebsite : JSONObject.NULL);
613 + jObj.put(MERCHANT_DETAILS, this.merchantDetails != null ? new JSONObject(this.merchantDetails.toString()) : JSONObject.NULL);
614 + jObj.putOpt(SCORE, this.score);
615 + jObj.put(APP_IMG_PREVIEW, this.appImgPreview != null ? this.appImgPreview : JSONObject.NULL);
616 + jObj.put(APP_IMGS, this.appImgs != null ? this.appImgs : JSONObject.NULL);
544 } catch (JSONException e) { 617 } catch (JSONException e) {
545 if (WarpConstants.DEBUG) { 618 if (WarpConstants.DEBUG) {
546 e.printStackTrace(); 619 e.printStackTrace();
...@@ -799,6 +872,34 @@ public class Couponset implements Parcelable, Serializable { ...@@ -799,6 +872,34 @@ public class Couponset implements Parcelable, Serializable {
799 return merchant; 872 return merchant;
800 } 873 }
801 874
875 + public String getMerchantAdminName() {
876 + return merchantAdminName;
877 + }
878 +
879 + public String getMerchantImgPreview() {
880 + return merchantImgPreview;
881 + }
882 +
883 + public String getMerchantWebsite() {
884 + return merchantWebsite;
885 + }
886 +
887 + public MerchantDetails getMerchantDetails() {
888 + return merchantDetails;
889 + }
890 +
891 + public int getScore() {
892 + return score;
893 + }
894 +
895 + public String getAppImgPreview() {
896 + return appImgPreview;
897 + }
898 +
899 + public JSONArray getAppImgs() {
900 + return appImgs;
901 + }
902 +
802 // ================================================================================ 903 // ================================================================================
803 // Setters 904 // Setters
804 // ================================================================================ 905 // ================================================================================
...@@ -987,6 +1088,34 @@ public class Couponset implements Parcelable, Serializable { ...@@ -987,6 +1088,34 @@ public class Couponset implements Parcelable, Serializable {
987 this.merchant = merchant; 1088 this.merchant = merchant;
988 } 1089 }
989 1090
1091 + public void setMerchantAdminName(String merchantAdminName) {
1092 + this.merchantAdminName = merchantAdminName;
1093 + }
1094 +
1095 + public void setMerchantImgPreview(String merchantImgPreview) {
1096 + this.merchantImgPreview = merchantImgPreview;
1097 + }
1098 +
1099 + public void setMerchantWebsite(String merchantWebsite) {
1100 + this.merchantWebsite = merchantWebsite;
1101 + }
1102 +
1103 + public void setMerchantDetails(MerchantDetails merchantDetails) {
1104 + this.merchantDetails = merchantDetails;
1105 + }
1106 +
1107 + public void setScore(int score) {
1108 + this.score = score;
1109 + }
1110 +
1111 + public void setAppImgPreview(String appImgPreview) {
1112 + this.appImgPreview = appImgPreview;
1113 + }
1114 +
1115 + public void setAppImgs(JSONArray appImgs) {
1116 + this.appImgs = appImgs;
1117 + }
1118 +
990 @Override 1119 @Override
991 public int describeContents() { 1120 public int describeContents() {
992 return 0; 1121 return 0;
......
...@@ -101,6 +101,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -101,6 +101,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
101 private static final String MIN_PRICE = "min_price"; 101 private static final String MIN_PRICE = "min_price";
102 private static final String MAX_PRICE = "max_price"; 102 private static final String MAX_PRICE = "max_price";
103 private static final String URL_NAME = "url_name"; 103 private static final String URL_NAME = "url_name";
104 + private static final String APP_IMG_PREVIEW = "app_img_preview";
105 + private static final String APP_IMGS = "app_imgs";
104 106
105 /* Member variables of the Merchant object */ 107 /* Member variables of the Merchant object */
106 108
...@@ -154,6 +156,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -154,6 +156,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
154 private String minPrice; 156 private String minPrice;
155 private String maxPrice; 157 private String maxPrice;
156 private String urlName; 158 private String urlName;
159 + private String appImgPreview;
160 + private JSONArray appImgs;
157 private LatLng coordinates; 161 private LatLng coordinates;
158 162
159 /** 163 /**
...@@ -215,6 +219,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -215,6 +219,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
215 this.minPrice = null; 219 this.minPrice = null;
216 this.maxPrice = null; 220 this.maxPrice = null;
217 this.urlName = null; 221 this.urlName = null;
222 + this.appImgPreview = null;
223 + this.appImgs = null;
218 this.coordinates = new LatLng( 224 this.coordinates = new LatLng(
219 this.latitude != null ? this.latitude : 0.0, 225 this.latitude != null ? this.latitude : 0.0,
220 this.longitude != null ? this.longitude : 0.0); 226 this.longitude != null ? this.longitude : 0.0);
...@@ -304,6 +310,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -304,6 +310,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
304 this.minPrice = optNullableString(json, MIN_PRICE); 310 this.minPrice = optNullableString(json, MIN_PRICE);
305 this.maxPrice = optNullableString(json, MAX_PRICE); 311 this.maxPrice = optNullableString(json, MAX_PRICE);
306 this.urlName = optNullableString(json, URL_NAME); 312 this.urlName = optNullableString(json, URL_NAME);
313 + this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
314 + this.appImgs = json.optJSONArray(APP_IMGS);
307 this.coordinates = new LatLng( 315 this.coordinates = new LatLng(
308 this.latitude != null ? this.latitude : 0.0, 316 this.latitude != null ? this.latitude : 0.0,
309 this.longitude != null ? this.longitude : 0.0); 317 this.longitude != null ? this.longitude : 0.0);
...@@ -325,6 +333,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -325,6 +333,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
325 this.admin_name = optNullableString(json, ADMIN_NAME); 333 this.admin_name = optNullableString(json, ADMIN_NAME);
326 this.img_preview = optNullableString(json, IMG_PREVIEW); 334 this.img_preview = optNullableString(json, IMG_PREVIEW);
327 this.website = optNullableString(json, WEBSITE); 335 this.website = optNullableString(json, WEBSITE);
336 + this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
337 + this.appImgs = json.optJSONArray(APP_IMGS);
328 } 338 }
329 } 339 }
330 340
...@@ -408,6 +418,13 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -408,6 +418,13 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
408 this.minPrice = source.readString(); 418 this.minPrice = source.readString();
409 this.maxPrice = source.readString(); 419 this.maxPrice = source.readString();
410 this.urlName = source.readString(); 420 this.urlName = source.readString();
421 + this.appImgPreview = source.readString();
422 + try {
423 + String appImgsStr = source.readString();
424 + this.appImgs = appImgsStr != null ? new JSONArray(appImgsStr) : null;
425 + } catch (JSONException e) {
426 + this.appImgs = null;
427 + }
411 this.coordinates = new LatLng( 428 this.coordinates = new LatLng(
412 this.latitude != null ? this.latitude : 0.0, 429 this.latitude != null ? this.latitude : 0.0,
413 this.longitude != null ? this.longitude : 0.0); 430 this.longitude != null ? this.longitude : 0.0);
...@@ -465,6 +482,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -465,6 +482,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
465 dest.writeString(this.minPrice); 482 dest.writeString(this.minPrice);
466 dest.writeString(this.maxPrice); 483 dest.writeString(this.maxPrice);
467 dest.writeString(this.urlName); 484 dest.writeString(this.urlName);
485 + dest.writeString(this.appImgPreview);
486 + dest.writeString(this.appImgs != null ? this.appImgs.toString() : null);
468 dest.writeParcelable(coordinates, flags); 487 dest.writeParcelable(coordinates, flags);
469 } 488 }
470 489
...@@ -526,6 +545,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -526,6 +545,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
526 jObj.put(MIN_PRICE, this.minPrice != null ? this.minPrice : JSONObject.NULL); 545 jObj.put(MIN_PRICE, this.minPrice != null ? this.minPrice : JSONObject.NULL);
527 jObj.put(MAX_PRICE, this.maxPrice != null ? this.maxPrice : JSONObject.NULL); 546 jObj.put(MAX_PRICE, this.maxPrice != null ? this.maxPrice : JSONObject.NULL);
528 jObj.put(URL_NAME, this.urlName != null ? this.urlName : JSONObject.NULL); 547 jObj.put(URL_NAME, this.urlName != null ? this.urlName : JSONObject.NULL);
548 + jObj.put(APP_IMG_PREVIEW, this.appImgPreview != null ? this.appImgPreview : JSONObject.NULL);
549 + jObj.put(APP_IMGS, this.appImgs != null ? this.appImgs : JSONObject.NULL);
529 } catch (JSONException e) { 550 } catch (JSONException e) {
530 if (WarpConstants.DEBUG) { 551 if (WarpConstants.DEBUG) {
531 e.printStackTrace(); 552 e.printStackTrace();
...@@ -790,6 +811,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -790,6 +811,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
790 return urlName; 811 return urlName;
791 } 812 }
792 813
814 + public String getAppImgPreview() {
815 + return appImgPreview;
816 + }
817 +
818 + public JSONArray getAppImgs() {
819 + return appImgs;
820 + }
821 +
793 // ================================================================================ 822 // ================================================================================
794 // Setters 823 // Setters
795 // ================================================================================ 824 // ================================================================================
...@@ -994,6 +1023,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { ...@@ -994,6 +1023,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
994 this.urlName = urlName; 1023 this.urlName = urlName;
995 } 1024 }
996 1025
1026 + public void setAppImgPreview(String appImgPreview) {
1027 + this.appImgPreview = appImgPreview;
1028 + }
1029 +
1030 + public void setAppImgs(JSONArray appImgs) {
1031 + this.appImgs = appImgs;
1032 + }
1033 +
997 public void setCoordinates(LatLng coordinates) { 1034 public void setCoordinates(LatLng coordinates) {
998 this.coordinates = coordinates; 1035 this.coordinates = coordinates;
999 } 1036 }
......
1 +package ly.warp.sdk.io.models;
2 +
3 +import android.os.Parcel;
4 +import android.os.Parcelable;
5 +
6 +import org.json.JSONObject;
7 +
8 +import java.io.Serializable;
9 +
10 +/**
11 + * Lightweight model representing the merchant_details object inside a Couponset response.
12 + */
13 +public class MerchantDetails implements Parcelable, Serializable {
14 +
15 + private static final long serialVersionUID = 3891274651234567890L;
16 +
17 + private static final String ADMIN_NAME = "admin_name";
18 + private static final String PREVIEW_IMG = "preview_img";
19 + private static final String UUID = "uuid";
20 + private static final String WEBSITE = "website";
21 +
22 + private String adminName;
23 + private String previewImg;
24 + private String uuid;
25 + private String website;
26 +
27 + private static String optNullableString(JSONObject json, String key) {
28 + return json.isNull(key) ? null : json.optString(key);
29 + }
30 +
31 + public MerchantDetails() {
32 + this.adminName = null;
33 + this.previewImg = null;
34 + this.uuid = null;
35 + this.website = null;
36 + }
37 +
38 + public MerchantDetails(JSONObject json) {
39 + if (json != null) {
40 + this.adminName = optNullableString(json, ADMIN_NAME);
41 + this.previewImg = optNullableString(json, PREVIEW_IMG);
42 + this.uuid = optNullableString(json, UUID);
43 + this.website = optNullableString(json, WEBSITE);
44 + }
45 + }
46 +
47 + public MerchantDetails(Parcel source) {
48 + this.adminName = source.readString();
49 + this.previewImg = source.readString();
50 + this.uuid = source.readString();
51 + this.website = source.readString();
52 + }
53 +
54 + @Override
55 + public void writeToParcel(Parcel dest, int flags) {
56 + dest.writeString(this.adminName);
57 + dest.writeString(this.previewImg);
58 + dest.writeString(this.uuid);
59 + dest.writeString(this.website);
60 + }
61 +
62 + @Override
63 + public int describeContents() {
64 + return 0;
65 + }
66 +
67 + public static final Creator<MerchantDetails> CREATOR = new Creator<MerchantDetails>() {
68 + @Override
69 + public MerchantDetails createFromParcel(Parcel source) {
70 + return new MerchantDetails(source);
71 + }
72 +
73 + @Override
74 + public MerchantDetails[] newArray(int size) {
75 + return new MerchantDetails[size];
76 + }
77 + };
78 +
79 + public String toString() {
80 + JSONObject jObj = new JSONObject();
81 + try {
82 + jObj.put(ADMIN_NAME, this.adminName != null ? this.adminName : JSONObject.NULL);
83 + jObj.put(PREVIEW_IMG, this.previewImg != null ? this.previewImg : JSONObject.NULL);
84 + jObj.put(UUID, this.uuid != null ? this.uuid : JSONObject.NULL);
85 + jObj.put(WEBSITE, this.website != null ? this.website : JSONObject.NULL);
86 + } catch (Exception e) {
87 + e.printStackTrace();
88 + }
89 + return jObj.toString();
90 + }
91 +
92 + // ================================================================================
93 + // Getters
94 + // ================================================================================
95 +
96 + public String getAdminName() {
97 + return adminName;
98 + }
99 +
100 + public String getPreviewImg() {
101 + return previewImg;
102 + }
103 +
104 + public String getUuid() {
105 + return uuid;
106 + }
107 +
108 + public String getWebsite() {
109 + return website;
110 + }
111 +
112 + // ================================================================================
113 + // Setters
114 + // ================================================================================
115 +
116 + public void setAdminName(String adminName) {
117 + this.adminName = adminName;
118 + }
119 +
120 + public void setPreviewImg(String previewImg) {
121 + this.previewImg = previewImg;
122 + }
123 +
124 + public void setUuid(String uuid) {
125 + this.uuid = uuid;
126 + }
127 +
128 + public void setWebsite(String website) {
129 + this.website = website;
130 + }
131 +}
...@@ -135,6 +135,18 @@ public interface ApiService { ...@@ -135,6 +135,18 @@ public interface ApiService {
135 @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); 135 @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
136 136
137 @Headers("Content-Type: application/json") 137 @Headers("Content-Type: application/json")
138 + @POST("/oauth/{appUuid}/context")
139 + Call<ResponseBody> getCarousel(@Path("appUuid") String appUuid,
140 + @Body RequestBody request,
141 + @Header(WarpConstants.HEADER_DATE) String timeStamp,
142 + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
143 + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
144 + @Header(WarpConstants.HEADER_CHANNEL) String channel,
145 + @Header(WarpConstants.HEADER_WEB_ID) String webId,
146 + @Header(WarpConstants.HEADER_SIGNATURE) String signature,
147 + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
148 +
149 + @Headers("Content-Type: application/json")
138 @POST("/api/mobile/v2/{appUuid}/context/") 150 @POST("/api/mobile/v2/{appUuid}/context/")
139 Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid, 151 Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid,
140 @Body RequestBody request, 152 @Body RequestBody request,
......
...@@ -35,6 +35,7 @@ import ly.warp.sdk.Warply; ...@@ -35,6 +35,7 @@ import ly.warp.sdk.Warply;
35 import ly.warp.sdk.db.WarplyDBHelper; 35 import ly.warp.sdk.db.WarplyDBHelper;
36 import ly.warp.sdk.io.models.BannerItem; 36 import ly.warp.sdk.io.models.BannerItem;
37 import ly.warp.sdk.io.models.Campaign; 37 import ly.warp.sdk.io.models.Campaign;
38 +import ly.warp.sdk.io.models.CarouselItem;
38 import ly.warp.sdk.io.models.Coupon; 39 import ly.warp.sdk.io.models.Coupon;
39 import ly.warp.sdk.io.models.CouponList; 40 import ly.warp.sdk.io.models.CouponList;
40 import ly.warp.sdk.io.models.Couponset; 41 import ly.warp.sdk.io.models.Couponset;
...@@ -59,6 +60,7 @@ public class WarplyManagerHelper { ...@@ -59,6 +60,7 @@ public class WarplyManagerHelper {
59 private static ArrayList<Coupon> mCouponList = new ArrayList<Coupon>(); 60 private static ArrayList<Coupon> mCouponList = new ArrayList<Coupon>();
60 private static ArrayList<Campaign> mCampaignListAll = new ArrayList<Campaign>(); 61 private static ArrayList<Campaign> mCampaignListAll = new ArrayList<Campaign>();
61 private static ArrayList<BannerItem> mBannerListAll = new ArrayList<BannerItem>(); 62 private static ArrayList<BannerItem> mBannerListAll = new ArrayList<BannerItem>();
63 + private static ArrayList<CarouselItem> mCarouselListAll = new ArrayList<>();
62 private static LinkedHashMap<String, ArrayList<Couponset>> mCouponsetCategorizedMap = new LinkedHashMap<>(); 64 private static LinkedHashMap<String, ArrayList<Couponset>> mCouponsetCategorizedMap = new LinkedHashMap<>();
63 private static User mUser = null; 65 private static User mUser = null;
64 66
...@@ -96,6 +98,15 @@ public class WarplyManagerHelper { ...@@ -96,6 +98,15 @@ public class WarplyManagerHelper {
96 return mBannerListAll; 98 return mBannerListAll;
97 } 99 }
98 100
101 + public static void setCarouselList(ArrayList<CarouselItem> carouselList) {
102 + mCarouselListAll.clear();
103 + mCarouselListAll.addAll(carouselList);
104 + }
105 +
106 + public static ArrayList<CarouselItem> getCarouselList() {
107 + return mCarouselListAll;
108 + }
109 +
99 public static void setCouponsetCategorizedMap(LinkedHashMap<String, ArrayList<Couponset>> couponsetMap) { 110 public static void setCouponsetCategorizedMap(LinkedHashMap<String, ArrayList<Couponset>> couponsetMap) {
100 mCouponsetCategorizedMap.clear(); 111 mCouponsetCategorizedMap.clear();
101 mCouponsetCategorizedMap.putAll(couponsetMap); 112 mCouponsetCategorizedMap.putAll(couponsetMap);
......
...@@ -32,6 +32,7 @@ import android.text.format.DateFormat; ...@@ -32,6 +32,7 @@ import android.text.format.DateFormat;
32 import android.util.ArrayMap; 32 import android.util.ArrayMap;
33 33
34 import androidx.annotation.NonNull; 34 import androidx.annotation.NonNull;
35 +import androidx.annotation.Nullable;
35 36
36 import com.google.common.util.concurrent.FutureCallback; 37 import com.google.common.util.concurrent.FutureCallback;
37 import com.google.common.util.concurrent.Futures; 38 import com.google.common.util.concurrent.Futures;
...@@ -59,6 +60,7 @@ import ly.warp.sdk.Warply; ...@@ -59,6 +60,7 @@ import ly.warp.sdk.Warply;
59 import ly.warp.sdk.db.WarplyDBHelper; 60 import ly.warp.sdk.db.WarplyDBHelper;
60 import ly.warp.sdk.io.callbacks.CallbackReceiver; 61 import ly.warp.sdk.io.callbacks.CallbackReceiver;
61 import ly.warp.sdk.io.models.BannerItem; 62 import ly.warp.sdk.io.models.BannerItem;
63 +import ly.warp.sdk.io.models.CarouselItem;
62 import ly.warp.sdk.io.models.Campaign; 64 import ly.warp.sdk.io.models.Campaign;
63 import ly.warp.sdk.io.models.Content; 65 import ly.warp.sdk.io.models.Content;
64 import ly.warp.sdk.io.models.Coupon; 66 import ly.warp.sdk.io.models.Coupon;
...@@ -404,7 +406,7 @@ public class WarplyManager { ...@@ -404,7 +406,7 @@ public class WarplyManager {
404 }, executorService); 406 }, executorService);
405 } 407 }
406 408
407 - private static LinkedHashMap<String, ArrayList<Couponset>> mergeCouponsetsResults(ArrayList<Couponset> resultCouponsets, ArrayList<Merchant> resultMerchants) { 409 + private static LinkedHashMap<String, ArrayList<Couponset>> mergeCouponsetsResults(ArrayList<Couponset> resultCouponsets) {
408 LinkedHashMap<String, ArrayList<Couponset>> categorizedMap = new LinkedHashMap<>(); 410 LinkedHashMap<String, ArrayList<Couponset>> categorizedMap = new LinkedHashMap<>();
409 411
410 if (resultCouponsets == null || resultCouponsets.isEmpty()) { 412 if (resultCouponsets == null || resultCouponsets.isEmpty()) {
...@@ -412,24 +414,10 @@ public class WarplyManager { ...@@ -412,24 +414,10 @@ public class WarplyManager {
412 return categorizedMap; 414 return categorizedMap;
413 } 415 }
414 416
415 - HashMap<String, Merchant> merchantLookup = new HashMap<>();
416 - if (resultMerchants != null) {
417 - for (Merchant merchant : resultMerchants) {
418 - if (merchant.getUuid() != null) {
419 - merchantLookup.put(merchant.getUuid(), merchant);
420 - }
421 - }
422 - }
423 -
424 ArrayList<Couponset> topOffers = new ArrayList<>(); 417 ArrayList<Couponset> topOffers = new ArrayList<>();
425 LinkedHashMap<String, ArrayList<Couponset>> categoryGroups = new LinkedHashMap<>(); 418 LinkedHashMap<String, ArrayList<Couponset>> categoryGroups = new LinkedHashMap<>();
426 419
427 for (Couponset couponset : resultCouponsets) { 420 for (Couponset couponset : resultCouponsets) {
428 - // Match merchant by merchantUuid
429 - if (couponset.getMerchantUuid() != null && merchantLookup.containsKey(couponset.getMerchantUuid())) {
430 - couponset.setMerchant(merchantLookup.get(couponset.getMerchantUuid()));
431 - }
432 -
433 if (couponset.isPromoted()) { 421 if (couponset.isPromoted()) {
434 topOffers.add(couponset); 422 topOffers.add(couponset);
435 } else { 423 } else {
...@@ -445,6 +433,14 @@ public class WarplyManager { ...@@ -445,6 +433,14 @@ public class WarplyManager {
445 categorizedMap.put("Top offers", topOffers); 433 categorizedMap.put("Top offers", topOffers);
446 } 434 }
447 435
436 + String[] priorityCategories = {"Αγορές", "Φαγητό και καφές"};
437 + for (String priorityCategory : priorityCategories) {
438 + ArrayList<Couponset> priorityList = categoryGroups.remove(priorityCategory);
439 + if (priorityList != null && !priorityList.isEmpty()) {
440 + categorizedMap.put(priorityCategory, priorityList);
441 + }
442 + }
443 +
448 for (Map.Entry<String, ArrayList<Couponset>> entry : categoryGroups.entrySet()) { 444 for (Map.Entry<String, ArrayList<Couponset>> entry : categoryGroups.entrySet()) {
449 if (!entry.getValue().isEmpty()) { 445 if (!entry.getValue().isEmpty()) {
450 categorizedMap.put(entry.getKey(), entry.getValue()); 446 categorizedMap.put(entry.getKey(), entry.getValue());
...@@ -487,22 +483,20 @@ public class WarplyManager { ...@@ -487,22 +483,20 @@ public class WarplyManager {
487 }, executorService); 483 }, executorService);
488 } 484 }
489 485
490 - public static void getCouponsets(final CallbackReceiver<LinkedHashMap<String, ArrayList<Couponset>>> receiver) { 486 + public static void getCouponsets(@Nullable String region, @Nullable String offerCategory, final CallbackReceiver<LinkedHashMap<String, ArrayList<Couponset>>> receiver) {
491 WarpUtils.log("************* WARPLY Couponsets Request ********************"); 487 WarpUtils.log("************* WARPLY Couponsets Request ********************");
492 WarpUtils.log("[WARP Trace] WARPLY Couponsets Request is active"); 488 WarpUtils.log("[WARP Trace] WARPLY Couponsets Request is active");
493 WarpUtils.log("**************************************************"); 489 WarpUtils.log("**************************************************");
494 490
495 ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); 491 ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
496 - ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2)); 492 + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
497 493
498 - ListenableFuture<ArrayList<Couponset>> futureCouponsets = getCouponsetsRetro(service, 0); 494 + ListenableFuture<ArrayList<Couponset>> futureCouponsets = getCouponsetsRetro(region, offerCategory, service, 0);
499 - ListenableFuture<ArrayList<Merchant>> futureMerchants = getMerchantsRetro(service);
500 495
501 - ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCouponsets, futureMerchants); 496 + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCouponsets);
502 ListenableFuture<LinkedHashMap<String, ArrayList<Couponset>>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> { 497 ListenableFuture<LinkedHashMap<String, ArrayList<Couponset>>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> {
503 ArrayList<Couponset> resultCouponsets = (ArrayList<Couponset>) results.get(0); 498 ArrayList<Couponset> resultCouponsets = (ArrayList<Couponset>) results.get(0);
504 - ArrayList<Merchant> resultMerchants = (ArrayList<Merchant>) results.get(1); 499 + return executorService.submit(() -> mergeCouponsetsResults(resultCouponsets));
505 - return executorService.submit(() -> mergeCouponsetsResults(resultCouponsets, resultMerchants));
506 }, executorService); 500 }, executorService);
507 501
508 Futures.addCallback(mergedResultFuture, new FutureCallback<LinkedHashMap<String, ArrayList<Couponset>>>() { 502 Futures.addCallback(mergedResultFuture, new FutureCallback<LinkedHashMap<String, ArrayList<Couponset>>>() {
...@@ -520,7 +514,7 @@ public class WarplyManager { ...@@ -520,7 +514,7 @@ public class WarplyManager {
520 }, executorService); 514 }, executorService);
521 } 515 }
522 516
523 - private static ListenableFuture<ArrayList<Couponset>> getCouponsetsRetro(ApiService service, int tries/*, Callback<ResponseBody> callback*/) { 517 + private static ListenableFuture<ArrayList<Couponset>> getCouponsetsRetro(@Nullable String region, @Nullable String offerCategory, ApiService service, int tries/*, Callback<ResponseBody> callback*/) {
524 SettableFuture<ArrayList<Couponset>> future = SettableFuture.create(); 518 SettableFuture<ArrayList<Couponset>> future = SettableFuture.create();
525 519
526 String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); 520 String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
...@@ -529,10 +523,16 @@ public class WarplyManager { ...@@ -529,10 +523,16 @@ public class WarplyManager {
529 523
530 Map<String, Object> jsonParamsCouponsets = new ArrayMap<>(); 524 Map<String, Object> jsonParamsCouponsets = new ArrayMap<>();
531 Map<String, Object> jsonParams = new ArrayMap<>(); 525 Map<String, Object> jsonParams = new ArrayMap<>();
532 - jsonParams.put("action", "retrieve_couponsets"); 526 + jsonParams.put("action", "get_offers");
533 jsonParams.put("active", true); 527 jsonParams.put("active", true);
534 jsonParams.put("visible", true); 528 jsonParams.put("visible", true);
535 jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext())); 529 jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
530 + if (!TextUtils.isEmpty(region)) {
531 + jsonParams.put("region", region);
532 + }
533 + if (!TextUtils.isEmpty(offerCategory)) {
534 + jsonParams.put("offer_category", offerCategory);
535 + }
536 jsonParamsCouponsets.put("coupon", jsonParams); 536 jsonParamsCouponsets.put("coupon", jsonParams);
537 537
538 RequestBody couponsetsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCouponsets)).toString()); 538 RequestBody couponsetsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCouponsets)).toString());
...@@ -591,10 +591,10 @@ public class WarplyManager { ...@@ -591,10 +591,10 @@ public class WarplyManager {
591 public void onSuccess(JSONObject result) { 591 public void onSuccess(JSONObject result) {
592 int status = result.optInt("status", 2); 592 int status = result.optInt("status", 2);
593 if (status == 1) 593 if (status == 1)
594 - getCouponsetsRetro(service, tries); 594 + getCouponsetsRetro(region, offerCategory, service, tries);
595 else { 595 else {
596 if (tries < MAX_RETRIES) { 596 if (tries < MAX_RETRIES) {
597 - getCouponsetsRetro(service, (tries + 1)); 597 + getCouponsetsRetro(region, offerCategory, service, (tries + 1));
598 } else { 598 } else {
599 future.setException(new Throwable()); 599 future.setException(new Throwable());
600 } 600 }
...@@ -604,7 +604,7 @@ public class WarplyManager { ...@@ -604,7 +604,7 @@ public class WarplyManager {
604 @Override 604 @Override
605 public void onFailure(int errorCode) { 605 public void onFailure(int errorCode) {
606 if (tries < MAX_RETRIES) { 606 if (tries < MAX_RETRIES) {
607 - getCouponsetsRetro(service, (tries + 1)); 607 + getCouponsetsRetro(region, offerCategory, service, (tries + 1));
608 } else { 608 } else {
609 future.setException(new Throwable()); 609 future.setException(new Throwable());
610 } 610 }
...@@ -824,6 +824,37 @@ public class WarplyManager { ...@@ -824,6 +824,37 @@ public class WarplyManager {
824 return allItems; 824 return allItems;
825 } 825 }
826 826
827 + public static void getCarousel(final CallbackReceiver<ArrayList<CarouselItem>> receiver) {
828 + WarpUtils.log("************* WARPLY Get Carousel Request ********************");
829 + WarpUtils.log("[WARP Trace] WARPLY Get Carousel Request is active");
830 + WarpUtils.log("**************************************************");
831 +
832 + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
833 + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
834 +
835 + ListenableFuture<ArrayList<CarouselItem>> futureCarousel = getCarouselRetro(service);
836 +
837 + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCarousel);
838 + ListenableFuture<ArrayList<CarouselItem>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> {
839 + ArrayList<CarouselItem> resultCarousel = (ArrayList<CarouselItem>) results.get(0);
840 + return executorService.submit(() -> resultCarousel);
841 + }, executorService);
842 +
843 + Futures.addCallback(mergedResultFuture, new FutureCallback<ArrayList<CarouselItem>>() {
844 + @Override
845 + public void onSuccess(ArrayList<CarouselItem> mergedResult) {
846 + executorService.shutdownNow();
847 + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult));
848 + }
849 +
850 + @Override
851 + public void onFailure(Throwable throwable) {
852 + executorService.shutdownNow();
853 + new Handler(Looper.getMainLooper()).post(() -> receiver.onFailure(2));
854 + }
855 + }, executorService);
856 + }
857 +
827 public static void getCampaigns(final CallbackReceiver<ArrayList<BannerItem>> receiver) { 858 public static void getCampaigns(final CallbackReceiver<ArrayList<BannerItem>> receiver) {
828 WarpUtils.log("************* WARPLY Get Campaigns Request ********************"); 859 WarpUtils.log("************* WARPLY Get Campaigns Request ********************");
829 WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active"); 860 WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active");
...@@ -938,6 +969,84 @@ public class WarplyManager { ...@@ -938,6 +969,84 @@ public class WarplyManager {
938 return future; 969 return future;
939 } 970 }
940 971
972 + private static /*void*/ ListenableFuture<ArrayList<CarouselItem>> getCarouselRetro(ApiService service/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) {
973 + SettableFuture<ArrayList<CarouselItem>> future = SettableFuture.create();
974 +
975 + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
976 + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
977 + String webId = WarpUtils.getWebId(Warply.getWarplyContext());
978 +
979 + Map<String, Object> jsonParamsCarousel = new ArrayMap<>();
980 + Map<String, Object> jsonParams = new ArrayMap<>();
981 + jsonParams.put("action", "get_carousel");
982 +
983 + jsonParamsCarousel.put("content", jsonParams);
984 + RequestBody carouselRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCarousel)).toString());
985 +
986 + Call<ResponseBody> carouselCall = service.getCarousel(WarplyProperty.getAppUuid(Warply.getWarplyContext()), carouselRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token"));
987 +
988 + carouselCall.enqueue(new Callback<ResponseBody>() {
989 + @Override
990 + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
991 + if (response.code() == 200 && response.body() != null) {
992 + JSONObject jobjCarouselResponse = null;
993 + try {
994 + jobjCarouselResponse = new JSONObject(response.body().string());
995 + } catch (Exception e) {
996 + e.printStackTrace();
997 + }
998 +
999 + if (jobjCarouselResponse != null && jobjCarouselResponse.has("status") && jobjCarouselResponse.optString("status", "2").equals("1")) {
1000 + JSONArray jCarouselBody = null;
1001 + try {
1002 + jCarouselBody = jobjCarouselResponse.optJSONArray("result");
1003 + } catch (Exception e) {
1004 + e.printStackTrace();
1005 + }
1006 +
1007 + if (jCarouselBody != null) {
1008 + ArrayList<CarouselItem> mBannerList = new ArrayList<>();
1009 +
1010 + final ExecutorService executorCarousel = Executors.newFixedThreadPool(1);
1011 + JSONArray finalCarouselJBody = jCarouselBody;
1012 + executorCarousel.submit(() -> {
1013 + try {
1014 + for (int i = 0; i < finalCarouselJBody.length(); ++i) {
1015 + CarouselItem banner = new CarouselItem(finalCarouselJBody.optJSONObject(i));
1016 + mBannerList.add(banner);
1017 + }
1018 + WarplyManagerHelper.setCarouselList(mBannerList);
1019 + future.set(mBannerList);
1020 + } catch (Exception e) {
1021 + future.setException(e);
1022 + }
1023 + executorCarousel.shutdownNow();
1024 + });
1025 + }
1026 + } else {
1027 +// receiver.onFailure(2);
1028 + future.set(new ArrayList<CarouselItem>());
1029 + }
1030 + } else if (String.valueOf(response.code()).startsWith("5")) {
1031 + future.set(new ArrayList<CarouselItem>());
1032 + } else {
1033 +// receiver.onFailure(response.code());
1034 +// future.set(new ArrayList<Campaign>());
1035 + future.setException(new Throwable());
1036 + }
1037 + }
1038 +
1039 + @Override
1040 + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
1041 +// receiver.onFailure(2);
1042 +// future.set(new ArrayList<Campaign>());
1043 + future.setException(new Throwable());
1044 + }
1045 + });
1046 +
1047 + return future;
1048 + }
1049 +
941 private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsPersonalizedRetro(ApiService service, int tries/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) { 1050 private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsPersonalizedRetro(ApiService service, int tries/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) {
942 SettableFuture<ArrayList<Campaign>> future = SettableFuture.create(); 1051 SettableFuture<ArrayList<Campaign>> future = SettableFuture.create();
943 1052
......
...@@ -267,6 +267,7 @@ ...@@ -267,6 +267,7 @@
267 </LinearLayout> 267 </LinearLayout>
268 268
269 <LinearLayout 269 <LinearLayout
270 + android:id="@+id/ll_website"
270 android:layout_width="match_parent" 271 android:layout_width="match_parent"
271 android:layout_height="55dp" 272 android:layout_height="55dp"
272 android:layout_marginTop="16dp" 273 android:layout_marginTop="16dp"
......
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + xmlns:app="http://schemas.android.com/apk/res-auto"
3 xmlns:tools="http://schemas.android.com/tools" 4 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent" 5 android:layout_width="match_parent"
5 - android:layout_height="150dp" 6 + android:layout_height="175dp"
6 android:background="@drawable/shape_rounded_skyblue_skyblue_border"> 7 android:background="@drawable/shape_rounded_skyblue_skyblue_border">
7 8
8 - <LinearLayout 9 + <androidx.constraintlayout.widget.ConstraintLayout
10 + android:id="@+id/cl_top"
9 android:layout_width="match_parent" 11 android:layout_width="match_parent"
10 android:layout_height="wrap_content" 12 android:layout_height="wrap_content"
11 android:layout_alignParentTop="true" 13 android:layout_alignParentTop="true"
12 - android:orientation="horizontal"> 14 + android:paddingHorizontal="10dp"
13 - 15 + android:paddingTop="12dp">
14 - <LinearLayout
15 - android:layout_width="0dp"
16 - android:layout_height="wrap_content"
17 - android:layout_marginTop="16dp"
18 - android:layout_weight="1"
19 - android:orientation="vertical"
20 - android:paddingHorizontal="16dp">
21 -
22 - <TextView
23 - android:id="@+id/tv_merchant"
24 - android:layout_width="wrap_content"
25 - android:layout_height="wrap_content"
26 - android:includeFontPadding="false"
27 - android:maxLines="1"
28 - android:ellipsize="end"
29 - android:textColor="@color/custom_grey3"
30 - android:textSize="14sp"
31 - tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
32 -
33 - <TextView
34 - android:id="@+id/tv_title"
35 - android:layout_width="wrap_content"
36 - android:layout_height="wrap_content"
37 - android:layout_marginTop="8dp"
38 - android:includeFontPadding="false"
39 - android:maxLines="1"
40 - android:ellipsize="end"
41 - android:textColor="@color/custom_black6"
42 - android:textSize="21sp"
43 - tools:text="Móvo 17,95" />
44 -
45 - <TextView
46 - android:id="@+id/tv_description"
47 - android:layout_width="wrap_content"
48 - android:layout_height="wrap_content"
49 - android:layout_marginTop="2dp"
50 - android:includeFontPadding="false"
51 - android:maxLines="2"
52 - android:textColor="@color/custom_grey3"
53 - android:textSize="13sp"
54 - tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
55 - </LinearLayout>
56 16
57 <ImageView 17 <ImageView
58 android:id="@+id/iv_logo" 18 android:id="@+id/iv_logo"
59 android:layout_width="68dp" 19 android:layout_width="68dp"
60 android:layout_height="68dp" 20 android:layout_height="68dp"
61 - android:layout_marginTop="10dp"
62 - android:layout_marginEnd="10dp"
63 android:scaleType="centerInside" 21 android:scaleType="centerInside"
22 + android:background="@drawable/shape_rectangle_rounded_white2"
23 + app:layout_constraintStart_toStartOf="parent"
24 + app:layout_constraintTop_toTopOf="parent"
64 tools:src="@drawable/demo_avis" /> 25 tools:src="@drawable/demo_avis" />
65 - </LinearLayout>
66 -
67 - <LinearLayout
68 - android:layout_width="match_parent"
69 - android:layout_height="wrap_content"
70 - android:layout_alignParentBottom="true"
71 - android:gravity="center"
72 - android:orientation="horizontal"
73 - android:paddingStart="16dp"
74 - android:paddingEnd="10dp"
75 - android:layout_marginBottom="8dp">
76 -
77 - <LinearLayout
78 - android:layout_width="0dp"
79 - android:layout_height="wrap_content"
80 - android:layout_weight="1">
81 26
82 <LinearLayout 27 <LinearLayout
83 android:id="@+id/ll_date" 28 android:id="@+id/ll_date"
...@@ -87,7 +32,9 @@ ...@@ -87,7 +32,9 @@
87 android:gravity="center" 32 android:gravity="center"
88 android:orientation="horizontal" 33 android:orientation="horizontal"
89 android:paddingHorizontal="8dp" 34 android:paddingHorizontal="8dp"
90 - android:paddingVertical="6dp"> 35 + android:paddingVertical="6dp"
36 + app:layout_constraintEnd_toEndOf="parent"
37 + app:layout_constraintTop_toTopOf="parent">
91 38
92 <ImageView 39 <ImageView
93 android:layout_width="14dp" 40 android:layout_width="14dp"
...@@ -109,6 +56,19 @@ ...@@ -109,6 +56,19 @@
109 </LinearLayout> 56 </LinearLayout>
110 57
111 <LinearLayout 58 <LinearLayout
59 + android:layout_width="wrap_content"
60 + android:layout_height="wrap_content"
61 + android:gravity="center"
62 + android:orientation="horizontal"
63 + app:layout_constraintEnd_toEndOf="parent"
64 + app:layout_constraintTop_toTopOf="parent">
65 +
66 + <LinearLayout
67 + android:layout_width="0dp"
68 + android:layout_height="wrap_content"
69 + android:layout_weight="1">
70 +
71 + <LinearLayout
112 android:id="@+id/ll_date_expired" 72 android:id="@+id/ll_date_expired"
113 android:layout_width="wrap_content" 73 android:layout_width="wrap_content"
114 android:layout_height="wrap_content" 74 android:layout_height="wrap_content"
...@@ -129,11 +89,67 @@ ...@@ -129,11 +89,67 @@
129 android:textSize="12sp" /> 89 android:textSize="12sp" />
130 </LinearLayout> 90 </LinearLayout>
131 </LinearLayout> 91 </LinearLayout>
92 + </LinearLayout>
93 + </androidx.constraintlayout.widget.ConstraintLayout>
94 +
95 + <androidx.constraintlayout.widget.ConstraintLayout
96 + android:id="@+id/cl_bottom"
97 + android:layout_width="match_parent"
98 + android:layout_height="wrap_content"
99 + android:layout_alignParentBottom="true"
100 + android:paddingBottom="16dp">
101 +
102 + <LinearLayout
103 + android:layout_width="0dp"
104 + android:layout_height="wrap_content"
105 + android:orientation="vertical"
106 + android:paddingHorizontal="16dp"
107 + app:layout_constraintBottom_toBottomOf="parent"
108 + app:layout_constraintEnd_toStartOf="@+id/header_layout"
109 + app:layout_constraintStart_toStartOf="parent">
110 +
111 + <TextView
112 + android:id="@+id/tv_merchant"
113 + android:layout_width="wrap_content"
114 + android:layout_height="wrap_content"
115 + android:ellipsize="end"
116 + android:includeFontPadding="false"
117 + android:maxLines="1"
118 + android:textColor="@color/custom_grey3"
119 + android:textSize="14sp"
120 + tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
121 +
122 + <TextView
123 + android:id="@+id/tv_title"
124 + android:layout_width="wrap_content"
125 + android:layout_height="wrap_content"
126 + android:layout_marginTop="2dp"
127 + android:ellipsize="end"
128 + android:includeFontPadding="false"
129 + android:maxLines="1"
130 + android:textColor="@color/custom_black6"
131 + android:textSize="21sp"
132 + tools:text="Móvo 17,95" />
133 +
134 + <TextView
135 + android:id="@+id/tv_description"
136 + android:layout_width="wrap_content"
137 + android:layout_height="wrap_content"
138 + android:layout_marginTop="2dp"
139 + android:includeFontPadding="false"
140 + android:maxLines="2"
141 + android:textColor="@color/custom_grey3"
142 + android:textSize="13sp"
143 + tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
144 + </LinearLayout>
132 145
133 <LinearLayout 146 <LinearLayout
134 android:id="@+id/header_layout" 147 android:id="@+id/header_layout"
135 android:layout_width="wrap_content" 148 android:layout_width="wrap_content"
136 - android:layout_height="wrap_content"> 149 + android:layout_height="wrap_content"
150 + android:layout_marginEnd="10dp"
151 + app:layout_constraintBottom_toBottomOf="parent"
152 + app:layout_constraintEnd_toEndOf="parent">
137 153
138 <ImageView 154 <ImageView
139 android:id="@+id/iv_back" 155 android:id="@+id/iv_back"
...@@ -144,5 +160,5 @@ ...@@ -144,5 +160,5 @@
144 android:rotation="180" 160 android:rotation="180"
145 android:src="@drawable/ic_back" /> 161 android:src="@drawable/ic_back" />
146 </LinearLayout> 162 </LinearLayout>
147 - </LinearLayout> 163 + </androidx.constraintlayout.widget.ConstraintLayout>
148 </RelativeLayout> 164 </RelativeLayout>
......