package com.howard.rockear.adapters;

import java.util.List;

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

import com.howard.rockear.R;
import com.howard.rockear.constant.AppConstant;

public class MenuListAdapter extends BaseAdapter {

	private ViewHolder viewHolder = null;
	private List<MenuListContent> listContent = null;
	private Context mContext = null;

	public MenuListAdapter(List<MenuListContent> listContent, Context mContent) {
		super();
		this.listContent = listContent;
		mContext = mContent;
	}

	@Override
	public View getView(int position, View mView, ViewGroup viewGroup) {
		if (mView == null) {
			viewHolder = new ViewHolder();
			mView = LayoutInflater.from(mContext).inflate(R.layout.menu_item,
					null);
			viewHolder.tv_title = (TextView) mView
					.findViewById(R.id.tv_title_menu);
			viewHolder.iv_icon = (ImageView) mView
					.findViewById(R.id.iv_icon_menu);
			viewHolder.iv_indicator = (ImageView) mView
					.findViewById(R.id.iv_indicator_menu);
			mView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) mView.getTag();
		}

		viewHolder.tv_title.setText(listContent.get(position).getTitle());
		if (position == AppConstant.CURRENT_MENU_ITEM) {
			viewHolder.tv_title.setTextColor(mContext.getResources().getColor(
					R.color.holo_green_dark));
			viewHolder.iv_icon.setVisibility(View.VISIBLE);
		} else {
			viewHolder.tv_title.setTextColor(mContext.getResources().getColor(
					R.color.black));
			viewHolder.iv_icon.setVisibility(View.INVISIBLE);
		}

		viewHolder.iv_icon.setBackgroundResource(listContent.get(position)
				.getIcon());
		viewHolder.iv_indicator.setBackgroundResource(listContent.get(position)
				.getIndicator());

		return mView;
	}

	@Override
	public int getCount() {
		return listContent.size();
	}

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

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

	final static class ViewHolder {
		TextView tv_title = null;
		ImageView iv_icon = null;
		ImageView iv_indicator = null;
	}

}

final class MySyncTask extends AsyncTask<String, String, String> {

	@Override
	protected String doInBackground(String... params) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.os.AsyncTask#onCancelled()
	 */
	@Override
	protected void onCancelled() {
		super.onCancelled();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.os.AsyncTask#onCancelled(java.lang.Object)
	 */
	@Override
	protected void onCancelled(String result) {
		super.onCancelled(result);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
	 */
	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.os.AsyncTask#onPreExecute()
	 */
	@Override
	protected void onPreExecute() {
		super.onPreExecute();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.os.AsyncTask#onProgressUpdate(Progress[])
	 */
	@Override
	protected void onProgressUpdate(String... values) {
		super.onProgressUpdate(values);
	}

}
