Showing
8 changed files
with
232 additions
and
13 deletions
| ... | @@ -13,6 +13,7 @@ import android.widget.LinearLayout; | ... | @@ -13,6 +13,7 @@ import android.widget.LinearLayout; |
| 13 | import android.widget.TextView; | 13 | import android.widget.TextView; |
| 14 | import android.widget.Toast; | 14 | import android.widget.Toast; |
| 15 | 15 | ||
| 16 | +import androidx.core.content.ContextCompat; | ||
| 16 | import androidx.core.text.HtmlCompat; | 17 | import androidx.core.text.HtmlCompat; |
| 17 | 18 | ||
| 18 | import com.bumptech.glide.Glide; | 19 | import com.bumptech.glide.Glide; |
| ... | @@ -20,6 +21,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; | ... | @@ -20,6 +21,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; |
| 20 | 21 | ||
| 21 | import java.text.ParseException; | 22 | import java.text.ParseException; |
| 22 | import java.text.SimpleDateFormat; | 23 | import java.text.SimpleDateFormat; |
| 24 | +import java.util.Calendar; | ||
| 23 | import java.util.Date; | 25 | import java.util.Date; |
| 24 | import java.util.Locale; | 26 | import java.util.Locale; |
| 25 | 27 | ||
| ... | @@ -42,6 +44,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen | ... | @@ -42,6 +44,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen |
| 42 | private TextView mTvSmallDescription; | 44 | private TextView mTvSmallDescription; |
| 43 | private TextView mTvFullDescription; | 45 | private TextView mTvFullDescription; |
| 44 | private TextView mTvEndDate; | 46 | private TextView mTvEndDate; |
| 47 | + private LinearLayout mLlDate; | ||
| 45 | private TextView mTvValue; | 48 | private TextView mTvValue; |
| 46 | private TextView mTvMoreButton; | 49 | private TextView mTvMoreButton; |
| 47 | private ImageView mIvImage; | 50 | private ImageView mIvImage; |
| ... | @@ -105,6 +108,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen | ... | @@ -105,6 +108,7 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen |
| 105 | mTvSmallDescription = findViewById(R.id.tv_coupon_small_description); | 108 | mTvSmallDescription = findViewById(R.id.tv_coupon_small_description); |
| 106 | mTvFullDescription = findViewById(R.id.tv_coupon_full_description); | 109 | mTvFullDescription = findViewById(R.id.tv_coupon_full_description); |
| 107 | mTvEndDate = findViewById(R.id.tv_coupon_end_date); | 110 | mTvEndDate = findViewById(R.id.tv_coupon_end_date); |
| 111 | + mLlDate = findViewById(R.id.ll_date); | ||
| 108 | mTvValue = findViewById(R.id.tv_coupon_value); | 112 | mTvValue = findViewById(R.id.tv_coupon_value); |
| 109 | mIvImage = findViewById(R.id.iv_coupon_image); | 113 | mIvImage = findViewById(R.id.iv_coupon_image); |
| 110 | mTvMoreButton = findViewById(R.id.tv_more_button); | 114 | mTvMoreButton = findViewById(R.id.tv_more_button); |
| ... | @@ -139,8 +143,35 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen | ... | @@ -139,8 +143,35 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen |
| 139 | 143 | ||
| 140 | if (mOfferItem != null) { | 144 | if (mOfferItem != null) { |
| 141 | if (mOfferItem.getExpiration() != null && !mOfferItem.getExpiration().isEmpty()) { | 145 | if (mOfferItem.getExpiration() != null && !mOfferItem.getExpiration().isEmpty()) { |
| 142 | - String formattedDate = formatValidityDate(mOfferItem.getExpiration()); | 146 | + String rawDate = mOfferItem.getExpiration().trim(); |
| 143 | - mTvEndDate.setText(getString(R.string.demo_valid_until, formattedDate)); | 147 | + Date parsedDate = parseDate(rawDate); |
| 148 | + if (parsedDate != null) { | ||
| 149 | + Calendar now = Calendar.getInstance(); | ||
| 150 | + now.set(Calendar.HOUR_OF_DAY, 0); | ||
| 151 | + now.set(Calendar.MINUTE, 0); | ||
| 152 | + now.set(Calendar.SECOND, 0); | ||
| 153 | + now.set(Calendar.MILLISECOND, 0); | ||
| 154 | + Calendar expiry = Calendar.getInstance(); | ||
| 155 | + expiry.setTime(parsedDate); | ||
| 156 | + expiry.set(Calendar.HOUR_OF_DAY, 0); | ||
| 157 | + expiry.set(Calendar.MINUTE, 0); | ||
| 158 | + expiry.set(Calendar.SECOND, 0); | ||
| 159 | + expiry.set(Calendar.MILLISECOND, 0); | ||
| 160 | + long daysLeft = (expiry.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24); | ||
| 161 | + if (daysLeft >= 0 && daysLeft <= 3) { | ||
| 162 | + mTvEndDate.setText(getString(R.string.demo_valid_days, daysLeft + " days")); | ||
| 163 | + mLlDate.setBackgroundResource(R.drawable.demo_shape_yellow_border_yellow); | ||
| 164 | + mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_gold)); | ||
| 165 | + } else { | ||
| 166 | + mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate))); | ||
| 167 | + mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey); | ||
| 168 | + mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7)); | ||
| 169 | + } | ||
| 170 | + } else { | ||
| 171 | + mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate))); | ||
| 172 | + mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey); | ||
| 173 | + mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7)); | ||
| 174 | + } | ||
| 144 | } | 175 | } |
| 145 | 176 | ||
| 146 | if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getImg_preview() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getImg_preview())) { | 177 | 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 | ... | @@ -194,6 +225,21 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen |
| 194 | } | 225 | } |
| 195 | } | 226 | } |
| 196 | 227 | ||
| 228 | + private Date parseDate(String endDate) { | ||
| 229 | + String[] formats = { | ||
| 230 | + "yyyy-MM-dd HH:mm:ss", | ||
| 231 | + "yyyy-MM-dd HH:mm", | ||
| 232 | + "yyyy-MM-dd'T'HH:mm:ss" | ||
| 233 | + }; | ||
| 234 | + for (String format : formats) { | ||
| 235 | + try { | ||
| 236 | + return new SimpleDateFormat(format, Locale.getDefault()).parse(endDate); | ||
| 237 | + } catch (ParseException ignored) { | ||
| 238 | + } | ||
| 239 | + } | ||
| 240 | + return null; | ||
| 241 | + } | ||
| 242 | + | ||
| 197 | private void setupCouponCodeSection() { | 243 | private void setupCouponCodeSection() { |
| 198 | mTvCouponCode.setText(mOfferItem.getCoupon()); | 244 | mTvCouponCode.setText(mOfferItem.getCoupon()); |
| 199 | 245 | ... | ... |
| ... | @@ -13,6 +13,7 @@ import android.widget.RelativeLayout; | ... | @@ -13,6 +13,7 @@ import android.widget.RelativeLayout; |
| 13 | import android.widget.TextView; | 13 | import android.widget.TextView; |
| 14 | import android.widget.Toast; | 14 | import android.widget.Toast; |
| 15 | 15 | ||
| 16 | +import androidx.core.content.ContextCompat; | ||
| 16 | import androidx.core.text.HtmlCompat; | 17 | import androidx.core.text.HtmlCompat; |
| 17 | 18 | ||
| 18 | import com.bumptech.glide.Glide; | 19 | import com.bumptech.glide.Glide; |
| ... | @@ -22,6 +23,7 @@ import org.json.JSONObject; | ... | @@ -22,6 +23,7 @@ import org.json.JSONObject; |
| 22 | 23 | ||
| 23 | import java.text.ParseException; | 24 | import java.text.ParseException; |
| 24 | import java.text.SimpleDateFormat; | 25 | import java.text.SimpleDateFormat; |
| 26 | +import java.util.Calendar; | ||
| 25 | import java.util.Date; | 27 | import java.util.Date; |
| 26 | import java.util.Locale; | 28 | import java.util.Locale; |
| 27 | 29 | ||
| ... | @@ -47,6 +49,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -47,6 +49,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 47 | private TextView mTvSmallDescription; | 49 | private TextView mTvSmallDescription; |
| 48 | private TextView mTvFullDescription; | 50 | private TextView mTvFullDescription; |
| 49 | private TextView mTvEndDate; | 51 | private TextView mTvEndDate; |
| 52 | + private LinearLayout mLlDate; | ||
| 50 | private TextView mTvValue; | 53 | private TextView mTvValue; |
| 51 | private TextView mTvMoreButton; | 54 | private TextView mTvMoreButton; |
| 52 | private ImageView mIvImage; | 55 | private ImageView mIvImage; |
| ... | @@ -124,6 +127,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -124,6 +127,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 124 | mTvSmallDescription = findViewById(R.id.tv_coupon_small_description); | 127 | mTvSmallDescription = findViewById(R.id.tv_coupon_small_description); |
| 125 | mTvFullDescription = findViewById(R.id.tv_coupon_full_description); | 128 | mTvFullDescription = findViewById(R.id.tv_coupon_full_description); |
| 126 | mTvEndDate = findViewById(R.id.tv_coupon_end_date); | 129 | mTvEndDate = findViewById(R.id.tv_coupon_end_date); |
| 130 | + mLlDate = findViewById(R.id.ll_date); | ||
| 127 | mTvValue = findViewById(R.id.tv_coupon_value); | 131 | mTvValue = findViewById(R.id.tv_coupon_value); |
| 128 | mIvImage = findViewById(R.id.iv_coupon_image); | 132 | mIvImage = findViewById(R.id.iv_coupon_image); |
| 129 | mTvMoreButton = findViewById(R.id.tv_more_button); | 133 | mTvMoreButton = findViewById(R.id.tv_more_button); |
| ... | @@ -152,8 +156,35 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -152,8 +156,35 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 152 | 156 | ||
| 153 | if (mOfferItem != null) { | 157 | if (mOfferItem != null) { |
| 154 | if (mOfferItem.getEndDate() != null && !mOfferItem.getEndDate().isEmpty()) { | 158 | if (mOfferItem.getEndDate() != null && !mOfferItem.getEndDate().isEmpty()) { |
| 155 | - String formattedDate = formatValidityDate(mOfferItem.getEndDate()); | 159 | + String rawDate = mOfferItem.getEndDate().trim(); |
| 156 | - mTvEndDate.setText(getString(R.string.demo_valid_until, formattedDate)); | 160 | + Date parsedDate = parseDate(rawDate); |
| 161 | + if (parsedDate != null) { | ||
| 162 | + Calendar now = Calendar.getInstance(); | ||
| 163 | + now.set(Calendar.HOUR_OF_DAY, 0); | ||
| 164 | + now.set(Calendar.MINUTE, 0); | ||
| 165 | + now.set(Calendar.SECOND, 0); | ||
| 166 | + now.set(Calendar.MILLISECOND, 0); | ||
| 167 | + Calendar expiry = Calendar.getInstance(); | ||
| 168 | + expiry.setTime(parsedDate); | ||
| 169 | + expiry.set(Calendar.HOUR_OF_DAY, 0); | ||
| 170 | + expiry.set(Calendar.MINUTE, 0); | ||
| 171 | + expiry.set(Calendar.SECOND, 0); | ||
| 172 | + expiry.set(Calendar.MILLISECOND, 0); | ||
| 173 | + long daysLeft = (expiry.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24); | ||
| 174 | + if (daysLeft >= 0 && daysLeft <= 3) { | ||
| 175 | + mTvEndDate.setText(getString(R.string.demo_valid_days, daysLeft + " days")); | ||
| 176 | + mLlDate.setBackgroundResource(R.drawable.demo_shape_yellow_border_yellow); | ||
| 177 | + mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_gold)); | ||
| 178 | + } else { | ||
| 179 | + mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate))); | ||
| 180 | + mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey); | ||
| 181 | + mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7)); | ||
| 182 | + } | ||
| 183 | + } else { | ||
| 184 | + mTvEndDate.setText(getString(R.string.demo_valid_until, formatValidityDate(rawDate))); | ||
| 185 | + mLlDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey); | ||
| 186 | + mTvEndDate.setTextColor(ContextCompat.getColor(this, R.color.custom_black7)); | ||
| 187 | + } | ||
| 157 | } | 188 | } |
| 158 | 189 | ||
| 159 | if (!TextUtils.isEmpty(mOfferItem.getImg_preview())) { | 190 | if (!TextUtils.isEmpty(mOfferItem.getImg_preview())) { |
| ... | @@ -199,6 +230,21 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -199,6 +230,21 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 199 | } | 230 | } |
| 200 | } | 231 | } |
| 201 | 232 | ||
| 233 | + private Date parseDate(String endDate) { | ||
| 234 | + String[] formats = { | ||
| 235 | + "yyyy-MM-dd HH:mm:ss", | ||
| 236 | + "yyyy-MM-dd HH:mm", | ||
| 237 | + "yyyy-MM-dd'T'HH:mm:ss" | ||
| 238 | + }; | ||
| 239 | + for (String format : formats) { | ||
| 240 | + try { | ||
| 241 | + return new SimpleDateFormat(format, Locale.getDefault()).parse(endDate); | ||
| 242 | + } catch (ParseException ignored) { | ||
| 243 | + } | ||
| 244 | + } | ||
| 245 | + return null; | ||
| 246 | + } | ||
| 247 | + | ||
| 202 | private void setupMoreButton() { | 248 | private void setupMoreButton() { |
| 203 | // Wait for layout to be ready to check if text is truncated | 249 | // Wait for layout to be ready to check if text is truncated |
| 204 | mTvFullDescription.post(new Runnable() { | 250 | mTvFullDescription.post(new Runnable() { | ... | ... |
| ... | @@ -7,8 +7,11 @@ import android.view.LayoutInflater; | ... | @@ -7,8 +7,11 @@ import android.view.LayoutInflater; |
| 7 | import android.view.View; | 7 | import android.view.View; |
| 8 | import android.view.ViewGroup; | 8 | import android.view.ViewGroup; |
| 9 | import android.widget.ImageView; | 9 | import android.widget.ImageView; |
| 10 | +import android.widget.LinearLayout; | ||
| 10 | import android.widget.TextView; | 11 | import android.widget.TextView; |
| 11 | 12 | ||
| 13 | +import androidx.core.content.ContextCompat; | ||
| 14 | + | ||
| 12 | import androidx.annotation.NonNull; | 15 | import androidx.annotation.NonNull; |
| 13 | import androidx.recyclerview.widget.RecyclerView; | 16 | import androidx.recyclerview.widget.RecyclerView; |
| 14 | 17 | ||
| ... | @@ -19,11 +22,13 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop; | ... | @@ -19,11 +22,13 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop; |
| 19 | import java.text.ParseException; | 22 | import java.text.ParseException; |
| 20 | import java.text.SimpleDateFormat; | 23 | import java.text.SimpleDateFormat; |
| 21 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
| 25 | +import java.util.Calendar; | ||
| 22 | import java.util.Date; | 26 | import java.util.Date; |
| 23 | import java.util.Locale; | 27 | import java.util.Locale; |
| 24 | 28 | ||
| 25 | import ly.warp.sdk.R; | 29 | import ly.warp.sdk.R; |
| 26 | import ly.warp.sdk.io.models.Coupon; | 30 | import ly.warp.sdk.io.models.Coupon; |
| 31 | +import ly.warp.sdk.utils.GrayscaleTransformation; | ||
| 27 | import ly.warp.sdk.utils.TopRoundedCornersTransformation; | 32 | import ly.warp.sdk.utils.TopRoundedCornersTransformation; |
| 28 | import ly.warp.sdk.utils.WarpUtils; | 33 | import ly.warp.sdk.utils.WarpUtils; |
| 29 | 34 | ||
| ... | @@ -36,7 +41,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView | ... | @@ -36,7 +41,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView |
| 36 | private ArrayList<Coupon> filteredCouponItems; | 41 | private ArrayList<Coupon> filteredCouponItems; |
| 37 | private final Context context; | 42 | private final Context context; |
| 38 | private OnCouponClickListener listener; | 43 | private OnCouponClickListener listener; |
| 39 | - private int currentFilter = 0; | ||
| 40 | 44 | ||
| 41 | /** | 45 | /** |
| 42 | * Interface for handling coupon item clicks | 46 | * Interface for handling coupon item clicks |
| ... | @@ -72,7 +76,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView | ... | @@ -72,7 +76,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView |
| 72 | * @param status The status to filter by (active, favorite, redeemed) or null for all | 76 | * @param status The status to filter by (active, favorite, redeemed) or null for all |
| 73 | */ | 77 | */ |
| 74 | public void filterByStatus(int status) { | 78 | public void filterByStatus(int status) { |
| 75 | - currentFilter = status; | ||
| 76 | filteredCouponItems.clear(); | 79 | filteredCouponItems.clear(); |
| 77 | 80 | ||
| 78 | if (status == 0) { | 81 | if (status == 0) { |
| ... | @@ -115,6 +118,9 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView | ... | @@ -115,6 +118,9 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView |
| 115 | private final TextView tvTitle; | 118 | private final TextView tvTitle; |
| 116 | private final TextView tvDescription; | 119 | private final TextView tvDescription; |
| 117 | private final TextView tvEndDate; | 120 | private final TextView tvEndDate; |
| 121 | + private final LinearLayout llDate; | ||
| 122 | + private final LinearLayout llDateExpired; | ||
| 123 | + private final TextView tvExpiredLabel; | ||
| 118 | 124 | ||
| 119 | CouponViewHolder(@NonNull View itemView) { | 125 | CouponViewHolder(@NonNull View itemView) { |
| 120 | super(itemView); | 126 | super(itemView); |
| ... | @@ -123,30 +129,79 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView | ... | @@ -123,30 +129,79 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView |
| 123 | tvTitle = itemView.findViewById(R.id.tv_title); | 129 | tvTitle = itemView.findViewById(R.id.tv_title); |
| 124 | tvDescription = itemView.findViewById(R.id.tv_description); | 130 | tvDescription = itemView.findViewById(R.id.tv_description); |
| 125 | tvEndDate = itemView.findViewById(R.id.tv_coupon_end_date); | 131 | tvEndDate = itemView.findViewById(R.id.tv_coupon_end_date); |
| 132 | + llDate = itemView.findViewById(R.id.ll_date); | ||
| 133 | + llDateExpired = itemView.findViewById(R.id.ll_date_expired); | ||
| 134 | + tvExpiredLabel = itemView.findViewById(R.id.tv_expired_label); | ||
| 126 | 135 | ||
| 127 | WarpUtils.renderCustomFont(context, R.font.ping_lcg_bold, tvTitle, | 136 | WarpUtils.renderCustomFont(context, R.font.ping_lcg_bold, tvTitle, |
| 128 | - tvMerchant, tvEndDate); | 137 | + tvMerchant, tvEndDate, tvExpiredLabel); |
| 129 | WarpUtils.renderCustomFont(context, R.font.ping_lcg_regular, tvDescription); | 138 | WarpUtils.renderCustomFont(context, R.font.ping_lcg_regular, tvDescription); |
| 130 | 139 | ||
| 131 | // Set click listeners | 140 | // Set click listeners |
| 132 | itemView.setOnClickListener(v -> { | 141 | itemView.setOnClickListener(v -> { |
| 133 | int position = getAdapterPosition(); | 142 | int position = getAdapterPosition(); |
| 134 | if (listener != null && position != RecyclerView.NO_POSITION) { | 143 | if (listener != null && position != RecyclerView.NO_POSITION) { |
| 135 | - listener.onCouponClick(filteredCouponItems.get(position), position); | 144 | + Coupon coupon = filteredCouponItems.get(position); |
| 145 | + if (coupon.getStatus() == 1) { | ||
| 146 | + listener.onCouponClick(coupon, position); | ||
| 147 | + } | ||
| 136 | } | 148 | } |
| 137 | }); | 149 | }); |
| 138 | } | 150 | } |
| 139 | 151 | ||
| 140 | void bind(Coupon couponItem, int position) { | 152 | void bind(Coupon couponItem, int position) { |
| 153 | + if (couponItem.getStatus() == -1) { | ||
| 154 | + itemView.setBackgroundResource(R.drawable.shape_rounded_grey_grey_border); | ||
| 155 | + tvMerchant.setTextColor(ContextCompat.getColor(context, R.color.custom_grey9)); | ||
| 156 | + tvTitle.setTextColor(ContextCompat.getColor(context, R.color.custom_grey9)); | ||
| 157 | + tvDescription.setTextColor(ContextCompat.getColor(context, R.color.custom_grey9)); | ||
| 158 | + llDate.setVisibility(View.GONE); | ||
| 159 | + llDateExpired.setVisibility(View.VISIBLE); | ||
| 160 | + } else { | ||
| 161 | + itemView.setBackgroundResource(R.drawable.shape_rounded_skyblue_skyblue_border); | ||
| 162 | + tvMerchant.setTextColor(ContextCompat.getColor(context, R.color.custom_grey3)); | ||
| 163 | + tvTitle.setTextColor(ContextCompat.getColor(context, R.color.custom_black6)); | ||
| 164 | + tvDescription.setTextColor(ContextCompat.getColor(context, R.color.custom_grey3)); | ||
| 165 | + llDate.setVisibility(View.VISIBLE); | ||
| 166 | + llDateExpired.setVisibility(View.GONE); | ||
| 167 | + } | ||
| 168 | + | ||
| 141 | tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getAdmin_name()) ? couponItem.getCouponsetDetails().getAdmin_name().trim() : ""); | 169 | tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getAdmin_name()) ? couponItem.getCouponsetDetails().getAdmin_name().trim() : ""); |
| 142 | tvTitle.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getName()) ? couponItem.getCouponsetDetails().getName().trim() : ""); | 170 | tvTitle.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getName()) ? couponItem.getCouponsetDetails().getName().trim() : ""); |
| 143 | tvDescription.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getShort_description()) ? couponItem.getCouponsetDetails().getShort_description().trim() : ""); | 171 | tvDescription.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getShort_description()) ? couponItem.getCouponsetDetails().getShort_description().trim() : ""); |
| 144 | - if (couponItem.getCouponsetDetails().getEndDate() != null && !couponItem.getCouponsetDetails().getEndDate().isEmpty()) { | 172 | + if (couponItem.getExpiration() != null && !couponItem.getExpiration().isEmpty()) { |
| 145 | - String formattedDate = formatValidityDate(couponItem.getCouponsetDetails().getEndDate().trim()); | 173 | + String rawDate = couponItem.getExpiration().trim(); |
| 146 | - tvEndDate.setText(context.getString(R.string.demo_valid_until, formattedDate)); | 174 | + Date parsedDate = parseDate(rawDate); |
| 175 | + if (parsedDate != null) { | ||
| 176 | + Calendar now = Calendar.getInstance(); | ||
| 177 | + now.set(Calendar.HOUR_OF_DAY, 0); | ||
| 178 | + now.set(Calendar.MINUTE, 0); | ||
| 179 | + now.set(Calendar.SECOND, 0); | ||
| 180 | + now.set(Calendar.MILLISECOND, 0); | ||
| 181 | + Calendar expiry = Calendar.getInstance(); | ||
| 182 | + expiry.setTime(parsedDate); | ||
| 183 | + expiry.set(Calendar.HOUR_OF_DAY, 0); | ||
| 184 | + expiry.set(Calendar.MINUTE, 0); | ||
| 185 | + expiry.set(Calendar.SECOND, 0); | ||
| 186 | + expiry.set(Calendar.MILLISECOND, 0); | ||
| 187 | + long daysLeft = (expiry.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24); | ||
| 188 | + if (daysLeft >= 0 && daysLeft <= 3) { | ||
| 189 | + tvEndDate.setText(context.getString(R.string.demo_valid_days, daysLeft + " days")); | ||
| 190 | + llDate.setBackgroundResource(R.drawable.demo_shape_yellow_border_yellow); | ||
| 191 | + tvEndDate.setTextColor(ContextCompat.getColor(context, R.color.custom_gold)); | ||
| 192 | + } else { | ||
| 193 | + tvEndDate.setText(context.getString(R.string.demo_valid_until, formatValidityDate(rawDate))); | ||
| 194 | + llDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey); | ||
| 195 | + tvEndDate.setTextColor(ContextCompat.getColor(context, R.color.custom_black7)); | ||
| 196 | + } | ||
| 197 | + } else { | ||
| 198 | + tvEndDate.setText(context.getString(R.string.demo_valid_until, formatValidityDate(rawDate))); | ||
| 199 | + llDate.setBackgroundResource(R.drawable.demo_shape_grey_border_grey); | ||
| 200 | + tvEndDate.setTextColor(ContextCompat.getColor(context, R.color.custom_black7)); | ||
| 201 | + } | ||
| 147 | } | 202 | } |
| 148 | 203 | ||
| 149 | - loadMerchantLogo(couponItem.getMerchantDetails().getImgPreview()); | 204 | + loadMerchantLogo(couponItem.getMerchantDetails().getImgPreview(), couponItem.getStatus()); |
| 150 | } | 205 | } |
| 151 | 206 | ||
| 152 | private String formatValidityDate(String endDate) { | 207 | private String formatValidityDate(String endDate) { |
| ... | @@ -174,17 +229,40 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView | ... | @@ -174,17 +229,40 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView |
| 174 | } | 229 | } |
| 175 | } | 230 | } |
| 176 | 231 | ||
| 177 | - private void loadMerchantLogo(String logoUrl) { | 232 | + private Date parseDate(String endDate) { |
| 233 | + String[] formats = { | ||
| 234 | + "yyyy-MM-dd HH:mm:ss", | ||
| 235 | + "yyyy-MM-dd HH:mm", | ||
| 236 | + "yyyy-MM-dd'T'HH:mm:ss" | ||
| 237 | + }; | ||
| 238 | + for (String format : formats) { | ||
| 239 | + try { | ||
| 240 | + return new SimpleDateFormat(format, Locale.getDefault()).parse(endDate); | ||
| 241 | + } catch (ParseException ignored) { | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + return null; | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + private void loadMerchantLogo(String logoUrl, int status) { | ||
| 178 | if (logoUrl != null && !logoUrl.isEmpty()) { | 248 | if (logoUrl != null && !logoUrl.isEmpty()) { |
| 179 | int radiusInPixels = (int) TypedValue.applyDimension( | 249 | int radiusInPixels = (int) TypedValue.applyDimension( |
| 180 | TypedValue.COMPLEX_UNIT_DIP, 10, | 250 | TypedValue.COMPLEX_UNIT_DIP, 10, |
| 181 | context.getResources().getDisplayMetrics()); | 251 | context.getResources().getDisplayMetrics()); |
| 182 | 252 | ||
| 253 | + if (status == -1) { | ||
| 254 | + Glide.with(context) | ||
| 255 | + .load(logoUrl) | ||
| 256 | + .diskCacheStrategy(DiskCacheStrategy.DATA) | ||
| 257 | + .transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true), new GrayscaleTransformation()) | ||
| 258 | + .into(ivLogo); | ||
| 259 | + } else { | ||
| 183 | Glide.with(context) | 260 | Glide.with(context) |
| 184 | .load(logoUrl) | 261 | .load(logoUrl) |
| 185 | .diskCacheStrategy(DiskCacheStrategy.DATA) | 262 | .diskCacheStrategy(DiskCacheStrategy.DATA) |
| 186 | .transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true)) | 263 | .transform(new CenterCrop(), new TopRoundedCornersTransformation(radiusInPixels, true)) |
| 187 | .into(ivLogo); | 264 | .into(ivLogo); |
| 265 | + } | ||
| 188 | 266 | ||
| 189 | ivLogo.setVisibility(View.VISIBLE); | 267 | ivLogo.setVisibility(View.VISIBLE); |
| 190 | } else { | 268 | } else { | ... | ... |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:shape="rectangle"> | ||
| 4 | + <corners android:radius="6dp" /> | ||
| 5 | + | ||
| 6 | + <solid android:color="@color/custom_yellow" /> | ||
| 7 | + | ||
| 8 | + <stroke | ||
| 9 | + android:width="1dp" | ||
| 10 | + android:color="@color/custom_yellow2" /> | ||
| 11 | +</shape> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:shape="rectangle"> | ||
| 4 | + <corners android:radius="13dp" /> | ||
| 5 | + | ||
| 6 | + <solid android:color="@color/custom_grey5" /> | ||
| 7 | + | ||
| 8 | + <stroke | ||
| 9 | + android:width="2dp" | ||
| 10 | + android:color="@color/custom_grey7" /> | ||
| 11 | +</shape> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -107,6 +107,27 @@ | ... | @@ -107,6 +107,27 @@ |
| 107 | android:textSize="12sp" | 107 | android:textSize="12sp" |
| 108 | tools:text="@string/demo_purchases" /> | 108 | tools:text="@string/demo_purchases" /> |
| 109 | </LinearLayout> | 109 | </LinearLayout> |
| 110 | + | ||
| 111 | + <LinearLayout | ||
| 112 | + android:id="@+id/ll_date_expired" | ||
| 113 | + android:layout_width="wrap_content" | ||
| 114 | + android:layout_height="wrap_content" | ||
| 115 | + android:background="@drawable/demo_shape_grey_border_grey" | ||
| 116 | + android:gravity="center" | ||
| 117 | + android:orientation="horizontal" | ||
| 118 | + android:paddingHorizontal="8dp" | ||
| 119 | + android:paddingVertical="6dp" | ||
| 120 | + android:visibility="gone"> | ||
| 121 | + | ||
| 122 | + <TextView | ||
| 123 | + android:id="@+id/tv_expired_label" | ||
| 124 | + android:layout_width="wrap_content" | ||
| 125 | + android:layout_height="wrap_content" | ||
| 126 | + android:includeFontPadding="false" | ||
| 127 | + android:text="@string/demo_coupon_expired" | ||
| 128 | + android:textColor="@color/custom_black7" | ||
| 129 | + android:textSize="12sp" /> | ||
| 130 | + </LinearLayout> | ||
| 110 | </LinearLayout> | 131 | </LinearLayout> |
| 111 | 132 | ||
| 112 | <LinearLayout | 133 | <LinearLayout | ... | ... |
| ... | @@ -37,4 +37,8 @@ | ... | @@ -37,4 +37,8 @@ |
| 37 | <color name="custom_grey7">#D2D6D9</color> | 37 | <color name="custom_grey7">#D2D6D9</color> |
| 38 | <color name="custom_grey8">#8F8F8F</color> | 38 | <color name="custom_grey8">#8F8F8F</color> |
| 39 | <color name="custom_skyblue6">#A5DAF8</color> | 39 | <color name="custom_skyblue6">#A5DAF8</color> |
| 40 | + <color name="custom_yellow">#FFF5DA</color> | ||
| 41 | + <color name="custom_yellow2">#FFEABA</color> | ||
| 42 | + <color name="custom_gold">#573300</color> | ||
| 43 | + <color name="custom_grey9">#ADB3B8</color> | ||
| 40 | </resources> | 44 | </resources> | ... | ... |
| ... | @@ -13,6 +13,7 @@ | ... | @@ -13,6 +13,7 @@ |
| 13 | <string name="demo_less">View less</string> | 13 | <string name="demo_less">View less</string> |
| 14 | <string name="demo_purchases">για αγορές</string> | 14 | <string name="demo_purchases">για αγορές</string> |
| 15 | <string name="demo_valid_until">Valid until %1$s</string> | 15 | <string name="demo_valid_until">Valid until %1$s</string> |
| 16 | + <string name="demo_valid_days">%1$s left</string> | ||
| 16 | <string name="demo_coupon_code">Available code</string> | 17 | <string name="demo_coupon_code">Available code</string> |
| 17 | <string name="demo_qr_code">QR Κουπονιού</string> | 18 | <string name="demo_qr_code">QR Κουπονιού</string> |
| 18 | <string name="demo_barcode_code">Barcode Κουπονιού</string> | 19 | <string name="demo_barcode_code">Barcode Κουπονιού</string> |
| ... | @@ -34,4 +35,5 @@ | ... | @@ -34,4 +35,5 @@ |
| 34 | <string name="demo_family_title">family</string> | 35 | <string name="demo_family_title">family</string> |
| 35 | <string name="demo_my_coupons_title">My coupons</string> | 36 | <string name="demo_my_coupons_title">My coupons</string> |
| 36 | <string name="demo_my_coupons_header">My Coupons</string> | 37 | <string name="demo_my_coupons_header">My Coupons</string> |
| 38 | + <string name="demo_coupon_expired">Expired</string> | ||
| 37 | </resources> | 39 | </resources> | ... | ... |
-
Please register or login to post a comment