package com.example.TreballFiGrau;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class EscriureNoticiaTags extends Fragment {
	CheckBox cultura;
	CheckBox esports;
	CheckBox economia;
	CheckBox politica;
	CheckBox tecnologia;
	CheckBox societat;
	CheckBox gps;
	TextView afegirTag;
	TextView llistaTags;
	TextView textViewLlistaTags;
	EditText editTextTags;
	ViewGroup rootView;
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
		Log.d("aki", "tags");	
    	rootView = (ViewGroup) inflater.inflate(R.layout.escriure_noticia_tags, container, false);
    	
    	
    	/*
    	ETtitolNoticia = (EditText) rootView.findViewById(R.id.titolNoticia);
    	ETtitolNoticia.setMaxWidth(ETtitolNoticia.getWidth());
    	*/
    	editTextTags = (EditText) rootView.findViewById(R.id.editText1);
    	editTextTags.setMaxWidth(editTextTags.getWidth());
    	
    	textViewLlistaTags = (TextView) rootView.findViewById(R.id.textViewLlistaTags);
    	textViewLlistaTags.setMovementMethod(new ScrollingMovementMethod());
    	listeners();
    	Log.d("aki", "vans cosa");
    	
    	Log.d("aki", "despres cosa");
        return rootView;
    }
	
	
	
	public void listeners(){
		cultura = (CheckBox) rootView.findViewById(R.id.checkBoxCultura);
		cultura.setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		    	  Log.d("aki", "cultura check box");	
		                //is chkIos checked?
		        if (((CheckBox) v).isChecked()) {
		        	Log.d("aki", "dintre if cultura");	
		        	NoticiaCreada.categorias.add("Cultura");
		        }
		        else{ 
		        	Log.d("aki", "else cultura");	
		        	NoticiaCreada.categorias.remove("Cultura");
		        }
		      }
		});
		esports = (CheckBox) rootView.findViewById(R.id.checkBoxEsports);
		esports.setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		                //is chkIos checked?
		        if (((CheckBox) v).isChecked()) {
		        	NoticiaCreada.categorias.add("Esports");
		        }
		        else{ 
		        	NoticiaCreada.categorias.remove("Esports");
		        }
		      }
		});
		economia = (CheckBox) rootView.findViewById(R.id.checkBoxEconomia);
		economia.setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		                //is chkIos checked?
		        if (((CheckBox) v).isChecked()) {
		        	NoticiaCreada.categorias.add("Economia");
		        }
		        else{ 
		        	NoticiaCreada.categorias.remove("Economia");
		        }
		      }
		});
		politica = (CheckBox) rootView.findViewById(R.id.checkBoxPolitica);
		politica.setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		                //is chkIos checked?
		        if (((CheckBox) v).isChecked()) {
		        	NoticiaCreada.categorias.add("Politica");
		        }
		        else{ 
		        	NoticiaCreada.categorias.remove("Politica");
		        }
		      }
		});
		tecnologia = (CheckBox) rootView.findViewById(R.id.checkBoxTecnologia);
		tecnologia.setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		                //is chkIos checked?
		        if (((CheckBox) v).isChecked()) {
		        	NoticiaCreada.categorias.add("Tecnologia");
		        }
		        else{ 
		        	NoticiaCreada.categorias.remove("Tecnologia");
		        }
		      }
		});
		societat = (CheckBox) rootView.findViewById(R.id.checkBoxSocietat);
		societat.setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		                //is chkIos checked?
		        if (((CheckBox) v).isChecked()) {
		        	NoticiaCreada.categorias.add("Societat");
		        }
		        else{ 
		        	NoticiaCreada.categorias.remove("Societat");
		        }
		      }
		});
		afegirTag= (TextView) rootView.findViewById(R.id.textViewAfegirTag);
		afegirTag.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				String cosa = editTextTags.getText().toString();
				String anterior = textViewLlistaTags.getText().toString();
				textViewLlistaTags.setText(anterior + cosa + ",");
				editTextTags.setText("");
				NoticiaCreada.tags= anterior + cosa + ", " ;
				
			}
		
		
		});
		gps = (CheckBox) rootView.findViewById(R.id.checkBoxGPS);
		gps.setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		                //is chkIos checked?
		        if (((CheckBox) v).isChecked()) {
		        	NoticiaCreada.gps=true;
		        	
		        	
		        	
		        }
		        else{ 
		        	NoticiaCreada.gps=false;
		        }
		      }
		});
		
	}
}
