|
|
@@ -0,0 +1,115 @@
|
|
|
+package com.miekir.ym.ui.coupon;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.bumptech.glide.request.target.SimpleTarget;
|
|
|
+import com.bumptech.glide.request.transition.Transition;
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.BaseViewHolder;
|
|
|
+import com.miekir.common.utils.ActivityTool;
|
|
|
+import com.miekir.common.utils.ToastTool;
|
|
|
+import com.miekir.ym.R;
|
|
|
+import com.miekir.ym.manager.UserInfoManager;
|
|
|
+import com.miekir.ym.listener.ItemLongClickListener;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Miekir
|
|
|
+ * @date 2020/7/6 20:08
|
|
|
+ * Description: 首页商品适配器
|
|
|
+ */
|
|
|
+public class CouponAdapter extends BaseQuickAdapter<CouponBean, BaseViewHolder> {
|
|
|
+ private int mRadius = 8;
|
|
|
+ private Context mContext;
|
|
|
+
|
|
|
+ public CouponAdapter(Context context, @Nullable List<CouponBean> data) {
|
|
|
+ super(R.layout.item_template, data);
|
|
|
+ mRadius = (int) context.getResources().getDimension(R.dimen.margin_s);
|
|
|
+ mContext = context;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void convert(@NonNull BaseViewHolder holder, CouponBean couponBean) {
|
|
|
+ ImageView iv_template = holder.getView(R.id.iv_template);
|
|
|
+ // 解决图片错乱
|
|
|
+ iv_template.setTag(R.id.iv_template, couponBean.coverUrl);
|
|
|
+ if (couponBean.isCoverUrlLocal) {
|
|
|
+ int resourceId = Integer.parseInt(couponBean.coverUrl);
|
|
|
+ iv_template.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
+ iv_template.setImageResource(resourceId);
|
|
|
+ } else {
|
|
|
+ // 圆角
|
|
|
+ Glide.with(mContext).load(couponBean.coverUrl)
|
|
|
+ //先加载原图大小的十分之一
|
|
|
+ .thumbnail(0.1f)
|
|
|
+ .into(new SimpleTarget<Drawable>() {
|
|
|
+ @Override
|
|
|
+ public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
|
|
+ if (resource == null) {
|
|
|
+ iv_template.setImageResource(R.mipmap.logo_gray);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String coverUrl = null;
|
|
|
+ try {
|
|
|
+ coverUrl = (String) iv_template.getTag(R.id.iv_template);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(coverUrl) || !TextUtils.equals(coverUrl, couponBean.coverUrl)) {
|
|
|
+ iv_template.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
|
+ iv_template.setImageResource(R.mipmap.logo_gray);
|
|
|
+ } else {
|
|
|
+ iv_template.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
+ iv_template.setImageDrawable(resource);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ holder.setText(R.id.tv_template, couponBean.couponName);
|
|
|
+ holder.setOnClickListener(R.id.rl_template, new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (!couponBean.actionEnable) {
|
|
|
+ ToastTool.showShort("敬请期待");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ActivityTool.openUrl((Activity) mContext, couponBean.jumpUrl);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ View view = holder.getView(R.id.rl_template);
|
|
|
+ view.setOnLongClickListener(v -> {
|
|
|
+ if (UserInfoManager.getInstance().isLogin() &&
|
|
|
+ TextUtils.equals("[email protected]", UserInfoManager.getInstance().getBeiUser().email)) {
|
|
|
+ if (couponLongClickListener != null) {
|
|
|
+ couponLongClickListener.onItemLongClick(holder.getLayoutPosition());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private ItemLongClickListener couponLongClickListener;
|
|
|
+ public ItemLongClickListener getCouponLongClickListener() {
|
|
|
+ return couponLongClickListener;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCouponLongClickListener(ItemLongClickListener couponListener) {
|
|
|
+ this.couponLongClickListener = couponListener;
|
|
|
+ }
|
|
|
+}
|