package com.uiui.zyappstore.adapter;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.uiui.zyappstore.R;
import com.uiui.zyappstore.bean.AppClassBean;

import java.util.List;

public class ClassAdapter extends RecyclerView.Adapter<ClassAdapter.Holder> {
    private List<AppClassBean> mAppClassList;
    private Context mContext;

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new Holder(LayoutInflater.from(mContext).inflate(R.layout.item_app_class, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        AppClassBean appClassBean = mAppClassList.get(position);
        Glide.with(mContext).load(appClassBean.getImg_url()).error(R.drawable.ic_app).into(holder.mImageView);
    }

    @Override
    public int getItemCount() {
        return mAppClassList == null ? 0 : mAppClassList.size();
    }

    public void setAppClassList(List<AppClassBean> appClassList) {
        this.mAppClassList = appClassList;
        notifyDataSetChanged();
    }

    public void claerAppClassList() {
        this.mAppClassList = null;
        notifyDataSetChanged();
    }

    class Holder extends RecyclerView.ViewHolder {
        ImageView mImageView;

        public Holder(@NonNull View itemView) {
            super(itemView);
            mImageView = itemView.findViewById(R.id.item_iv);
        }
    }
}
