package com.usai.apex;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class DocumentsFragment extends ListFragment
{
	

	// @Override
	// public View onCreateView(LayoutInflater inflater, ViewGroup container,
	// Bundle savedInstanceState)
	// {
	// View view = inflater.inflate(R.layout.fragment_tools, null);
	// // Button btn = (Button) view.findViewById(R.id.btn_cancel);
	// // btn.setOnClickListener(this);
	// return view;
	// // return super.onCreateView(inflater, container, savedInstanceState);
	// }
	private List<Map<String, Object>> getData()
	{
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("title", "Search document online");
		map.put("img", R.drawable.rect_search_documents);
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("title", "View downloaded document");
		map.put("img", R.drawable.rect_view_download_documents);
		list.add(map);

	
		
		return list;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState)
	{
		super.onActivityCreated(savedInstanceState);
		SimpleAdapter adapter = new SimpleAdapter(this.getActivity(),
				getData(), R.layout.fragment_tools, new String[] { "title",
						"img" }, new int[] { R.id.tv_toolname, R.id.iv_thumb});
		setListAdapter(adapter);
		this.getListView().setBackgroundColor(Color.WHITE);
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id)
	{
		Log.d("FragmentList", "Item clicked: " + id);
		
		String title = (String) getData().get(position).get("title");
		Intent intent = new Intent();
		if(title.equals("Search document online"))
		{
			intent.setClass(getActivity(), SearchListActivity.class);
	
			intent.putExtra("function_name", "Download Document");
			intent.putExtra("title", "Document Search");

		}
		else if(title.equals("View downloaded document"))
		{
			intent.setClass(getActivity(), LocalDocumentActivity.class);
//			intent.putExtra("module_name", "Announcements");
		}

		
		startActivity(intent);

	}
}
