package com.zxhl.main.page.adapter;

import android.app.Application;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.zxhl.cms.AppContext;
import com.zxhl.cms.net.model.box.GoodList;
import com.zxhl.main.R;

import java.util.List;

public class DetailMiddleAdapter extends RecyclerView.Adapter<DetailMiddleAdapter.BaseViewHolder> {
    private final Context mContext;
    private final List<GoodList> mData;
    //private final int[] imgRes = new int[]{R.drawable.icon_jinbi, R.drawable.icon_kefu_hei,};

    public DetailMiddleAdapter(Context context, List<GoodList> list) {
        this.mContext = context;
        this.mData = list;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.middle_list_item, parent, false);
        BaseViewHolder holder = new BaseViewHolder(view);
        return holder;

    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        int pos = position % mData.size();

        Glide.with(AppContext.get()).load(mData.get(pos).getMainImage())
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(10)))
                .into(holder.imggood);
        if (mData.get(pos).getGoodsLevel().equals("0")) {
            holder.catename.setBackgroundResource(R.drawable.shape_putong_bg_left);
        } else if (mData.get(pos).getGoodsLevel().equals("1")) {
            holder.catename.setBackgroundResource(R.drawable.shape_xiyou_bg_left);
        } else if (mData.get(pos).getGoodsLevel().equals("2")) {
            holder.catename.setBackgroundResource(R.drawable.shape_shishi_bg_left);
        } else if (mData.get(pos).getGoodsLevel().equals("3")) {
            holder.catename.setBackgroundResource(R.drawable.shape_chuanshuo_bg_left);
        }
        holder.catename.setText(mData.get(pos).getCateName());

    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }

    class BaseViewHolder extends RecyclerView.ViewHolder {
        TextView catename;
        ImageView imggood;

        public BaseViewHolder(View itemView) {
            super(itemView);
            catename = itemView.findViewById(R.id.id_tv_cate_it);
            imggood = itemView.findViewById(R.id.id_img_goos_it);
        }
    }
}


