package de.tudarmstadt.informatik.hostage.ui2.adapter;

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

import java.util.List;

import de.tudarmstadt.informatik.hostage.R;
import de.tudarmstadt.informatik.hostage.ui2.model.DrawerListItem;

/**
 * @author Alexander Brakowski
 * @created 13.01.14 16:35
 */
public class DrawerListAdapter extends ArrayAdapter<DrawerListItem> {
    private final Context mContext;
    private final List<DrawerListItem> mValues;

    public DrawerListAdapter(Context context, List<DrawerListItem> objects) {
        super(context, R.layout.drawer_list_item, objects);
        this.mContext = context;
        this.mValues  = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.drawer_list_item, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.drawer_listitem_text);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.drawer_listitem_icon);

        DrawerListItem item = mValues.get(position);
        textView.setText(item.text);
        imageView.setImageResource(item.icon);

        return rowView;
    }
}
