package com.example.TreballFiGrau;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class LlegirNoticiaTags extends Fragment {
	ViewGroup rootView;
	TextView llistaTags;
	CheckBox checkBoxLlegirEconomia,checkBoxLlegirEsports,checkBoxLlegirSocietat;
	CheckBox checkBoxLlegirPolitica,checkBoxLlegirTecnologia,checkBoxLlegirCultura;
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
		
		rootView = (ViewGroup) inflater.inflate(R.layout.llegir_noticia_tags, container, false);

		//Button sendButton = (Button) rootView.findViewById(R.id.titolNoticia);
		Log.d("aki", "tags");	
    	//ETtitolNoticia = (EditText) rootView.findViewById(R.id.titolNoticia);
    	//ETtitolNoticia.setMaxWidth(ETtitolNoticia.getWidth());
    	
    
		cargarCategories();
		cargarTags();
    	
    	
    	return rootView;
   

    }
	
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public void cargarCategories(){
		Log.d("aki", "cargar tags");	
		
    	
		checkBoxLlegirEconomia = (CheckBox) rootView.findViewById(R.id.checkBoxLlegirEconomia);
		checkBoxLlegirEconomia.setEnabled(false);
		if(NoticiaSeleccionada.categorias.contains("Economia")){
			Log.d("aki", "dintre if 1");	
			checkBoxLlegirEconomia.setChecked(true);
		}
		checkBoxLlegirEsports = (CheckBox) rootView.findViewById(R.id.checkBoxLlegirEsports);
		checkBoxLlegirEsports.setEnabled(false);
		if(NoticiaSeleccionada.categorias.contains("Esports")){
			Log.d("aki", "dintre if 2");
			checkBoxLlegirEsports.setChecked(true);
		}
		checkBoxLlegirSocietat = (CheckBox) rootView.findViewById(R.id.checkBoxLlegirSocietat);
		checkBoxLlegirSocietat.setEnabled(false);
		if(NoticiaSeleccionada.categorias.contains("Societat")){
			Log.d("aki", "dintre if 3");
			checkBoxLlegirSocietat.setChecked(true);
		}
		checkBoxLlegirCultura = (CheckBox) rootView.findViewById(R.id.checkBoxLlegirCultura);
		checkBoxLlegirCultura.setEnabled(false);
		if(NoticiaSeleccionada.categorias.contains("Cultura")){
			Log.d("aki", "dintre if 4");
			checkBoxLlegirCultura.setChecked(true);
		}
		checkBoxLlegirPolitica = (CheckBox) rootView.findViewById(R.id.checkBoxLlegirPolitica);
		checkBoxLlegirPolitica.setEnabled(false);
		if(NoticiaSeleccionada.categorias.contains("Politica")){
			Log.d("aki", "dintre if 5");
			checkBoxLlegirPolitica.setChecked(true);
		}
		checkBoxLlegirTecnologia = (CheckBox) rootView.findViewById(R.id.checkBoxLlegirTecnologia);
		checkBoxLlegirTecnologia.setEnabled(false);
		if(NoticiaSeleccionada.categorias.contains("Tecnologia")){
			Log.d("aki", "dintre if 6");
			checkBoxLlegirTecnologia.setChecked(true);
		}
		
	}
	
	
	public void cargarTags(){
		Log.d("aki", NoticiaSeleccionada.tags);
		llistaTags = (TextView) rootView.findViewById(R.id.textViewLlegirLlistaTags);
		//llistaTags.setMaxWidth(llistaTags.getWidth());
		llistaTags.setText(NoticiaSeleccionada.tags);
		llistaTags.setMovementMethod(new ScrollingMovementMethod());
		//llistaTags.setText("dintre");
	}
}
