package fishrungames.bashgid;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ListView;

public class MainPageFragment extends Fragment {
	
	
	final Integer[] teaserIcons = {
			R.drawable.economics_teaser_button,
			R.drawable.test_teaser_bkg_button,
			R.drawable.agro_teaser_button,
			R.drawable.transport_teaser_button,
			R.drawable.education_teaser_button,
			R.drawable.tourism_teaser_button,
			R.drawable.medicine_teaser_button,
			R.drawable.sport_teaser_button,
	};
	
	final String[] teaserText = {
			"Экономика",
			"Промышленность",
			"Сельское  хозяйство ",
			"Транспорт",
			"Образование",
			"Туризм",
			"Медицина",
			"Спорт",
			
	};
	
	GridView teaserGridView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_main_page, container, false);
		
	
		teaserGridView = (GridView) rootView.findViewById(R.id.teaserGridView);
		
		teaserGridView.setAdapter(new SlideListAdapter(getActivity()));
		

		return rootView;
	}
	
	
	public class SlideListAdapter extends BaseAdapter {
	    private Context mContext;

	    public SlideListAdapter(Context c) {
	        mContext = c;
	    }

	    public int getCount() {
	        return teaserIcons.length;
	    }

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

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

	    // create a new ImageView for each item referenced by the Adapter
	    public View getView(int position, View convertView, ViewGroup parent) {
	        
	    	
	    	View view;
	        if (convertView == null) {  // if it's not recycled, initialize some attributes
	        	LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        	view = inflater.inflate(R.layout.teaser_list_element, null);
	        	
	   
	        } else {
	        	view = convertView;
	        }
	        
	        Button button = (Button) view.findViewById(R.id.teaserElement);
	        
	        button.setOnClickListener(new View.OnClickListener()
	        {
				@Override
				public void onClick(View v) {
					MainActivity.getInstance().OnSelectSemiDetails(0);
				}
	        }
	        );
	        
	        //button.setBackground(mContext.getResources().getDrawable(teaserIcons[position]));

	        button.setBackgroundResource(teaserIcons[position]);
	        button.setText(teaserText[position]);
	        return view;
	    }

	}
}
