package com.viaccessorca.voplayerdemo.adapters;

import java.util.List;

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

import com.viaccessorca.voplayerdemo.R;
import com.viaccessorca.voplayerdemo.mediamgt.MediaItem;
import com.viaccessorca.voplayerdemo.mediamgt.SubtitleMediaItem;

public class SubtitleListAdapter extends ArrayAdapter<MediaItem> {


	private List<MediaItem> items;
	private int selectedItem = -1;

	public SubtitleListAdapter(Context context, int textViewResourceId, List<MediaItem> subtitlesList) {
		super(context, textViewResourceId, subtitlesList);
		this.items = subtitlesList;
	}

	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);
		}
		SubtitleMediaItem mediaItem = (SubtitleMediaItem) items.get(position);
		if (mediaItem != null) {

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

			itemText.setText(mediaItem.getDisplayName());
			if(position == selectedItem) {
				itemText.setSelected(true);
				itemText.setTypeface(null, Typeface.BOLD);
				itemText.setTextColor(android.graphics.Color.CYAN);
			}else{
				itemText.setSelected(false);
				itemText.setTypeface(null, Typeface.NORMAL);
				itemText.setTextColor(0xFFCCCCCC);
			}
		}
		return v;
	}
}
