Panagiotis Triantafyllou

additions part1

package ly.warp.sdk.activities;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
......@@ -27,10 +30,10 @@ import java.util.List;
import java.util.Map;
import ly.warp.sdk.R;
import ly.warp.sdk.io.adapters.BannerAdapter;
import ly.warp.sdk.io.adapters.CarouselAdapter;
import ly.warp.sdk.io.adapters.CouponsetAdapter;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.BannerItem;
import ly.warp.sdk.io.models.CarouselItem;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.Couponset;
import ly.warp.sdk.io.models.User;
......@@ -57,7 +60,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
/* View Pager */
// private ViewPager2 mBannerViewPager;
private RecyclerView mRvBannerViewPager;
private BannerAdapter mBannerAdapter;
private CarouselAdapter mBannerAdapter;
/* Pagination */
// private LinearLayout mDotsContainer;
// private List<ImageView> mDots;
......@@ -87,8 +90,8 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
mSectionsLoading.setVisibility(View.VISIBLE);
WarplyManager.getCoupons(mCouponsCallback);
WarplyManager.getCampaigns(mCampaignsCallback);
WarplyManager.getCouponsets(mCouponsetsCallback);
WarplyManager.getCarousel(mCarouselCallback);
WarplyManager.getCouponsets(null, null, mCouponsetsCallback);
}
@Override
......@@ -201,15 +204,16 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
mRvBannerViewPager.setLayoutManager(layoutManager);
mRvBannerViewPager.setHasFixedSize(true);
mBannerAdapter = new BannerAdapter(this, WarplyManagerHelper.getBannerList());
mBannerAdapter.setOnBannerCampaignClickListener(campaign -> {
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(campaign)));
});
mBannerAdapter.setOnBannerContentClickListener(article -> {
if (article != null && article.getExtraFields() != null) {
String couponsetUuid = article.getExtraFields().optString("url_link", null);
if (couponsetUuid != null && !couponsetUuid.isEmpty()) {
Couponset matchedCouponset = findCouponsetByUuid(couponsetUuid);
mBannerAdapter = new CarouselAdapter(this, WarplyManagerHelper.getCarouselList());
mBannerAdapter.setOnBannerClickListener(carouselItem -> {
// startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(carouselItem.getUrl())));
if (!TextUtils.isEmpty(carouselItem.getUrl())) {
if (carouselItem.getUrl().contains("Offers?")) {
//TODO: category uuid
} else if (carouselItem.getUrl().contains("singleOffer")) {
if (!TextUtils.isEmpty(carouselItem.getUuid())) {
Couponset matchedCouponset = findCouponsetByUuid(carouselItem.getUuid());
if (matchedCouponset != null) {
Intent myIntent = new Intent(HomeActivity.this, SingleCouponsetActivity.class);
myIntent.putExtra(SingleCouponsetActivity.EXTRA_OFFER_ITEM, (Parcelable) matchedCouponset);
......@@ -217,6 +221,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
}
}
}
}
});
/* View Pager */
......@@ -343,15 +348,15 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
return null;
}
private final CallbackReceiver<ArrayList<BannerItem>> mCampaignsCallback = new CallbackReceiver<ArrayList<BannerItem>>() {
private final CallbackReceiver<ArrayList<CarouselItem>> mCarouselCallback = new CallbackReceiver<ArrayList<CarouselItem>>() {
@Override
public void onSuccess(ArrayList<BannerItem> result) {
public void onSuccess(ArrayList<CarouselItem> result) {
mPbLoading.setVisibility(View.GONE);
if (result != null && !result.isEmpty()) {
// Preloads the campaigns' images
result.forEach(bannerItem -> {
Glide.with(getApplicationContext())
.load(bannerItem.isCampaign() ? bannerItem.getCampaign().getLogoUrl() : bannerItem.getContent().getImgPreview())
.load(bannerItem.getAppImg())
.diskCacheStrategy(DiskCacheStrategy.DATA)
.preload();
});
......
package ly.warp.sdk.activities;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
......@@ -45,7 +47,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
private TextView mTvSmallDescription;
private TextView mTvFullDescription;
private TextView mTvEndDate;
private LinearLayout mLlDate, mLlShopsButton;
private LinearLayout mLlDate, mLlShopsButton, mLlWebsiteButton;
private TextView mTvValue;
private TextView mTvMoreButton;
private ImageView mIvImage;
......@@ -107,6 +109,20 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
Intent myIntent = new Intent(SingleCouponActivity.this, ShopsActivity.class);
myIntent.putExtra(SingleCouponActivity.EXTRA_MERCHANT_UUID, mOfferItem.getMerchantUuid());
startActivity(myIntent);
return;
}
if (v.getId() == R.id.ll_website) {
if (mOfferItem != null && mOfferItem.getMerchantDetails() != null
&& !TextUtils.isEmpty(mOfferItem.getMerchantDetails().getWebsite())
&& mOfferItem.getMerchantDetails().getWebsite().length() > 8) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(mOfferItem.getMerchantDetails().getWebsite()));
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
}
}
......@@ -121,6 +137,9 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
mLlShopsButton = findViewById(R.id.ll_shops);
mLlShopsButton.setOnClickListener(this);
mLlWebsiteButton = findViewById(R.id.ll_website);
mLlWebsiteButton.setOnClickListener(this);
// Initialize views
mTvSmallDescription = findViewById(R.id.tv_coupon_small_description);
mTvFullDescription = findViewById(R.id.tv_coupon_full_description);
......@@ -202,8 +221,8 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
.into(mIvImage);
}
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getAdmin_name() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getAdmin_name()))
mTvMerchantName.setText(mOfferItem.getCouponsetDetails().getAdmin_name());
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getMerchantAdminName() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getMerchantAdminName()))
mTvMerchantName.setText(mOfferItem.getCouponsetDetails().getMerchantAdminName());
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getName() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getName()))
mTvValue.setText(mOfferItem.getCouponsetDetails().getName());
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getShort_description() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getShort_description()))
......
......@@ -3,6 +3,8 @@ package ly.warp.sdk.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.View;
......@@ -198,8 +200,8 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
.into(mIvImage);
}
if (!TextUtils.isEmpty(mOfferItem.getAdmin_name()))
mTvMerchantName.setText(mOfferItem.getAdmin_name());
if (!TextUtils.isEmpty(mOfferItem.getMerchantAdminName()))
mTvMerchantName.setText(mOfferItem.getMerchantAdminName());
if (!TextUtils.isEmpty(mOfferItem.getName()))
mTvValue.setText(mOfferItem.getName());
if (!TextUtils.isEmpty(mOfferItem.getShort_description()))
......@@ -339,17 +341,18 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
@Override
public void onSuccess(JSONObject result) {
mPbLoading.setVisibility(View.GONE);
Toast.makeText(SingleCouponsetActivity.this, "RETRIEVE SUCCESS", Toast.LENGTH_SHORT).show();
// Coupon coupon = new Coupon();
// coupon.setCoupon(result.optString("coupon", ""));
// coupon.setExpiration(result.optString("expiration", ""));
// coupon.setCouponsetDetails(mOfferItem);
// Intent myIntent = new Intent(SingleCouponsetActivity.this, SingleCouponActivity.class);
// myIntent.putExtra(SingleCouponActivity.EXTRA_OFFER_ITEM, (Parcelable) coupon);
// startActivity(myIntent);
mRedeemButton.setVisibility(View.GONE);
mSuccessButton.setVisibility(View.VISIBLE);
new Handler(Looper.getMainLooper()).postDelayed(() -> {
Coupon coupon = new Coupon();
coupon.setCoupon(result.optString("coupon", ""));
coupon.setExpiration(result.optString("expiration", ""));
coupon.setCouponsetDetails(mOfferItem);
Intent myIntent = new Intent(SingleCouponsetActivity.this, SingleCouponActivity.class);
myIntent.putExtra(SingleCouponActivity.EXTRA_OFFER_ITEM, (Parcelable) coupon);
startActivity(myIntent);
}, 500);
}
@Override
......
package ly.warp.sdk.io.adapters;
import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import java.util.ArrayList;
import ly.warp.sdk.R;
import ly.warp.sdk.io.models.CarouselItem;
import ly.warp.sdk.utils.TopRoundedCornersTransformation;
public class CarouselAdapter extends RecyclerView.Adapter<CarouselAdapter.BannerViewHolder> {
private final Context mContext;
private final ArrayList<CarouselItem> mBannerItems;
private OnBannerClickListener mListenerBanner;
public interface OnBannerClickListener {
void onBannerClick(CarouselItem item);
}
public CarouselAdapter(Context context, ArrayList<CarouselItem> carouselItems) {
this.mContext = context;
this.mBannerItems = carouselItems;
}
public void setOnBannerClickListener(OnBannerClickListener listener) {
this.mListenerBanner = listener;
}
@NonNull
@Override
public BannerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_banner, parent, false);
return new BannerViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull BannerViewHolder holder, int position) {
CarouselItem bannerItem = mBannerItems.get(position);
int radiusInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 13,
mContext.getResources().getDisplayMetrics());
if (bannerItem != null) {
Glide.with(mContext)
// .setDefaultRequestOptions(
// RequestOptions
// .placeholderOf(R.drawable.demo_logo)
// .error(R.drawable.demo_logo))
.load(bannerItem.getAppImg())
.diskCacheStrategy(DiskCacheStrategy.DATA)
.transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true))
.into(holder.imageView);
holder.itemView.setOnClickListener(v -> {
if (mListenerBanner != null) {
mListenerBanner.onBannerClick(bannerItem);
}
});
}
}
@Override
public int getItemCount() {
return mBannerItems.size();
}
static class BannerViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
BannerViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.iv_banner);
}
}
}
......@@ -170,7 +170,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
llDateExpired.setVisibility(View.GONE);
}
tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getAdmin_name()) ? couponItem.getCouponsetDetails().getAdmin_name().trim() : "");
tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getMerchantAdminName()) ? couponItem.getCouponsetDetails().getMerchantAdminName().trim() : "");
tvTitle.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getName()) ? couponItem.getCouponsetDetails().getName().trim() : "");
tvDescription.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getShort_description()) ? couponItem.getCouponsetDetails().getShort_description().trim() : "");
if (couponItem.getExpiration() != null && !couponItem.getExpiration().isEmpty()) {
......@@ -205,7 +205,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
}
}
loadMerchantLogo(couponItem.getMerchantDetails().getImgPreview(), couponItem.getStatus());
loadMerchantLogo(couponItem.getMerchantDetails().getAppImgPreview(), couponItem.getStatus());
}
private String formatValidityDate(String endDate) {
......@@ -267,10 +267,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
.transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true))
.into(ivLogo);
}
ivLogo.setVisibility(View.VISIBLE);
} else {
ivLogo.setVisibility(View.GONE);
}
}
}
......
......@@ -104,10 +104,10 @@ public class CouponsetAdapter extends RecyclerView.Adapter<CouponsetAdapter.Coup
tvValidity.setVisibility(View.GONE);
}
loadCouponsetImage(couponset.getImgPreview());
loadCouponsetImage(couponset.getAppImgPreview());
if (couponset.getMerchant() != null && couponset.getMerchant().getImgPreview() != null) {
loadMerchantLogo(couponset.getMerchant().getImgPreview());
if (couponset.getMerchantDetails() != null && couponset.getMerchantDetails().getPreviewImg() != null) {
loadMerchantLogo(couponset.getMerchantDetails().getPreviewImg());
} else {
ivLogo.setVisibility(View.GONE);
}
......
package ly.warp.sdk.io.models;
import android.os.Parcel;
import android.os.Parcelable;
import org.json.JSONObject;
import java.io.Serializable;
/**
* Model representing a single item from the carousel (get_carousel) API response.
*/
public class CarouselItem implements Parcelable, Serializable {
private static final long serialVersionUID = 7812345678901234567L;
private static final String APP_IMG = "app_img";
private static final String APP_URL = "app_url";
private static final String ENTITY = "entity";
private static final String NAME = "name";
private static final String URL = "url";
private static final String UUID = "uuid";
private static final String WEB_IMG = "web_img";
private static final String WEB_IMG_RESPONSIVE = "web_img_responsive";
private String appImg;
private String appUrl;
private String entity;
private String name;
private String url;
private String uuid;
private String webImg;
private String webImgResponsive;
private static String optNullableString(JSONObject json, String key) {
return json.isNull(key) ? null : json.optString(key);
}
public CarouselItem() {
this.appImg = null;
this.appUrl = null;
this.entity = null;
this.name = null;
this.url = null;
this.uuid = null;
this.webImg = null;
this.webImgResponsive = null;
}
public CarouselItem(JSONObject json) {
if (json != null) {
this.appImg = optNullableString(json, APP_IMG);
this.appUrl = optNullableString(json, APP_URL);
this.entity = optNullableString(json, ENTITY);
this.name = optNullableString(json, NAME);
this.url = optNullableString(json, URL);
this.uuid = optNullableString(json, UUID);
this.webImg = optNullableString(json, WEB_IMG);
this.webImgResponsive = optNullableString(json, WEB_IMG_RESPONSIVE);
}
}
public CarouselItem(Parcel source) {
this.appImg = source.readString();
this.appUrl = source.readString();
this.entity = source.readString();
this.name = source.readString();
this.url = source.readString();
this.uuid = source.readString();
this.webImg = source.readString();
this.webImgResponsive = source.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.appImg);
dest.writeString(this.appUrl);
dest.writeString(this.entity);
dest.writeString(this.name);
dest.writeString(this.url);
dest.writeString(this.uuid);
dest.writeString(this.webImg);
dest.writeString(this.webImgResponsive);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<CarouselItem> CREATOR = new Creator<CarouselItem>() {
@Override
public CarouselItem createFromParcel(Parcel source) {
return new CarouselItem(source);
}
@Override
public CarouselItem[] newArray(int size) {
return new CarouselItem[size];
}
};
// ================================================================================
// Getters
// ================================================================================
public String getAppImg() {
return appImg;
}
public String getAppUrl() {
return appUrl;
}
public String getEntity() {
return entity;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public String getUuid() {
return uuid;
}
public String getWebImg() {
return webImg;
}
public String getWebImgResponsive() {
return webImgResponsive;
}
// ================================================================================
// Setters
// ================================================================================
public void setAppImg(String appImg) {
this.appImg = appImg;
}
public void setAppUrl(String appUrl) {
this.appUrl = appUrl;
}
public void setEntity(String entity) {
this.entity = entity;
}
public void setName(String name) {
this.name = name;
}
public void setUrl(String url) {
this.url = url;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public void setWebImg(String webImg) {
this.webImg = webImg;
}
public void setWebImgResponsive(String webImgResponsive) {
this.webImgResponsive = webImgResponsive;
}
}
......@@ -92,6 +92,13 @@ public class Couponset implements Parcelable, Serializable {
private static final String OFFER_CATEGORY = "offer_category";
private static final String TAGGING = "tagging";
private static final String REGIONS = "regions";
private static final String MERCHANT_ADMIN_NAME = "merchant_admin_name";
private static final String MERCHANT_IMG_PREVIEW = "merchant_img_preview";
private static final String MERCHANT_DETAILS = "merchant_details";
private static final String MERCHANT_WEBSITE = "merchant_website";
private static final String SCORE = "score";
private static final String APP_IMG_PREVIEW = "app_img_preview";
private static final String APP_IMGS = "app_imgs";
/* Member variables of the Couponset object */
......@@ -141,6 +148,13 @@ public class Couponset implements Parcelable, Serializable {
private JSONObject tagging;
private JSONArray regions;
private Merchant merchant;
private String merchantAdminName;
private String merchantImgPreview;
private String merchantWebsite;
private MerchantDetails merchantDetails;
private int score;
private String appImgPreview;
private JSONArray appImgs;
/**
* Helper method to get a nullable String from a JSONObject.
......@@ -197,6 +211,13 @@ public class Couponset implements Parcelable, Serializable {
this.tagging = null;
this.regions = null;
this.merchant = null;
this.merchantAdminName = null;
this.merchantImgPreview = null;
this.merchantWebsite = null;
this.merchantDetails = null;
this.score = 0;
this.appImgPreview = null;
this.appImgs = null;
}
public Couponset(boolean isUniversal) {
......@@ -233,6 +254,13 @@ public class Couponset implements Parcelable, Serializable {
this.offerCategory = null;
this.tagging = null;
this.regions = null;
this.merchantAdminName = null;
this.merchantImgPreview = null;
this.merchantWebsite = null;
this.merchantDetails = null;
this.score = 0;
this.appImgPreview = null;
this.appImgs = null;
}
/**
......@@ -301,6 +329,14 @@ public class Couponset implements Parcelable, Serializable {
this.offerCategory = optNullableString(json, OFFER_CATEGORY);
this.tagging = json.optJSONObject(TAGGING);
this.regions = json.optJSONArray(REGIONS);
this.merchantAdminName = optNullableString(json, MERCHANT_ADMIN_NAME);
this.merchantImgPreview = optNullableString(json, MERCHANT_IMG_PREVIEW);
this.merchantWebsite = optNullableString(json, MERCHANT_WEBSITE);
JSONObject merchantDetailsJson = json.optJSONObject(MERCHANT_DETAILS);
this.merchantDetails = merchantDetailsJson != null ? new MerchantDetails(merchantDetailsJson) : null;
this.score = json.optInt(SCORE, 0);
this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
this.appImgs = json.optJSONArray(APP_IMGS);
}
}
......@@ -324,6 +360,7 @@ public class Couponset implements Parcelable, Serializable {
this.active = json.optBoolean(ACTIVE);
this.buyable = json.optBoolean(BUYABLE);
this.name = optNullableString(json, NAME);
this.description = optNullableString(json, DESCRIPTION);
this.short_description = optNullableString(json, SHORT_DESCRIPTION);
this.discount = optNullableString(json, DISCOUNT);
this.category = optNullableString(json, CATEGORY);
......@@ -343,6 +380,14 @@ public class Couponset implements Parcelable, Serializable {
this.offerCategory = optNullableString(json, OFFER_CATEGORY);
this.tagging = json.optJSONObject(TAGGING);
this.regions = json.optJSONArray(REGIONS);
this.merchantAdminName = optNullableString(json, MERCHANT_ADMIN_NAME);
this.merchantImgPreview = optNullableString(json, MERCHANT_IMG_PREVIEW);
this.merchantWebsite = optNullableString(json, MERCHANT_WEBSITE);
JSONObject merchantDetailsJson = json.optJSONObject(MERCHANT_DETAILS);
this.merchantDetails = merchantDetailsJson != null ? new MerchantDetails(merchantDetailsJson) : null;
this.score = json.optInt(SCORE, 0);
this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
this.appImgs = json.optJSONArray(APP_IMGS);
}
}
......@@ -438,6 +483,19 @@ public class Couponset implements Parcelable, Serializable {
} catch (JSONException e) {
this.regions = null;
}
this.merchant = source.readParcelable(Merchant.class.getClassLoader());
this.merchantAdminName = source.readString();
this.merchantImgPreview = source.readString();
this.merchantWebsite = source.readString();
this.merchantDetails = source.readParcelable(MerchantDetails.class.getClassLoader());
this.score = source.readInt();
this.appImgPreview = source.readString();
try {
String appImgsStr = source.readString();
this.appImgs = appImgsStr != null ? new JSONArray(appImgsStr) : null;
} catch (JSONException e) {
this.appImgs = null;
}
}
@Override
......@@ -487,6 +545,14 @@ public class Couponset implements Parcelable, Serializable {
dest.writeString(this.offerCategory);
dest.writeString(this.tagging != null ? this.tagging.toString() : null);
dest.writeString(this.regions != null ? this.regions.toString() : null);
dest.writeParcelable(this.merchant, flags);
dest.writeString(this.merchantAdminName);
dest.writeString(this.merchantImgPreview);
dest.writeString(this.merchantWebsite);
dest.writeParcelable(this.merchantDetails, flags);
dest.writeInt(this.score);
dest.writeString(this.appImgPreview);
dest.writeString(this.appImgs != null ? this.appImgs.toString() : null);
}
/**
......@@ -541,6 +607,13 @@ public class Couponset implements Parcelable, Serializable {
jObj.put(OFFER_CATEGORY, this.offerCategory != null ? this.offerCategory : JSONObject.NULL);
jObj.put(TAGGING, this.tagging != null ? this.tagging : JSONObject.NULL);
jObj.put(REGIONS, this.regions != null ? this.regions : JSONObject.NULL);
jObj.put(MERCHANT_ADMIN_NAME, this.merchantAdminName != null ? this.merchantAdminName : JSONObject.NULL);
jObj.put(MERCHANT_IMG_PREVIEW, this.merchantImgPreview != null ? this.merchantImgPreview : JSONObject.NULL);
jObj.put(MERCHANT_WEBSITE, this.merchantWebsite != null ? this.merchantWebsite : JSONObject.NULL);
jObj.put(MERCHANT_DETAILS, this.merchantDetails != null ? new JSONObject(this.merchantDetails.toString()) : JSONObject.NULL);
jObj.putOpt(SCORE, this.score);
jObj.put(APP_IMG_PREVIEW, this.appImgPreview != null ? this.appImgPreview : JSONObject.NULL);
jObj.put(APP_IMGS, this.appImgs != null ? this.appImgs : JSONObject.NULL);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
......@@ -799,6 +872,34 @@ public class Couponset implements Parcelable, Serializable {
return merchant;
}
public String getMerchantAdminName() {
return merchantAdminName;
}
public String getMerchantImgPreview() {
return merchantImgPreview;
}
public String getMerchantWebsite() {
return merchantWebsite;
}
public MerchantDetails getMerchantDetails() {
return merchantDetails;
}
public int getScore() {
return score;
}
public String getAppImgPreview() {
return appImgPreview;
}
public JSONArray getAppImgs() {
return appImgs;
}
// ================================================================================
// Setters
// ================================================================================
......@@ -987,6 +1088,34 @@ public class Couponset implements Parcelable, Serializable {
this.merchant = merchant;
}
public void setMerchantAdminName(String merchantAdminName) {
this.merchantAdminName = merchantAdminName;
}
public void setMerchantImgPreview(String merchantImgPreview) {
this.merchantImgPreview = merchantImgPreview;
}
public void setMerchantWebsite(String merchantWebsite) {
this.merchantWebsite = merchantWebsite;
}
public void setMerchantDetails(MerchantDetails merchantDetails) {
this.merchantDetails = merchantDetails;
}
public void setScore(int score) {
this.score = score;
}
public void setAppImgPreview(String appImgPreview) {
this.appImgPreview = appImgPreview;
}
public void setAppImgs(JSONArray appImgs) {
this.appImgs = appImgs;
}
@Override
public int describeContents() {
return 0;
......
......@@ -101,6 +101,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
private static final String MIN_PRICE = "min_price";
private static final String MAX_PRICE = "max_price";
private static final String URL_NAME = "url_name";
private static final String APP_IMG_PREVIEW = "app_img_preview";
private static final String APP_IMGS = "app_imgs";
/* Member variables of the Merchant object */
......@@ -154,6 +156,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
private String minPrice;
private String maxPrice;
private String urlName;
private String appImgPreview;
private JSONArray appImgs;
private LatLng coordinates;
/**
......@@ -215,6 +219,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
this.minPrice = null;
this.maxPrice = null;
this.urlName = null;
this.appImgPreview = null;
this.appImgs = null;
this.coordinates = new LatLng(
this.latitude != null ? this.latitude : 0.0,
this.longitude != null ? this.longitude : 0.0);
......@@ -304,6 +310,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
this.minPrice = optNullableString(json, MIN_PRICE);
this.maxPrice = optNullableString(json, MAX_PRICE);
this.urlName = optNullableString(json, URL_NAME);
this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
this.appImgs = json.optJSONArray(APP_IMGS);
this.coordinates = new LatLng(
this.latitude != null ? this.latitude : 0.0,
this.longitude != null ? this.longitude : 0.0);
......@@ -325,6 +333,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
this.admin_name = optNullableString(json, ADMIN_NAME);
this.img_preview = optNullableString(json, IMG_PREVIEW);
this.website = optNullableString(json, WEBSITE);
this.appImgPreview = optNullableString(json, APP_IMG_PREVIEW);
this.appImgs = json.optJSONArray(APP_IMGS);
}
}
......@@ -408,6 +418,13 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
this.minPrice = source.readString();
this.maxPrice = source.readString();
this.urlName = source.readString();
this.appImgPreview = source.readString();
try {
String appImgsStr = source.readString();
this.appImgs = appImgsStr != null ? new JSONArray(appImgsStr) : null;
} catch (JSONException e) {
this.appImgs = null;
}
this.coordinates = new LatLng(
this.latitude != null ? this.latitude : 0.0,
this.longitude != null ? this.longitude : 0.0);
......@@ -465,6 +482,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
dest.writeString(this.minPrice);
dest.writeString(this.maxPrice);
dest.writeString(this.urlName);
dest.writeString(this.appImgPreview);
dest.writeString(this.appImgs != null ? this.appImgs.toString() : null);
dest.writeParcelable(coordinates, flags);
}
......@@ -526,6 +545,8 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
jObj.put(MIN_PRICE, this.minPrice != null ? this.minPrice : JSONObject.NULL);
jObj.put(MAX_PRICE, this.maxPrice != null ? this.maxPrice : JSONObject.NULL);
jObj.put(URL_NAME, this.urlName != null ? this.urlName : JSONObject.NULL);
jObj.put(APP_IMG_PREVIEW, this.appImgPreview != null ? this.appImgPreview : JSONObject.NULL);
jObj.put(APP_IMGS, this.appImgs != null ? this.appImgs : JSONObject.NULL);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
......@@ -790,6 +811,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
return urlName;
}
public String getAppImgPreview() {
return appImgPreview;
}
public JSONArray getAppImgs() {
return appImgs;
}
// ================================================================================
// Setters
// ================================================================================
......@@ -994,6 +1023,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem {
this.urlName = urlName;
}
public void setAppImgPreview(String appImgPreview) {
this.appImgPreview = appImgPreview;
}
public void setAppImgs(JSONArray appImgs) {
this.appImgs = appImgs;
}
public void setCoordinates(LatLng coordinates) {
this.coordinates = coordinates;
}
......
package ly.warp.sdk.io.models;
import android.os.Parcel;
import android.os.Parcelable;
import org.json.JSONObject;
import java.io.Serializable;
/**
* Lightweight model representing the merchant_details object inside a Couponset response.
*/
public class MerchantDetails implements Parcelable, Serializable {
private static final long serialVersionUID = 3891274651234567890L;
private static final String ADMIN_NAME = "admin_name";
private static final String PREVIEW_IMG = "preview_img";
private static final String UUID = "uuid";
private static final String WEBSITE = "website";
private String adminName;
private String previewImg;
private String uuid;
private String website;
private static String optNullableString(JSONObject json, String key) {
return json.isNull(key) ? null : json.optString(key);
}
public MerchantDetails() {
this.adminName = null;
this.previewImg = null;
this.uuid = null;
this.website = null;
}
public MerchantDetails(JSONObject json) {
if (json != null) {
this.adminName = optNullableString(json, ADMIN_NAME);
this.previewImg = optNullableString(json, PREVIEW_IMG);
this.uuid = optNullableString(json, UUID);
this.website = optNullableString(json, WEBSITE);
}
}
public MerchantDetails(Parcel source) {
this.adminName = source.readString();
this.previewImg = source.readString();
this.uuid = source.readString();
this.website = source.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.adminName);
dest.writeString(this.previewImg);
dest.writeString(this.uuid);
dest.writeString(this.website);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<MerchantDetails> CREATOR = new Creator<MerchantDetails>() {
@Override
public MerchantDetails createFromParcel(Parcel source) {
return new MerchantDetails(source);
}
@Override
public MerchantDetails[] newArray(int size) {
return new MerchantDetails[size];
}
};
public String toString() {
JSONObject jObj = new JSONObject();
try {
jObj.put(ADMIN_NAME, this.adminName != null ? this.adminName : JSONObject.NULL);
jObj.put(PREVIEW_IMG, this.previewImg != null ? this.previewImg : JSONObject.NULL);
jObj.put(UUID, this.uuid != null ? this.uuid : JSONObject.NULL);
jObj.put(WEBSITE, this.website != null ? this.website : JSONObject.NULL);
} catch (Exception e) {
e.printStackTrace();
}
return jObj.toString();
}
// ================================================================================
// Getters
// ================================================================================
public String getAdminName() {
return adminName;
}
public String getPreviewImg() {
return previewImg;
}
public String getUuid() {
return uuid;
}
public String getWebsite() {
return website;
}
// ================================================================================
// Setters
// ================================================================================
public void setAdminName(String adminName) {
this.adminName = adminName;
}
public void setPreviewImg(String previewImg) {
this.previewImg = previewImg;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public void setWebsite(String website) {
this.website = website;
}
}
......@@ -135,6 +135,18 @@ public interface ApiService {
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getCarousel(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/api/mobile/v2/{appUuid}/context/")
Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid,
@Body RequestBody request,
......
......@@ -35,6 +35,7 @@ import ly.warp.sdk.Warply;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.io.models.BannerItem;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CarouselItem;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.Couponset;
......@@ -59,6 +60,7 @@ public class WarplyManagerHelper {
private static ArrayList<Coupon> mCouponList = new ArrayList<Coupon>();
private static ArrayList<Campaign> mCampaignListAll = new ArrayList<Campaign>();
private static ArrayList<BannerItem> mBannerListAll = new ArrayList<BannerItem>();
private static ArrayList<CarouselItem> mCarouselListAll = new ArrayList<>();
private static LinkedHashMap<String, ArrayList<Couponset>> mCouponsetCategorizedMap = new LinkedHashMap<>();
private static User mUser = null;
......@@ -96,6 +98,15 @@ public class WarplyManagerHelper {
return mBannerListAll;
}
public static void setCarouselList(ArrayList<CarouselItem> carouselList) {
mCarouselListAll.clear();
mCarouselListAll.addAll(carouselList);
}
public static ArrayList<CarouselItem> getCarouselList() {
return mCarouselListAll;
}
public static void setCouponsetCategorizedMap(LinkedHashMap<String, ArrayList<Couponset>> couponsetMap) {
mCouponsetCategorizedMap.clear();
mCouponsetCategorizedMap.putAll(couponsetMap);
......
......@@ -267,6 +267,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/ll_website"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="16dp"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_height="175dp"
android:background="@drawable/shape_rounded_skyblue_skyblue_border">
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingHorizontal="16dp">
<TextView
android:id="@+id/tv_merchant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@color/custom_grey3"
android:textSize="14sp"
tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:includeFontPadding="false"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@color/custom_black6"
android:textSize="21sp"
tools:text="Móvo 17,95" />
<TextView
android:id="@+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:includeFontPadding="false"
android:maxLines="2"
android:textColor="@color/custom_grey3"
android:textSize="13sp"
tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
</LinearLayout>
android:paddingHorizontal="10dp"
android:paddingTop="12dp">
<ImageView
android:id="@+id/iv_logo"
android:layout_width="68dp"
android:layout_height="68dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:scaleType="centerInside"
android:background="@drawable/shape_rectangle_rounded_white2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/demo_avis" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingEnd="10dp"
android:layout_marginBottom="8dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:id="@+id/ll_date"
......@@ -87,7 +32,9 @@
android:gravity="center"
android:orientation="horizontal"
android:paddingHorizontal="8dp"
android:paddingVertical="6dp">
android:paddingVertical="6dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="14dp"
......@@ -109,6 +56,19 @@
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:id="@+id/ll_date_expired"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -129,11 +89,67 @@
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="16dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/header_layout"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="@+id/tv_merchant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@color/custom_grey3"
android:textSize="14sp"
tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:textColor="@color/custom_black6"
android:textSize="21sp"
tools:text="Móvo 17,95" />
<TextView
android:id="@+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:includeFontPadding="false"
android:maxLines="2"
android:textColor="@color/custom_grey3"
android:textSize="13sp"
tools:text="2 πίτσες &amp; Coca-COLA 1,5lt" />
</LinearLayout>
<LinearLayout
android:id="@+id/header_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:id="@+id/iv_back"
......@@ -144,5 +160,5 @@
android:rotation="180"
android:src="@drawable/ic_back" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
......