/*
 * Copyright (c) 2016, Aegir Labs LLC. All rights reserved.
 */

package com.aegir.demo.adapters;

/**
 * Created by jveach on 8/25/2016.
 */
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.aegir.demo.views.DirectionItemView;
import com.aegir.vmms.wayfinding.model.MapDirectionStep;

/**
 * Adapter used to get views for the Text Directions List
 */
public class ItemAdapter extends ArrayAdapter<MapDirectionStep> {

    /**
     * Designated constructor
     * @param c the activity context
     * @param items the list of directions
     */
    public ItemAdapter(Context c, List<MapDirectionStep> items) {
        super(c, 0, items);
    }

    /**
     * Creates the view for the given row
     * @param position the position in the list
     * @param convertView a view to recycle if any
     * @param parent the parent view group
     * @return A DirectionItemView Instance
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DirectionItemView itemView = (DirectionItemView)convertView;
        if (null == itemView)
            itemView = DirectionItemView.inflate(parent);
        itemView.setItem(getItem(position));
        return itemView;
    }
}