package cn.alandelip.teachingsupportapp.main.view.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.alandelip.teachingsupportapp.R;
import cn.alandelip.teachingsupportapp.main.data.ClassData;

/**
 * @author v-zhuxu on 6/20/2017.
 */
public class ClassDataAdapter extends ArrayAdapter<ClassData> {
    @BindView(R.id.class_name)
    TextView mClassnameText;

    private int resourceId;

    public ClassDataAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<ClassData> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view;
        if (convertView != null) {
            view = convertView;
        } else {
            view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
        }
        ButterKnife.bind(this, view);
        setData(getItem(position));
        return view;
    }

    private void setData(ClassData classData) {
        mClassnameText.setText(classData.getClassName());
    }
}
