package de.metalmatze.krautreporter.adapters;

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

import java.text.SimpleDateFormat;
import java.util.List;

import de.metalmatze.krautreporter.R;
import de.metalmatze.krautreporter.entities.Article;
import de.metalmatze.krautreporter.viewholders.ArticleViewHolder;

public class ArticleRecyclerViewAdapter extends RecyclerView.Adapter<ArticleViewHolder> {

    private List<Article> articles;

    public ArticleRecyclerViewAdapter(List<Article> articles) {
        this.articles = articles;
    }

    @Override
    public ArticleViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View itemView = LayoutInflater
                        .from(viewGroup.getContext())
                        .inflate(R.layout.article_list, viewGroup, false);

        return new ArticleViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ArticleViewHolder articleViewHolder, int position) {
        Article article = this.articles.get(position);

        String articleDate = new SimpleDateFormat("dd.MM.yyyy").format(article.getDate().getTime());
        articleViewHolder.article_date.setText(articleDate);
        articleViewHolder.article_headline.setText(article.getTitle());
    }

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

@@ -40,16 +40,79 @@
 pters;%0A%0A
+import android.content.Context;%0Aimport android.content.Intent;%0A
 import a
@@ -242,16 +242,48 @@
 ewGroup;
+%0Aimport android.widget.TextView;
 %0A%0Aimport
@@ -408,19 +408,21 @@
 eporter.
-ent
+activ
 ities.Ar
@@ -426,16 +426,24 @@
 .Article
+Activity
 ;%0Aimport
@@ -475,37 +475,24 @@
 ter.
-viewholders.ArticleViewHolder
+entities.Article
 ;%0A%0Ap
@@ -562,24 +562,44 @@
 pter%3CArticle
+RecyclerViewAdapter.
 ViewHolder%3E 
@@ -636,16 +636,45 @@
 rticles;
+%0A    private Article article;
 %0A%0A    pu
@@ -796,32 +796,52 @@
   public Article
+RecyclerViewAdapter.
 ViewHolder onCre
@@ -883,16 +883,9 @@
 int 
-viewType
+i
 ) %7B%0A
@@ -939,24 +939,16 @@
         
-  
-      
 .from(vi
@@ -969,24 +969,16 @@
 text())%0A
-        
         
@@ -1056,23 +1056,16 @@
 urn new 
-Article
 ViewHold
@@ -1135,24 +1135,44 @@
 lder(Article
+RecyclerViewAdapter.
 ViewHolder a
@@ -1170,24 +1170,17 @@
 wHolder 
-articleV
+v
 iewHolde
@@ -1198,24 +1198,25 @@
 tion) %7B%0A
+%0A
         
 Article 
@@ -1207,24 +1207,21 @@
         
-Article 
+this.
 article 
@@ -1357,32 +1357,25 @@
 ));%0A        
-articleV
+v
 iewHolder.ar
@@ -1419,16 +1419,9 @@
     
-articleV
+v
 iewH
@@ -1567,11 +1567,808 @@
 );%0A    %7D
+%0A%0A    public class ViewHolder extends RecyclerView.ViewHolder %7B%0A%0A        public TextView article_date;%0A        public TextView article_headline;%0A%0A        public ViewHolder(final View itemView) %7B%0A            super(itemView);%0A%0A            this.article_date = (TextView) itemView.findViewById(R.id.article_list_date);%0A            this.article_headline = (TextView) itemView.findViewById(R.id.article_list_headline);%0A%0A            itemView.setOnClickListener(new View.OnClickListener() %7B%0A                @Override%0A                public void onClick(View v) %7B%0A                    Context context = itemView.getContext();%0A%0A                    Intent intent = new Intent(context, ArticleActivity.class);%0A                    context.startActivity(intent);%0A                %7D%0A            %7D);%0A        %7D%0A    %7D
 %0A%7D%0A

Improve the ArticleRecyclerViewAdapter with ViewHolder included and with onClick