package com.zxhl.main.page.adapter;


import android.content.Context;
import android.util.Log;
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.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
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.MarqueeEntity;
import com.zxhl.cms.widget.RecycleImageView;
import com.zxhl.main.R;

import java.util.List;

public class AutoPollAdapter extends RecyclerView.Adapter<AutoPollAdapter.BaseViewHolder> {
    private final Context mContext;
    private final List<MarqueeEntity> mData;

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

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.auto_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).getHeadImage())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(holder.imghead);
//        Glide.with(mContext).load(mData.get(pos).getGoodsImage())
//                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
//                .into(holder.imggoods);
        holder.imggoods.setLoadImageUrl(mData.get(pos).getGoodsImage(),false);
        holder.content.setText(mData.get(pos).getText());

//        switch (mData.get(pos).getLevel()){
//            case 0:
//                break;
//            case 1:
//                break;
//            case 2:
//                break;
//            case 3:
//                break;
//        }

    }

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

    class BaseViewHolder extends RecyclerView.ViewHolder {
        TextView content;
        ImageView imghead;
        RecycleImageView imggoods;

        public BaseViewHolder(View itemView) {
            super(itemView);
            content = itemView.findViewById(R.id.content);
            imghead = itemView.findViewById(R.id.id_img_1);
            imggoods = itemView.findViewById(R.id.id_img_goos);
        }
    }
}

