package es.ua.eps.filmoteca;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class FilmAdapter extends ArrayAdapter<Film> {

    public FilmAdapter(Context context, int resource,
                       List<Film> objects) {
        super(context, resource, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null) {
            convertView = LayoutInflater.from(this.getContext())
                    .inflate(R.layout.item_film,parent,false);
        }
        TextView txtNombre = (TextView)convertView.findViewById(R.id.txtFilmItemTitle);
        TextView txtDirector = (TextView)convertView.findViewById(R.id.txtFilmItemDirector);
        ImageView imgPoster = (ImageView)convertView.findViewById(R.id.imgPoster);

        Film f = getItem(position);
        txtNombre.setText(f.title);
        txtDirector.setText(f.director);
        imgPoster.setImageResource(f.imageResId);

        return convertView;
    }
}
