package com.mick88.dittimetable.list;

import java.util.List;

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 com.mick88.dittimetable.R;
import com.mick88.dittimetable.list.EventAdapter.EventItem;
import com.mick88.dittimetable.timetable.TimetableEvent;
import com.mick88.dittimetable.utils.FontApplicator;

public class EventAdapter extends ArrayAdapter<EventItem>
{	
	/**
	 * Interface for event list item. Represents any of the following:
	 * - Event / lecture
	 * - a group of events at the same time
	 * - one or more hour break between events
	 */
	public static interface EventItem
	{
		public static final int 
			ITEM_TYPE_EVENT = 0,
			ITEM_TYPE_MULTIEVENT = 1,
			ITEM_TYPE_SEPARATOR = 2,
			NUM_TYPES = 3;
		
		int getViewType();
		View getView(LayoutInflater layoutInflater, View convertView, ViewGroup parent, FontApplicator fontApplicator);
	}
	
	
	
	private FontApplicator fontApplicator;

	public EventAdapter(Context context, List<EventItem> objects) 
	{
		super(context, R.layout.timetable_event_small, objects);
		fontApplicator = new FontApplicator(getContext().getAssets(), "Roboto-Light.ttf");
	}
	
	LayoutInflater getLayoutInflater()
	{
		return (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		return getItem(position).getView(getLayoutInflater(), convertView, parent, fontApplicator);
		/*View view = convertView;
	
		switch (getItemViewType(position))
		{
			case EventItem.ITEM_TYPE_EVENT:
				final EventViewHolder viewHolder;
				final TimetableEvent event = (TimetableEvent) getItem(position);
				
				if (view == null)
				{
					view = getItem(position).getView(getLayoutInflater(), convertView, parent);
					fontApplicator.applyFont(view);
					viewHolder = new EventViewHolder(view);

					view.setTag(viewHolder);
				}
				else viewHolder = (EventViewHolder) view.getTag();
				
				if (event == null) return view;
				
				
				break;
				
			default:
				return getItem(position).getView(getLayoutInflater(), null, parent);
		}
		return view;*/
	}
	
	@Override
	public int getItemViewType(int position)
	{
		return getItem(position).getViewType();
	}
	
	@Override
	public int getViewTypeCount()
	{
		return EventItem.NUM_TYPES;
	}
}

@@ -220,40 +220,8 @@
 ter;
-%0Aimport android.widget.TextView;
 %0A%0Aim
@@ -316,65 +316,8 @@
 em;%0A
-import com.mick88.dittimetable.timetable.TimetableEvent;%0A
 impo
@@ -1497,683 +1497,8 @@
 r);%0A
-%09%09/*View view = convertView;%0A%09%0A%09%09switch (getItemViewType(position))%0A%09%09%7B%0A%09%09%09case EventItem.ITEM_TYPE_EVENT:%0A%09%09%09%09final EventViewHolder viewHolder;%0A%09%09%09%09final TimetableEvent event = (TimetableEvent) getItem(position);%0A%09%09%09%09%0A%09%09%09%09if (view == null)%0A%09%09%09%09%7B%0A%09%09%09%09%09view = getItem(position).getView(getLayoutInflater(), convertView, parent);%0A%09%09%09%09%09fontApplicator.applyFont(view);%0A%09%09%09%09%09viewHolder = new EventViewHolder(view);%0A%0A%09%09%09%09%09view.setTag(viewHolder);%0A%09%09%09%09%7D%0A%09%09%09%09else viewHolder = (EventViewHolder) view.getTag();%0A%09%09%09%09%0A%09%09%09%09if (event == null) return view;%0A%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09break;%0A%09%09%09%09%0A%09%09%09default:%0A%09%09%09%09return getItem(position).getView(getLayoutInflater(), null, parent);%0A%09%09%7D%0A%09%09return view;*/%0A
 %09%7D%0A%09

Clear EventAdapter