package com.nmakademija.nmaakademija.adapter;

import android.content.Context;
import android.content.Intent;
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 com.bumptech.glide.Glide;
import com.nmakademija.nmaakademija.ArticleActivity;
import com.nmakademija.nmaakademija.R;
import com.nmakademija.nmaakademija.entity.Article;

import java.util.List;

public class ArticlesAdapter extends RecyclerView.Adapter<ArticlesAdapter.MyViewHolder> {
    private List<Article> articlesList;

    public ArticlesAdapter(List<Article> articlesList) {
        this.articlesList = articlesList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item_news, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final Article article = articlesList.get(position);
        holder.title.setText(article.getTitle());
        holder.description.setText(article.getDescription());
        Glide.with(holder.itemView.getContext()).load(article.getTitleImage()).into(holder.image);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Context c = view.getContext();
                Intent i = new Intent(c, ArticleActivity.class);
                i.putExtra(ArticleActivity.EXTRA_ARTICLE_CONTENT, article.getContent());
                c.startActivity(i);
            }
        });
    }

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

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView title, description;
        public ImageView image;

        public MyViewHolder(View view) {
            super(view);
            title = (TextView) view.findViewById(R.id.news_title);
            description = (TextView) view.findViewById(R.id.news_description);
            image = (ImageView) view.findViewById(R.id.news_image);
        }
    }
}

@@ -1539,16 +1539,22 @@
 ontext c
+ontext
  = view.
@@ -1591,16 +1591,21 @@
 Intent i
+ntent
  = new I
@@ -1611,16 +1611,22 @@
 Intent(c
+ontext
 , Articl
@@ -1660,16 +1660,21 @@
        i
+ntent
 .putExtr
@@ -1754,16 +1754,22 @@
        c
+ontext
 .startAc
@@ -1776,16 +1776,21 @@
 tivity(i
+ntent
 );%0A     

rename var