package fishrungames.bashgid;


import android.annotation.SuppressLint;
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.widget.BaseAdapter;

import android.widget.ImageView;
import android.widget.ListView;

import fishrungames.bashgid.core.AlbumManager;
import fishrungames.networkutils.ImageManager;

public class PhotoAlbumFragment extends Fragment
{
	
	AlbumManager.AlbumStruct album;
	
	ListAdapter listAdapter;
	
	public PhotoAlbumFragment(AlbumManager.AlbumStruct album)
	{
		this.album = album;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		
		View rootView = inflater.inflate(R.layout.fragment_photo_album_page, container, false);

		listAdapter = new ListAdapter(getActivity());
		
		ListView listView = (ListView) rootView.findViewById(R.id.listView);
		
		listView.setAdapter(listAdapter);
		
		return rootView;
	}
	
	public class ListAdapter extends BaseAdapter {
	    private Context mContext;

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

	    public int getCount() {
	        return album.imageIds.size();
	    }

	    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
	    @SuppressLint("InflateParams")
	    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.photo_album_element, null);
	        	
	   
	        } else {
	        	view = convertView;
	        }
	        
	        
	        ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
	        
	        ImageManager.getInstance().ApplyImageToImageView(imageView, album.imageIds.get(position));
	        
	        return view;
	    }

	}
	
	
}