package de.metalmatze.krautreporter.adapters;

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.TextView;

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

import de.metalmatze.krautreporter.R;
import de.metalmatze.krautreporter.activities.ArticleActivity;
import de.metalmatze.krautreporter.models.ArticleModel;

public class ArticleRecyclerViewAdapter extends RecyclerView.Adapter<ArticleRecyclerViewAdapter.ViewHolder> {

    protected Context context;
    private List<ArticleModel> articles;

    public ArticleRecyclerViewAdapter(Context context, List<ArticleModel> articles) {
        this.context = context;
        this.articles = articles;
    }

    @Override
    public ArticleRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater
                .from(viewGroup.getContext())
                .inflate(R.layout.article_card, viewGroup, false);

        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ArticleRecyclerViewAdapter.ViewHolder viewHolder, int position) {

	this.article = this.articles.get(position);

        String articleDate = new SimpleDateFormat("dd.MM.yyyy").format(article.date.getTime());
        viewHolder.article_date.setText(articleDate);
        viewHolder.article_headline.setText(article.title);
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

	public TextView article_date;
        public TextView article_headline;

        public ViewHolder(final View itemView) {
            super(itemView);

	    this.article_date = (TextView) itemView.findViewById(R.id.article_date);
            this.article_headline = (TextView) itemView.findViewById(R.id.article_title);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Context context = itemView.getContext();

                    ArticleModel articleModel = articles.get(getPosition());

                    Intent intent = new Intent(context, ArticleActivity.class);
                    intent.putExtra("id", articleModel.getId());
                    context.startActivity(intent);
                }
            });
        }

    }
}

@@ -103,16 +103,48 @@
 Intent;%0A
+import android.graphics.Bitmap;%0A
 import a
@@ -297,24 +297,223 @@
 .widget.
-TextView
+ImageView;%0Aimport android.widget.TextView;%0A%0Aimport com.android.volley.Response;%0Aimport com.android.volley.VolleyError;%0Aimport com.android.volley.toolbox.ImageRequest;%0Aimport com.android.volley.toolbox.Volley
 ;%0A%0Aimpor
@@ -1427,16 +1427,22 @@
 wHolder(
+final 
 ArticleR
@@ -1504,14 +1504,29 @@
  %7B%0A%0A
-%09this.
+        ArticleModel 
 arti
@@ -1767,24 +1767,904 @@
 cle.title);%0A
+%0A        if (article.image != null)%0A        %7B%0A            viewHolder.article_image.setVisibility(View.VISIBLE);%0A%0A            ImageRequest imageRequest = new ImageRequest(%0A                    article.image,%0A                    new Response.Listener%3CBitmap%3E() %7B%0A                        @Override%0A                        public void onResponse(Bitmap bitmap) %7B%0A                            viewHolder.article_image.setImageBitmap(bitmap);%0A                        %7D%0A                    %7D,%0A                    0,0,null,%0A                    new Response.ErrorListener() %7B%0A                        @Override%0A                        public void onErrorResponse(VolleyError volleyError) %7B%0A                            volleyError.printStackTrace();%0A                        %7D%0A                    %7D%0A            );%0A%0A            Volley.newRequestQueue(this.context).add(imageRequest);%0A        %7D%0A%0A
     %7D%0A%0A    @
@@ -2815,20 +2815,28 @@
  %7B%0A%0A
-%09
+        
 public 
-Text
+Image
 View
@@ -2844,19 +2844,20 @@
 article_
-dat
+imag
 e;%0A     
@@ -2892,16 +2892,95 @@
 eadline;
+%0A        public TextView article_date;%0A        public TextView article_excerpt;
 %0A%0A      
@@ -3056,9 +3056,16 @@
 );%0A%0A
-%09
+        
     
@@ -3081,20 +3081,22 @@
 cle_
-dat
+imag
 e = (
-Text
+Image
 View
@@ -3132,19 +3132,20 @@
 article_
-dat
+imag
 e);%0A    
@@ -3225,24 +3225,200 @@
 icle_title);
+%0A            this.article_date = (TextView) itemView.findViewById(R.id.article_date);%0A            this.article_excerpt = (TextView) itemView.findViewById(R.id.article_excerpt);
 %0A%0A          

Use CardView in ArticleRecyclerViewAdapter