package com.zhaohaoting.framework.abs.adapter;

import android.content.Context;
import android.widget.BaseAdapter;

import com.zhaohaoting.framework.mvchelper.mvc.IDataAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * author：Created by ZHT on 2017/11/1 16:13
 * email：526309416@qq.com
 * desc：列表类界面 基类适配器
 */
@SuppressWarnings("unchecked")
public abstract class SimpleListAdapter<DATA> extends BaseAdapter implements IDataAdapter<List<DATA>> {

    protected List<DATA> listEntity;
    protected Context context;

    public SimpleListAdapter(Context context) {
        this.listEntity = new ArrayList<>();
        this.context = context;
    }

    public SimpleListAdapter(Context context, List<DATA> listEntity) {
        this.listEntity = listEntity;
        this.context = context;
    }

    @Override
    public int getCount() {
        return listEntity.size();
    }

    @Override
    public DATA getItem(int position) {
        return listEntity.get(position);
    }

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

    @Override
    public void notifyDataChanged(List<DATA> dataList, boolean isRefresh) {
        if (isRefresh) {
            listEntity.clear();
        }
        listEntity.addAll(dataList);
        notifyDataSetChanged();
    }

    @Override
    public List<DATA> getData() {
        return listEntity;
    }

    @Override
    public boolean isEmpty() {
        return super.isEmpty();
    }

}