package org.arkiwi.app.adapter;

import java.util.ArrayList;

import org.arkiwi.app.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterGrid extends BaseAdapter {
	@SuppressWarnings("unused")
	private final static String LOG_TAG = "GridAdapter";
	public static final int ACTIVITY_CREATE = 10;
	public static ArrayList<String> titles;
	public static ArrayList<Integer> icons;
	private Context mContext;

	public AdapterGrid(Context c) {
		mContext = c;
		titles = new ArrayList<String>();
		icons = new ArrayList<Integer>();
	}

	//TODO: attenzione ai tipi audio/webm - video/webm - altri.
	public void addItem(String title, String type){
		titles.add(title);
		if (type.equalsIgnoreCase("dir")) 
			icons.add(R.drawable.dir);
		else if(type.equalsIgnoreCase("audio/ogg"))
			icons.add(R.drawable.audio);
		else if(type.equalsIgnoreCase("video/ogg"))
			icons.add(R.drawable.video);
		else
			icons.add(R.drawable.audio);

		//Log.d(LOG_TAG,"addItem() "+titles.get(0));
	}
	
	public void clearData(){
		icons.clear();
		titles.clear();
	}
	
	@Override
	public int getCount() {
		//Log.d(LOG_TAG, "getCount() tn:" + titles.size());
		return titles.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v;
		if (convertView == null) {
			LayoutInflater li = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = li.inflate(R.layout.viewer_grid_ico_txt, null);
			
		} else {
			v = convertView;
		}
		
		TextView tv = (TextView) v.findViewById(R.id.icon_text);
		tv.setText(titles.get(position));
		ImageView iv = (ImageView) v.findViewById(R.id.icon_image);
		iv.setImageResource(icons.get(position));
		
		return v;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

}



