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.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class SemiDetailsFragment extends Fragment {
	
	
	ListView semidetailsGridView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_semidetails_page, container, false);
		
		semidetailsGridView = (ListView) rootView.findViewById(R.id.listView);
		
		semidetailsGridView.setAdapter(new SemidetailsAdapter(getActivity()));

		return rootView;
	}
	
	

	
	public class SemidetailsAdapter extends BaseAdapter {
	    private Context mContext;

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

	    public int getCount() {
	        return 2;
	    }

	    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.semidetails_element, null);
	        	
	   
	        } else {
	        	view = convertView;
	        }
	        
	        TextView headerTextView = (TextView)view.findViewById(R.id.headerTextView);
	        TextView subHeaderTextView = (TextView)view.findViewById(R.id.subHeaderTextView);
	        
	        ImageView imageView = (ImageView)view.findViewById(R.id.imageView);
	        
	        TextView imageTextView = (TextView)view.findViewById(R.id.imageTextView);
	        
	        TextView footerTextView = (TextView)view.findViewById(R.id.footerTextView);
	        
	        if (position == 0)
	        {
	        	headerTextView.setVisibility(View.VISIBLE);
	        	headerTextView.setText("Структура промышленности Башкортостана");
	        	
	        	subHeaderTextView.setText("Важнейшие отрасли промышленности Башкортостана — нефтедобыча, нефтепереработка, химия и нефтехимия.");
	        	subHeaderTextView.setVisibility(View.VISIBLE);
	        	
	        	imageView.setImageResource(R.drawable.test_promstruct_rb);
	        	
	        	LayoutParams params = imageView.getLayoutParams();
	        	params.width = LayoutParams.MATCH_PARENT;
	        	imageView.setLayoutParams(params);
	        	
	        	
	        	
	        	imageTextView.setVisibility(View.GONE);
	        	
	        	footerTextView.setText("");
	        	
	        }
	        else
	        {
	        	headerTextView.setVisibility(View.VISIBLE);
	        	headerTextView.setText("УМПО");
	        	
	        	subHeaderTextView.setVisibility(View.VISIBLE);
	        	subHeaderTextView.setText("Стремимся к вершинам!");
	        	
	        	imageView.setImageResource(R.drawable.test_umpo);
	        	
	        	LayoutParams params = imageView.getLayoutParams();
	        	params.width = 200;
	        	imageView.setLayoutParams(params);
	        	
	        	
	        	imageTextView.setVisibility(View.VISIBLE);
	        	imageTextView.setText("УМПО - российское предприятие, производитель авиационных двигателей. Основано в 1925 году. В объединении работают более 15 тысяч человек.");
	        	
	        	footerTextView.setText("Нажмите сюда для подробностей");
	        }
	        
	        //Button button = (Button) view.findViewById(R.id.teaserElement);
	        
	        //button.setBackground(mContext.getResources().getDrawable(teaserIcons[position]));

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

	}
}
