| | |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | |
| | | import androidx.recyclerview.widget.GridLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.load.engine.DiskCacheStrategy; |
| | | import com.bumptech.glide.request.RequestOptions; |
| | | import com.nostra13.universalimageloader.core.DisplayImageOptions; |
| | | import com.nostra13.universalimageloader.core.assist.ImageScaleType; |
| | | import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer; |
| | | import com.wpc.library.util.common.DimenUtils; |
| | | import com.tejia.lijin.app.R; |
| | | import com.tejia.lijin.app.entity.TaoBaoGoodsBrief; |
| | | import com.tejia.lijin.app.util.GlideRoundTransform; |
| | | import com.tejia.lijin.app.util.goods.GoodsDetailJumpUtil; |
| | | import com.tejia.lijin.app.util.goods.GoodsDetailListUtil; |
| | | import com.tejia.lijin.app.util.ui.GoodsRightViewHolder; |
| | | import com.tejia.lijin.app.util.ui.HomeUIUtil; |
| | | |
| | | import java.util.List; |
| | | |
| | | import androidx.recyclerview.widget.GridLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade; |
| | | |
| | |
| | | private RecyclerView mRecyclerView; |
| | | |
| | | private List<TaoBaoGoodsBrief> mList; |
| | | private RecommendFragment mFragment; |
| | | private Context mContext; |
| | | |
| | | private View VIEW_FOOTER; |
| | |
| | | private int TYPE_HEADER = 1001; |
| | | public int TYPE_FOOTER = 1002; |
| | | |
| | | private DisplayImageOptions options; |
| | | private String mFrom; |
| | | int goodsType = 1; |
| | | |
| | | public RecommendGoodsAdapter(RecommendFragment fragment, List<TaoBaoGoodsBrief> list, String from) { |
| | | public RecommendGoodsAdapter(Context context, List<TaoBaoGoodsBrief> list, String from) { |
| | | this.mList = list; |
| | | this.mFragment = fragment; |
| | | this.mContext = fragment.getContext(); |
| | | this.mContext = context; |
| | | this.mFrom = from; |
| | | this.options = new DisplayImageOptions.Builder() |
| | | .showImageForEmptyUri(R.drawable.ic_goods_default) |
| | | .showImageOnFail(R.drawable.ic_goods_default) |
| | | .showImageOnLoading(R.drawable.ic_goods_default) |
| | | .resetViewBeforeLoading(true).cacheInMemory(true) |
| | | .cacheOnDisk(true).imageScaleType(ImageScaleType.EXACTLY) |
| | | .considerExifParams(true) |
| | | .displayer(new RoundedBitmapDisplayer(DimenUtils |
| | | .dip2px(mContext, 5))).build(); |
| | | } |
| | | |
| | | |
| | |
| | | } else if (viewType == TYPE_HEADER) { |
| | | return new ViewHolder(VIEW_HEADER); |
| | | } else { |
| | | View view = LayoutInflater.from(mContext).inflate(R.layout.item_category, parent, false); |
| | | View view = LayoutInflater.from(mContext).inflate(R.layout.item_goods, parent, false); |
| | | ViewHolder holder = new ViewHolder(view); |
| | | return holder; |
| | | } |
| | |
| | | public void onBindViewHolder(RecyclerView.ViewHolder holder1, int position) { |
| | | if (!isHeaderView(position) && !isFooterView(position)) { |
| | | final TaoBaoGoodsBrief info; |
| | | boolean showShadow = false; |
| | | if (haveHeaderView()) { |
| | | info = mList.get(position - 1); |
| | | if (position == 1) { |
| | | showShadow = true; |
| | | } |
| | | } else { |
| | | info = mList.get(position); |
| | | if (position == 0) { |
| | | showShadow = true; |
| | | } |
| | | } |
| | | |
| | | |
| | | ViewHolder viewHolder = (ViewHolder) holder1; |
| | | |
| | | if ("jingxuan".equalsIgnoreCase(mFrom)) { |
| | | ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) viewHolder.ll_item1.getLayoutParams(); |
| | | params.leftMargin = DimenUtils.dipToPixels(10, mContext); |
| | | params.rightMargin = DimenUtils.dipToPixels(10, mContext); |
| | | viewHolder.ll_item1.setLayoutParams(params); |
| | | } |
| | | |
| | | viewHolder.ll_recommend_gv.setVisibility(View.GONE); |
| | | viewHolder.ll_item1.setVisibility(View.VISIBLE); |
| | | viewHolder.v_top.setVisibility(View.VISIBLE); |
| | | |
| | | if ((haveHeaderView() && position == 1) || (!haveHeaderView() && position == 0)) { |
| | | viewHolder.v_top.setVisibility(View.VISIBLE); |
| | | if (showShadow && "jingxuan".equalsIgnoreCase(mFrom)) { |
| | | viewHolder.fl_shadow.setVisibility(View.VISIBLE); |
| | | viewHolder.view_shadow.setBackground(HomeUIUtil.getHomeTopBg("#FF227B", "#FF2A3E")); |
| | | } else { |
| | | viewHolder.v_top.setVisibility(View.GONE); |
| | | viewHolder.fl_shadow.setVisibility(View.GONE); |
| | | } |
| | | |
| | | viewHolder.v_top.setVisibility(View.GONE); |
| | | viewHolder.v_top1.setVisibility(View.VISIBLE); |
| | | viewHolder.v_left.setVisibility(View.GONE); |
| | | |
| | | //商品详情填充 |
| | | GoodsDetailListUtil.setGoodsDetail(mContext, info, viewHolder.goodsDetail); |
| | | // 图片 |
| | | try { |
| | | Glide.with(mContext).load(info.getPicUrl()).apply(new RequestOptions().centerCrop()).transform(new GlideRoundTransform(mContext, 5)).transition(withCrossFade()).placeholder(R.drawable.ic_goods_default).diskCacheStrategy(DiskCacheStrategy.ALL).into(viewHolder.iv_pic1); |
| | | Glide.with(mContext).load(info.getPicUrl()).apply(new RequestOptions().centerCrop()).transform(new GlideRoundTransform(mContext, 5)).transition(withCrossFade()).placeholder(R.drawable.ic_goods_default).diskCacheStrategy(DiskCacheStrategy.ALL).into(viewHolder.iv_pic); |
| | | } catch (IllegalArgumentException e) { |
| | | } |
| | | |
| | | |
| | | viewHolder.ll_item1.setOnClickListener(new View.OnClickListener() { |
| | | viewHolder.view.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = GoodsDetailJumpUtil.getGoodsDetailIntent(mContext, info.getGoodsType()); |
| | | Intent intent =new Intent(mContext,GoodsDetailActivity.class); |
| | | intent.putExtra("goodsId", info.getGoodsId()); |
| | | intent.putExtra("goodsType", info.getGoodsType()); |
| | | intent.putExtra("title", info.getTitle()); |
| | | intent.putExtra("id", info.getGoodsId()); |
| | | // intent.putExtra("from", from); |
| | | mContext.startActivity(intent); |
| | | } |
| | | }); |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean haveHeaderView() { |
| | | public boolean haveHeaderView() { |
| | | return VIEW_HEADER != null; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | class ViewHolder extends RecyclerView.ViewHolder { |
| | | TextView tv_name; |
| | | TextView tv_price; |
| | | TextView tv_coupon_price; |
| | | LinearLayout ll_coupon_bg; |
| | | TextView tv_shop_name; |
| | | LinearLayout ll_coupon; |
| | | LinearLayout ll_shop; |
| | | TextView tv_normal_price; |
| | | LinearLayout ll_recommend_gv; |
| | | TextView tv_favourable;//红包,券后价 |
| | | TextView tv_sale_num; |
| | | |
| | | View view; |
| | | //首页背景 |
| | | FrameLayout fl_shadow; |
| | | View view_shadow; |
| | | |
| | | /*********内容*********/ |
| | | ImageView iv_pic; |
| | | View v_top; |
| | | View v_top1; |
| | | View v_left; |
| | | LinearLayout ll_item1; |
| | | ImageView iv_pic1; |
| | | |
| | | |
| | | GoodsRightViewHolder goodsDetail; |
| | | |
| | |
| | | /* |
| | | 竖屏 |
| | | */ |
| | | view = convertView; |
| | | goodsDetail = new GoodsRightViewHolder(convertView); |
| | | iv_pic = convertView |
| | | .findViewById(R.id.iv_movie_cover); |
| | | tv_normal_price = convertView |
| | | .findViewById(R.id.tv_normal_price); |
| | | tv_shop_name = convertView |
| | | .findViewById(R.id.tv_shop_name); |
| | | tv_name = convertView |
| | | .findViewById(R.id.tv_movie_title); |
| | | tv_price = convertView.findViewById(R.id.tv_price); |
| | | ll_coupon_bg = convertView.findViewById(R.id.ll_coupon_bg); |
| | | tv_coupon_price = convertView.findViewById(R.id.tv_coupon_price); |
| | | ll_coupon = convertView.findViewById(R.id.ll_coupon); |
| | | ll_recommend_gv = convertView.findViewById(R.id.ll_recommend_gv); |
| | | tv_favourable = convertView.findViewById(R.id.tv_favourable); |
| | | tv_sale_num = convertView.findViewById(R.id.tv_sale_num); |
| | | ll_shop = convertView.findViewById(R.id.ll_shop); |
| | | /* |
| | | 横屏 |
| | | */ |
| | | v_top = convertView.findViewById(R.id.v_top); |
| | | v_top1 = convertView.findViewById(R.id.v_top1); |
| | | v_left = convertView.findViewById(R.id.v_left); |
| | | ll_item1 = convertView.findViewById(R.id.ll_horizontal_item); |
| | | iv_pic1 = convertView |
| | | .findViewById(R.id.iv_movie_cover1); |
| | | .findViewById(R.id.iv_pic); |
| | | |
| | | |
| | | fl_shadow = convertView |
| | | .findViewById(R.id.fl_shadow); |
| | | view_shadow = convertView |
| | | .findViewById(R.id.view_shadow); |
| | | |
| | | } |
| | | } |
| | | |