package com.viaccessorca.voplayerdemo.adapters;

import java.util.ArrayList;

import com.viaccessorca.voplayerdemo.R;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class BasicStringAdapter extends ArrayAdapter<String> {

	private ArrayList<String> items;
	private int selectedItem = -1;
	
	private static final int selectedColor = Color.rgb(30, 116, 207);

	public BasicStringAdapter(Context context, int textViewResourceId, ArrayList<String> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}
	
	public BasicStringAdapter(Context context, int textViewResourceId, String items[]) {
		super(context, textViewResourceId, items);
		this.items = new ArrayList<String>();
		for(String s: items) {
			this.items.add(s);
		}
	}


	public void setSelectedItem(int position) {
		this.selectedItem = position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.list_basic_item, null);
		}
		String item = items.get(position);
		if (item != null) {

			TextView itemText = (TextView)v.findViewById(R.id.text1);

			itemText.setText(item);
			if(position == selectedItem) {
				itemText.setSelected(true);
				itemText.setTypeface(null, Typeface.BOLD);
				itemText.setTextColor(selectedColor);
			}else{
				itemText.setSelected(false);
				itemText.setTypeface(null, Typeface.NORMAL);
				itemText.setTextColor(0xFFCCCCCC);
			}
		}
		return v;
	}
	
}
