package com.example.TreballFiGrau;

import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
 
public class GalleryAdapter extends BaseAdapter {
    private Context mContext;

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

    public int getCount() {
        return mThumbIds.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) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }*/
    
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) {
    	 ImageView imageView;
    	 if (convertView == null) {
    		 imageView = new ImageView(mContext);
    		 imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
             imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
             imageView.setPadding(8, 8, 8, 8);
    		 
    	 }else{
    		 imageView = (ImageView) convertView;
    	 }
    	  //String url = (String) getItem(position);

    	  Picasso.with(mContext).load(mThumbIds[position]).into( imageView);
    	  return imageView;
    	}
    

    // references to our images
    private String[] mThumbIds = {
    		"http://tfg-sharenews.rhcloud.com/media/img/2014/05/30/grey_knight_term_150_129.gif/", "http://tfg-sharenews.rhcloud.com/media/img/2014/05/30/grey_knight_term_150_129.gif/",
    		"http://tfg-sharenews.rhcloud.com/media/img/2014/05/30/videoTest.mp4"
            
    };
}