package org.ntlab.acanthus_client.views.main_menu_ui.edit;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.content.Context;

import org.ntlab.acanthus_client.R;

import java.util.ArrayList;

public class WorkListViewAdapter extends BaseAdapter {

    private final LayoutInflater inflater;
    private final int layoutId;

    private ArrayList<String> animationNameList = new ArrayList<>();
    private ArrayList<String> lastUpdateList = new ArrayList<>();

    //参照保存データ
    static class ViewHolder {
        TextView textViewName;
        TextView textViewDate;
    }

    //コンテキスト
    public WorkListViewAdapter(Context context, int layoutId) {
        super();
        this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.layoutId = layoutId;
    }

    public WorkListViewAdapter(Context context, int layoutId, ArrayList<String> animationName, ArrayList<String> lastUpdate) {
        super();
        this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.layoutId = layoutId;
        this.animationNameList = animationName;
        this.lastUpdateList = lastUpdate;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        //Viewのinflate(拡張)
        if (convertView == null) {
            //fragment_edit.xmlにlistView用のレイアウトを入れ込む
            convertView = inflater.inflate(layoutId, parent, false);
            //ViewHolderの生成とレイアウト内テキストのセット
            viewHolder = new ViewHolder();
            viewHolder.textViewName = convertView.findViewById(R.id.textViewName);
            viewHolder.textViewDate = convertView.findViewById(R.id.textViewDate);
            convertView.setTag(viewHolder);
        } else {
            //既に初期セットの処理がされている場合、再利用する
            viewHolder = (ViewHolder) convertView.getTag();
        }

        //ViewHolder内のtextViewName,Dateに各ポジションのデータをセット
        if (animationNameList != null) viewHolder.textViewName.setText(animationNameList.get(position));
        if (lastUpdateList != null) viewHolder.textViewDate.setText(lastUpdateList.get(position));

        return convertView;
    }

    public void setAnimationNameList(ArrayList<String> animationNameList) {
        this.animationNameList = animationNameList;
    }

    public void setLastUpdateList(ArrayList<String> lastUpdateList) {
        this.lastUpdateList = lastUpdateList;
    }

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

    @Override
    public Object getItem(int position) {
        return null;
    }

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

}
