Panagiotis Triantafyllou

redesign part6

......@@ -13,6 +13,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import com.bumptech.glide.Glide;
......@@ -20,6 +21,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
......@@ -42,6 +44,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
private TextView mTvSmallDescription;
private TextView mTvFullDescription;
private TextView mTvEndDate;
private LinearLayout mLlDate;
private TextView mTvValue;
private TextView mTvMoreButton;
private ImageView mIvImage;
......@@ -105,6 +108,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
mTvSmallDescription = findViewById(R.id.tv_coupon_small_description);
mTvFullDescription = findViewById(R.id.tv_coupon_full_description);
mTvEndDate = findViewById(R.id.tv_coupon_end_date);
mLlDate = findViewById(R.id.ll_date);
mTvValue = findViewById(R.id.tv_coupon_value);
mIvImage = findViewById(R.id.iv_coupon_image);
mTvMoreButton = findViewById(R.id.tv_more_button);
......@@ -139,8 +143,35 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
if (mOfferItem != null) {
if (mOfferItem.getExpiration() != null && !mOfferItem.getExpiration().isEmpty()) {
String formattedDate = formatValidityDate(mOfferItem.getExpiration());
mTvEndDate.setText(getString(R.string.demo_valid_until, formattedDate));
String rawDate = mOfferItem.getExpiration().trim();
Date parsedDate = parseDate(rawDate);
if (parsedDate != null) {
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
Calendar expiry = Calendar.getInstance();
expiry.setTime(parsedDate);
expiry.set(Calendar.HOUR_OF_DAY, 0);
expiry.set(Calendar.MINUTE, 0);
expiry.set(Calendar.SECOND, 0);
expiry.set(Calendar.MILLISECOND, 0);
long daysLeft = (expiry.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24);
if (daysLeft >= 0 && daysLeft <= 3) {
mTvEndDate.setText(getString(R.string.demo_valid_days, daysLeft + " days"));
mLlDate.setBackgroundResource(R.drawable.demo_shape_yellow_border_yellow);
mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_gold));
} else {
mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate)));
mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey);
mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7));
}
} else {
mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate)));
mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey);
mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7));
}
}
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getImg_preview() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getImg_preview())) {
......@@ -194,6 +225,21 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
}
}
private Date parseDate(String endDate) {
String[] formats = {
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm",
"yyyy-MM-dd'T'HH:mm:ss"
};
for (String format : formats) {
try {
return new SimpleDateFormat(format, Locale.getDefault()).parse(endDate);
} catch (ParseException ignored) {
}
}
return null;
}
private void setupCouponCodeSection() {
mTvCouponCode.setText(mOfferItem.getCoupon());
......
......@@ -13,6 +13,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import com.bumptech.glide.Glide;
......@@ -22,6 +23,7 @@ import org.json.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
......@@ -47,6 +49,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
private TextView mTvSmallDescription;
private TextView mTvFullDescription;
private TextView mTvEndDate;
private LinearLayout mLlDate;
private TextView mTvValue;
private TextView mTvMoreButton;
private ImageView mIvImage;
......@@ -124,6 +127,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
mTvSmallDescription = findViewById(R.id.tv_coupon_small_description);
mTvFullDescription = findViewById(R.id.tv_coupon_full_description);
mTvEndDate = findViewById(R.id.tv_coupon_end_date);
mLlDate = findViewById(R.id.ll_date);
mTvValue = findViewById(R.id.tv_coupon_value);
mIvImage = findViewById(R.id.iv_coupon_image);
mTvMoreButton = findViewById(R.id.tv_more_button);
......@@ -152,8 +156,35 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
if (mOfferItem != null) {
if (mOfferItem.getEndDate() != null && !mOfferItem.getEndDate().isEmpty()) {
String formattedDate = formatValidityDate(mOfferItem.getEndDate());
mTvEndDate.setText(getString(R.string.demo_valid_until, formattedDate));
String rawDate = mOfferItem.getEndDate().trim();
Date parsedDate = parseDate(rawDate);
if (parsedDate != null) {
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
Calendar expiry = Calendar.getInstance();
expiry.setTime(parsedDate);
expiry.set(Calendar.HOUR_OF_DAY, 0);
expiry.set(Calendar.MINUTE, 0);
expiry.set(Calendar.SECOND, 0);
expiry.set(Calendar.MILLISECOND, 0);
long daysLeft = (expiry.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24);
if (daysLeft >= 0 && daysLeft <= 3) {
mTvEndDate.setText(getString(R.string.demo_valid_days, daysLeft + " days"));
mLlDate.setBackgroundResource(R.drawable.demo_shape_yellow_border_yellow);
mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_gold));
} else {
mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate)));
mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey);
mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7));
}
} else {
mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate)));
mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey);
mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7));
}
}
if (!TextUtils.isEmpty(mOfferItem.getImg_preview())) {
......@@ -199,6 +230,21 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
}
}
private Date parseDate(String endDate) {
String[] formats = {
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm",
"yyyy-MM-dd'T'HH:mm:ss"
};
for (String format : formats) {
try {
return new SimpleDateFormat(format, Locale.getDefault()).parse(endDate);
} catch (ParseException ignored) {
}
}
return null;
}
private void setupMoreButton() {
// Wait for layout to be ready to check if text is truncated
mTvFullDescription.post(new Runnable() {
......
......@@ -7,8 +7,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
......@@ -19,11 +22,13 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import ly.warp.sdk.R;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.utils.GrayscaleTransformation;
import ly.warp.sdk.utils.TopRoundedCornersTransformation;
import ly.warp.sdk.utils.WarpUtils;
......@@ -36,7 +41,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
private ArrayList<Coupon> filteredCouponItems;
private final Context context;
private OnCouponClickListener listener;
private int currentFilter = 0;
/**
* Interface for handling coupon item clicks
......@@ -72,7 +76,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
* @param status The status to filter by (active, favorite, redeemed) or null for all
*/
public void filterByStatus(int status) {
currentFilter = status;
filteredCouponItems.clear();
if (status == 0) {
......@@ -115,6 +118,9 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
private final TextView tvTitle;
private final TextView tvDescription;
private final TextView tvEndDate;
private final LinearLayout llDate;
private final LinearLayout llDateExpired;
private final TextView tvExpiredLabel;
CouponViewHolder(@NonNull View itemView) {
super(itemView);
......@@ -123,30 +129,79 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
tvTitle = itemView.findViewById(R.id.tv_title);
tvDescription = itemView.findViewById(R.id.tv_description);
tvEndDate = itemView.findViewById(R.id.tv_coupon_end_date);
llDate = itemView.findViewById(R.id.ll_date);
llDateExpired = itemView.findViewById(R.id.ll_date_expired);
tvExpiredLabel = itemView.findViewById(R.id.tv_expired_label);
WarpUtils.renderCustomFont(context, R.font.ping_lcg_bold, tvTitle,
tvMerchant, tvEndDate);
tvMerchant, tvEndDate, tvExpiredLabel);
WarpUtils.renderCustomFont(context, R.font.ping_lcg_regular, tvDescription);
// Set click listeners
itemView.setOnClickListener(v -> {
int position = getAdapterPosition();
if (listener != null && position != RecyclerView.NO_POSITION) {
listener.onCouponClick(filteredCouponItems.get(position), position);
Coupon coupon = filteredCouponItems.get(position);
if (coupon.getStatus() == 1) {
listener.onCouponClick(coupon, position);
}
}
});
}
void bind(Coupon couponItem, int position) {
if (couponItem.getStatus() == -1) {
itemView.setBackgroundResource(R.drawable.shape_rounded_grey_grey_border);
tvMerchant.setTextColor(ContextCompat.getColor(context, R.color.custom_grey9));
tvTitle.setTextColor(ContextCompat.getColor(context, R.color.custom_grey9));
tvDescription.setTextColor(ContextCompat.getColor(context, R.color.custom_grey9));
llDate.setVisibility(View.GONE);
llDateExpired.setVisibility(View.VISIBLE);
} else {
itemView.setBackgroundResource(R.drawable.shape_rounded_skyblue_skyblue_border);
tvMerchant.setTextColor(ContextCompat.getColor(context, R.color.custom_grey3));
tvTitle.setTextColor(ContextCompat.getColor(context, R.color.custom_black6));
tvDescription.setTextColor(ContextCompat.getColor(context, R.color.custom_grey3));
llDate.setVisibility(View.VISIBLE);
llDateExpired.setVisibility(View.GONE);
}
tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getAdmin_name()) ? couponItem.getCouponsetDetails().getAdmin_name().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.getCouponsetDetails().getEndDate() != null && !couponItem.getCouponsetDetails().getEndDate().isEmpty()) {
String formattedDate = formatValidityDate(couponItem.getCouponsetDetails().getEndDate().trim());
tvEndDate.setText(context.getString(R.string.demo_valid_until, formattedDate));
if (couponItem.getExpiration() != null && !couponItem.getExpiration().isEmpty()) {
String rawDate = couponItem.getExpiration().trim();
Date parsedDate = parseDate(rawDate);
if (parsedDate != null) {
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
Calendar expiry = Calendar.getInstance();
expiry.setTime(parsedDate);
expiry.set(Calendar.HOUR_OF_DAY, 0);
expiry.set(Calendar.MINUTE, 0);
expiry.set(Calendar.SECOND, 0);
expiry.set(Calendar.MILLISECOND, 0);
long daysLeft = (expiry.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24);
if (daysLeft >= 0 && daysLeft <= 3) {
tvEndDate.setText(context.getString(R.string.demo_valid_days, daysLeft + " days"));
llDate.setBackgroundResource(R.drawable.demo_shape_yellow_border_yellow);
tvEndDate.setTextColor(ContextCompat.getColor(context, R.color.custom_gold));
} else {
tvEndDate.setText(context.getString(R.string.demo_valid_until, formatValidityDate(rawDate)));
llDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey);
tvEndDate.setTextColor(ContextCompat.getColor(context, R.color.custom_black7));
}
} else {
tvEndDate.setText(context.getString(R.string.demo_valid_until, formatValidityDate(rawDate)));
llDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey);
tvEndDate.setTextColor(ContextCompat.getColor(context, R.color.custom_black7));
}
}
loadMerchantLogo(couponItem.getMerchantDetails().getImgPreview());
loadMerchantLogo(couponItem.getMerchantDetails().getImgPreview(), couponItem.getStatus());
}
private String formatValidityDate(String endDate) {
......@@ -174,17 +229,40 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
}
}
private void loadMerchantLogo(String logoUrl) {
private Date parseDate(String endDate) {
String[] formats = {
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm",
"yyyy-MM-dd'T'HH:mm:ss"
};
for (String format : formats) {
try {
return new SimpleDateFormat(format, Locale.getDefault()).parse(endDate);
} catch (ParseException ignored) {
}
}
return null;
}
private void loadMerchantLogo(String logoUrl, int status) {
if (logoUrl != null && !logoUrl.isEmpty()) {
int radiusInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 10,
context.getResources().getDisplayMetrics());
if (status == -1) {
Glide.with(context)
.load(logoUrl)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true), new GrayscaleTransformation())
.into(ivLogo);
} else {
Glide.with(context)
.load(logoUrl)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true))
.into(ivLogo);
}
ivLogo.setVisibility(View.VISIBLE);
} else {
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="6dp" />
<solid android:color="@color/custom_yellow" />
<stroke
android:width="1dp"
android:color="@color/custom_yellow2" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="13dp" />
<solid android:color="@color/custom_grey5" />
<stroke
android:width="2dp"
android:color="@color/custom_grey7" />
</shape>
\ No newline at end of file
......@@ -107,6 +107,27 @@
android:textSize="12sp"
tools:text="@string/demo_purchases" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_date_expired"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/demo_shape_grey_border_grey"
android:gravity="center"
android:orientation="horizontal"
android:paddingHorizontal="8dp"
android:paddingVertical="6dp"
android:visibility="gone">
<TextView
android:id="@+id/tv_expired_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="@string/demo_coupon_expired"
android:textColor="@color/custom_black7"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
......
......@@ -37,4 +37,8 @@
<color name="custom_grey7">#D2D6D9</color>
<color name="custom_grey8">#8F8F8F</color>
<color name="custom_skyblue6">#A5DAF8</color>
<color name="custom_yellow">#FFF5DA</color>
<color name="custom_yellow2">#FFEABA</color>
<color name="custom_gold">#573300</color>
<color name="custom_grey9">#ADB3B8</color>
</resources>
......
......@@ -13,6 +13,7 @@
<string name="demo_less">View less</string>
<string name="demo_purchases">για αγορές</string>
<string name="demo_valid_until">Valid until %1$s</string>
<string name="demo_valid_days">%1$s left</string>
<string name="demo_coupon_code">Available code</string>
<string name="demo_qr_code">QR Κουπονιού</string>
<string name="demo_barcode_code">Barcode Κουπονιού</string>
......@@ -34,4 +35,5 @@
<string name="demo_family_title">family</string>
<string name="demo_my_coupons_title">My coupons</string>
<string name="demo_my_coupons_header">My Coupons</string>
<string name="demo_coupon_expired">Expired</string>
</resources>
......