package org.keyscience.adapters;

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

import org.keyscience.R;
import org.keyscience.models.LectureSeriesModel;

import java.util.List;

public class LectureSeriesAdapter extends RecyclerView.Adapter<LectureSeriesAdapter.LS_ViewHolder> {

    private List<LectureSeriesModel> mData;
    private LayoutInflater mInflater;

    public LectureSeriesAdapter(List<LectureSeriesModel> mData, Context context) {
        this.mData = mData;
        this.mInflater = LayoutInflater.from(context);
    }


    @NonNull
    @Override
    public LS_ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = mInflater.inflate(R.layout.lecture_series_item, viewGroup, false);
        return new LS_ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull LS_ViewHolder lectureSeriesView, int i) {
        LectureSeriesModel currentObj = mData.get(i);
        lectureSeriesView.setData(currentObj);
    }

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

    class LS_ViewHolder extends RecyclerView.ViewHolder {

        ImageView image;
        TextView title;
        TextView paragraph;

        public LS_ViewHolder(@NonNull View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.headerImage);
            title = itemView.findViewById(R.id.ls_title);
            paragraph = itemView.findViewById(R.id.ls_paragraph);
        }

        void setData(LectureSeriesModel model) {
            image.setImageResource(model.getImage());
            title.setText(model.getTitle());
            paragraph.setText(model.getParagraph());
        }
    }
}
