package com.example.TreballFiGrau;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class EscriureNoticiaMedia extends Fragment {
	TextView afegirFoto;
	TextView afegirVideo;
	ViewGroup rootView;
	GridView gridviewFotos;
	GridView gridviewVideos;
	public static NoticiaCreadaGAFotos adapterFotos;
	public static NoticiaCreadaGAVideos adapterVideos;
	
	private static final int SELECT_VIDEO = 3;
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
		Log.d("aki", "media");	
		rootView = (ViewGroup) inflater.inflate(R.layout.escriure_noticia_media, container, false);
		
		
		gridviewFotos = (GridView) rootView.findViewById(R.id.gridViewFotos);
		adapterFotos = new NoticiaCreadaGAFotos(getActivity());
		gridviewFotos.setAdapter(adapterFotos);

		gridviewFotos.setOnItemClickListener(new OnItemClickListener() {
	        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
	            Toast.makeText(getActivity(), "" + position, Toast.LENGTH_SHORT).show();
	        }
	    });
		
		
		gridviewVideos = (GridView) rootView.findViewById(R.id.gridViewVideos);
		adapterVideos = new NoticiaCreadaGAVideos(getActivity());
		gridviewVideos.setAdapter(adapterVideos);

		gridviewVideos.setOnItemClickListener(new OnItemClickListener() {
	        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
	            Toast.makeText(getActivity(), "" + position, Toast.LENGTH_SHORT).show();
	        }
	    });
		
		
		
		listener();
        return rootView;
    }
	public void listener(){
		afegirFoto= (TextView) rootView.findViewById(R.id.textViewAfegeixFoto);
		afegirFoto.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				Log.d("aki", "listener fotos");	
				Intent intent = new Intent( getActivity(), NoticiaCreadaAfegirFoto.class);
            	startActivity(intent);
            	Log.d("aki", "listerner despres");	
			}
		});
		
		afegirVideo= (TextView) rootView.findViewById(R.id.textViewAfegeixVideo);
		afegirVideo.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				Log.d("aki", "111");	
				Intent intent = new Intent( getActivity(), NoticiaCreadaAfegirVideo.class);
            	startActivity(intent);
            	Log.d("aki", "22222");	
			}
		});
		
	}
	
}
