/**
 * Copyright (C) 2005-2012 XELOG AG
 */
package ch.spherIC.recurvebowsight.components;

import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ArrayAdapter;
import android.widget.TextView;

import ch.spherIC.recurvebowsight.R;
import ch.spherIC.recurvebowsight.model.IArcherySetup;

import java.util.List;


/**
 * @author  FC Smilari
 */
public class ArcerySetupArrayAdapter extends ArrayAdapter<IArcherySetup> {

    /**
     * Konstruktor.
     *
     * @param  context
     * @param  textViewResourceId
     * @param  objects
     */
    public ArcerySetupArrayAdapter(final Context context, final int textViewResourceId, final IArcherySetup[] objects) {
        super(context, textViewResourceId, objects);
    }

    /**
     * Konstruktor.
     *
     * @param  context
     * @param  textViewResourceId
     * @param  objects
     */
    public ArcerySetupArrayAdapter(final Context context, final int textViewResourceId, final List<IArcherySetup> objects) {
        super(context, textViewResourceId, objects);
    }

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {

        LayoutInflater inflater = getLayoutInflater();
        View item = inflater.inflate(R.layout.rbs_archerysetup_item, parent, false);
        XTextView textViewMain = (XTextView) item.findViewById(R.id.chooseArcherySetupTxtMain);
        TextView textViewSub = (TextView) item.findViewById(R.id.chooseArcherySetupTxtSub);

        if (getItem(position).getId() != -999) {
            textViewMain.setText(getItem(position).getName());
            textViewSub.setText(getItem(position).getRiser().toString() + " ● " + getItem(position).getSight().toString());
        } else {
            textViewMain.setText("-");
            textViewMain.setDrawborder(false);
            textViewMain.setBackgroundColor(getContext().getResources().getColor(R.color.translucent));
            textViewSub.setText(getContext().getString(R.string.caption_NoSelection));
        }

        return item;
    }

    protected LayoutInflater getLayoutInflater() {
        return (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

}
