package com.common.lib_base.base.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Date: 2022/5/26 0026 13:53
 * Description:
 */
public abstract class SuperBaseAdapter<T> extends BaseAdapter {
    private List<T> mData;

    public SuperBaseAdapter(List<T> data) {
        this.mData = data;
    }

    @Override
    public int getCount() {
        if (mData != null || mData.size() <= 0) {
            return 0;
        }
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BaseViewHolder holder = null;
        if (convertView == null) {
            holder = getHolder();
        } else {
            holder = (BaseViewHolder) convertView.getTag();
        }
        holder.setData(mData.get(position));
        return holder.convertView;
    }

    public abstract BaseViewHolder getHolder();


}