package fishrungames.bashgid;

import fishrungames.bashgid.core.AlbumManager.AlbumFullData;

import fishrungames.networkutils.ImageManager;
 

import android.content.Context;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PhotoFragmentAdapter extends PagerAdapter {
 
	private Context context;
	
	AlbumFullData album;
	

    public PhotoFragmentAdapter(Context context, AlbumFullData album) {
    	this.context = context;
        this.album = album;
    }
 
    @Override
    public int getCount() {
        return album.photoRecordArr.size();
    }
 
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((LinearLayout) object);
    }
     
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
       
    	
 
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        View viewLayout = inflater.inflate(R.layout.photo_page_element, container,
                false);
        
        TextView titleTextView = (TextView) viewLayout.findViewById(R.id.titleTextView);
    	
    	titleTextView.setText(album.photoRecordArr.get(position).title);
    	
    	TextView descriptionTextView = (TextView) viewLayout.findViewById(R.id.descriptionTextView);
    	
    	descriptionTextView.setText(album.photoRecordArr.get(position).description);
    	
        ImageView image = (ImageView) viewLayout.findViewById(R.id.image);
  
        ImageManager.getInstance().ApplyImageToImageView(image, album.photoRecordArr.get(position).imageUrl);
                  
        ((ViewPager) container).addView(viewLayout);
  
        return viewLayout;
    }
    
    @Override
    public void destroyItem(View collection, int position, Object o) {
        View view = (View)o;
        ((ViewPager) collection).removeView(view);
        view = null;
    }
     
}