package es.upvmaster.fullmediaplayer;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.Vector;

/**
 * Created by crpor on 06/08/2016.
 */
public class AdaptadorListas extends RecyclerView.Adapter<AdaptadorListas.ViewHolder> {
    private LayoutInflater inflador;
    protected Vector<ListaMedios> vectorListaMedios;

    private View.OnClickListener onClickListener;
    private View.OnLongClickListener onLongClickListener;

    public AdaptadorListas(Context contexto, Vector<ListaMedios> vectorListaMedios) {
        this.vectorListaMedios = vectorListaMedios;
        this.inflador = (LayoutInflater) contexto.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void setOnItemClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public void setOnLongClickListener(View.OnLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView nombreLista;
        public TextView nombreAutor;

        public ViewHolder(View itemView) {
            super(itemView);
            this.nombreLista = (TextView) itemView.findViewById(R.id.nombreLista);
            this.nombreAutor = (TextView) itemView.findViewById(R.id.nombreAutor);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = this.inflador.inflate(R.layout.elemento_lista,null);
        v.setOnClickListener(onClickListener);
        v.setOnLongClickListener(onLongClickListener);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ListaMedios listaMediosActual = vectorListaMedios.elementAt(position);
        holder.nombreLista.setText(listaMediosActual.getName());
        holder.nombreAutor.setText(InfoGlobal.getINSTANCIA().getContextoAplicacion().getResources().getString(R.string.texto_autor)+" "+listaMediosActual.getAuthor());
    }

    @Override
    public int getItemCount() {
        return vectorListaMedios.size();
    }
}
