package quotebook.theoneandonly.com.thequotebook;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;
//import java.util.Random;


public class QuoteAdapter extends RecyclerView.Adapter<QuoteAdapter.QuoteViewHolder> {

    private List<Quote> quoteList;

    public QuoteAdapter(List<Quote> quoteList) {
        this.quoteList = quoteList;
    }


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

    // Create new views (invoked by the layout manager)
    @Override
    public QuoteAdapter.QuoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // create a new view
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.card_layout, parent, false);
        // set the view's size, margins, paddings and layout parameters
//        Random rnd = new Random();
//
//        int r = rnd.nextInt(200);
//        int g = rnd.nextInt(200);
//        int b = rnd.nextInt(200);
//
//        int randomColor = Color.rgb(r, g, b);
//
//        v.setBackgroundColor(randomColor);

        QuoteViewHolder vh = new QuoteViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(QuoteViewHolder quoteViewHolder, int i) {
        Quote q = quoteList.get(i);
        Log.d("QUOTE", "onBindViewHolder: " + q.quote + " " + q.person);
        quoteViewHolder.vQuote.setText(q.quote);
        quoteViewHolder.vPerson.setText(q.person);
    }


    public static class QuoteViewHolder extends RecyclerView.ViewHolder {

        protected TextView vQuote;
        protected TextView vPerson;

        public QuoteViewHolder(View v) {
            super(v);
            vQuote = (TextView) v.findViewById(R.id.quote);
            vPerson = (TextView) v.findViewById(R.id.person);
        }
    }
}
@@ -75,16 +75,59 @@
 .Color;%0A
+import android.support.v7.widget.CardView;%0A
 import a
@@ -161,24 +161,24 @@
 cyclerView;%0A
-
 import andro
@@ -339,18 +339,16 @@
 l.List;%0A
-//
 import j
@@ -364,16 +364,16 @@
 Random;%0A
+
 %0A%0Apublic
@@ -836,37 +836,8 @@
 ) %7B%0A
-        // create a new view%0A
     
@@ -957,328 +957,8 @@
 e);%0A
-        // set the view's size, margins, paddings and layout parameters%0A//        Random rnd = new Random();%0A//%0A//        int r = rnd.nextInt(200);%0A//        int g = rnd.nextInt(200);%0A//        int b = rnd.nextInt(200);%0A//%0A//        int randomColor = Color.rgb(r, g, b);%0A//%0A//        v.setBackgroundColor(randomColor);%0A%0A
     
@@ -1483,16 +1483,50 @@
 vPerson;
+%0A        protected CardView vCard;
 %0A%0A      
@@ -1634,32 +1634,32 @@
 Id(R.id.quote);%0A
-
             vPer
@@ -1696,32 +1696,357 @@
 d(R.id.person);%0A
+            vCard = (CardView) v.findViewById(R.id.card_view);%0A%0A            Random rnd = new Random();%0A%0A            int r = rnd.nextInt(200);%0A            int g = rnd.nextInt(200);%0A            int b = rnd.nextInt(200);%0A%0A            int randomColor = Color.rgb(r, g, b);%0A%0A            vCard.setCardBackgroundColor(randomColor);%0A
         %7D%0A    %7D%0A

Set bg color of each quote card.