package kr.co.hanwha.hifive.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import java.util.ArrayList;

import kr.co.hanwha.hifive.adapter.contract.TaskHistoryListContract;
import kr.co.hanwha.hifive.adapter.viewholder.TaskHistoryViewHolder;
import kr.co.hanwha.hifive.data.model.TaskHistoryData;

/**
 * Created by sanghoonkwon on 2018. 1. 22..
 */

public class TaskHistoryListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
        implements TaskHistoryListContract.Model, TaskHistoryListContract.View {
    private final int ZERO = 0;

    private ArrayList<TaskHistoryData> mListData;

    /**************************************************
     * ViewActivity
     **************************************************/
    @Override
    public void notifyDataAll() {
        this.notifyDataSetChanged();

    }

    @Override
    public void notifyDataRangeChanged(int positionStart, int itemCount) {
        this.notifyItemRangeChanged(positionStart, itemCount);
    }

    /**************************************************
     * Model
     **************************************************/
    @Override
    public void clearItems() {
        if (mListData != null) mListData.clear();
    }

    @Override
    public void addItems(ArrayList<TaskHistoryData> list) {
        if (mListData == null) mListData = new ArrayList<>();
        mListData.addAll(list);
    }

    /**************************************************
     * Adapter
     **************************************************/

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TaskHistoryViewHolder(parent);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int index = position;
        TaskHistoryViewHolder view = (TaskHistoryViewHolder) holder;
        view.onBind(mListData.get(index), index);
    }

    @Override
    public int getItemCount() {
        return mListData != null ? mListData.size() : ZERO;
    }
}
