package com.newtzgames.dcssonline.data;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.newtzgames.dcssonline.R;

import java.util.List;

public class NavigationDrawerAdapter extends ArrayAdapter<DrawerItem>
{
	Context _context;
	List<DrawerItem> _items;
	int _layoutResourceID;

	public NavigationDrawerAdapter(Context context, int layoutResourceID, List<DrawerItem> items)
	{
		super(context, layoutResourceID, items);

		_context = context;
		_items = items;
		_layoutResourceID = layoutResourceID;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent)
	{
		DrawerItemHolder holder;

		if (view == null)
		{
			holder = new DrawerItemHolder();
			LayoutInflater inflater = ((Activity)_context).getLayoutInflater();

			view = inflater.inflate(R.layout.navigation_drawer_item, parent, false);

			holder.headerLayout = (LinearLayout)view.findViewById(R.id.header);
			holder.titleLayout = (LinearLayout)view.findViewById(R.id.title);
			holder.itemLayout = (LinearLayout)view.findViewById(R.id.item);

			holder.title = (TextView)view.findViewById(R.id.title_text);
			holder.item = (TextView)view.findViewById(R.id.item_text);

			view.setTag(holder);
		}
		else
		{
			holder = (DrawerItemHolder)view.getTag();
		}

		holder.headerLayout.setVisibility(LinearLayout.INVISIBLE);
		holder.titleLayout.setVisibility(LinearLayout.INVISIBLE);
		holder.itemLayout.setVisibility(LinearLayout.INVISIBLE);

		DrawerItem item = _items.get(position);
		item.configure(holder);

		return view;
	}

	public List<DrawerItem> getItems()
	{
		return _items;
	}
}
