GoodsMsgProvider

@ProviderTag(messageContent = GoodsMsg.class, showReadState = true)
public class GoodsMsgProvider extends IContainerItemProvider.MessageProvider {

    private Context mContext;

    public GoodsMsgProvider(Context context) {
        mContext = context;
    }

    @Override
    public void bindView(View view, int i, GoodsMsg goodsMsg, UIMessage uiMessage) {
        //根据需求,适配数据
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.tvGoodsName.setText(goodsMsg.getGoodsName());
        holder.tvShopName.setText(goodsMsg.getShopName());
        holder.tvGoodsPrice.setText(goodsMsg.getGoodsPriceMin());
        GlideRoundTransform glideRoundTransform = new GlideRoundTransform(mContext, 8, GlideRoundTransform.CornerType.TOP);
        Glide.with(mContext)
                .load(goodsMsg.getGoodsCoverUrl())
                .apply(new RequestOptions()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .transform(glideRoundTransform))
                .placeholder(R.mipmap.icon_default_placeholder)
                .into(holder.ivGoodsCover);
        ImageLoaderUtil.loadImgCenterCrop(holder.ivShopLogo, goodsMsg.getShopLogo(), R.mipmap.icon_default_avatar_shop);
        List goodsTag = goodsMsg.getGoodsTag();
        if (goodsTag != null && !goodsTag.isEmpty()) {
            holder.tflGoodsTag.setVisibility(View.VISIBLE);
            holder.tflGoodsTag.setAdapter(new TagAdapter(goodsTag) {
                @Override
                public View getView(FlowLayout parent, int position, String s) {
                    TextView tv = (TextView) LayoutInflater.from(mContext).inflate(R.layout.item_goods_tag_bg, parent, false);
                    tv.setText(s);
                    return tv;
                }
            });
        } else {
            holder.tflGoodsTag.setVisibility(View.GONE);
        }
    }

    @Override
    public Spannable getContentSummary(GoodsMsg goodsMsg) {
        return null;
    }

    @Override
    public Spannable getContentSummary(Context context, GoodsMsg data) {
        return new SpannableString("[商品信息]");
    }

    @Override
    public void onItemClick(View view, int i, GoodsMsg goodsMsg, UIMessage uiMessage) {
        String goodsId = goodsMsg.getGoodsId();
        ARouter.getInstance()
                .build(CommonARouterPath.GOODS_DETAIL_ACTIVITY)
                .withString("id", goodsId)
                .navigation();
    }

    @Override
    public View newView(Context context, ViewGroup viewGroup) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_goods_msg, null);
        view.setLayoutParams(new ViewGroup.LayoutParams((int) (ScreenUtil.getScreenWidth(context) * 2 / 3), ViewGroup.LayoutParams.WRAP_CONTENT));
        ViewHolder holder = new ViewHolder();
        holder.ivGoodsCover = view.findViewById(R.id.iv_goods_cover);
        holder.ivShopLogo = view.findViewById(R.id.iv_shop_logo);
        holder.tvGoodsPrice = view.findViewById(R.id.tv_goods_price);
        holder.tvGoodsName = view.findViewById(R.id.tv_goods_name);
        holder.tvShopName = view.findViewById(R.id.tv_shop_name);
        holder.tflGoodsTag = view.findViewById(R.id.tfl_goods_tag);
        view.setTag(holder);
        return view;
    }

    private static class ViewHolder {
        ImageView ivGoodsCover;
        CircleImageView ivShopLogo;
        TextView tvGoodsPrice, tvGoodsName, tvShopName;
        TagFlowLayout tflGoodsTag;
    }
}

你可能感兴趣的:(GoodsMsgProvider)