/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.android.recyclerview;

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

/**
 * We couldn't come up with a good name for this class. Then, we realized
 * that this lesson is about RecyclerView.
 *
 * RecyclerView... Recycling... Saving the planet? Being green? Anyone?
 * #crickets
 *
 * Avoid unnecessary garbage collection by using RecyclerView and ViewHolders.
 *
 * If you don't like our puns, we named this Adapter GreenAdapter because its
 * contents are green.
 */
// completed (4) From GreenAdapter, extend RecyclerView.Adapter<NumberViewHolder>
public class GreenAdapter extends RecyclerView.Adapter<GreenAdapter.NumberViewHolder>{

    // completed (1) Add a private int variable called mNumberItems
    private int mNumberItems;

    // completed (2) Create a constructor for GreenAdapter that accepts an int as a parameter for numberOfItems
    // completed (3) Store the numberOfItems parameter in mNumberItems
    public void GreenAdapter(int numberOfItems){

        mNumberItems = numberOfItems;
    }

    @Override
    public NumberViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(NumberViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return 0;
    }

    mNumberItems =

    // TODO (5) Override the onCreateViewHolder method
    // TODO (6) Create and return a new NumberViewHolder within this method

    // TODO (7) Override onBindViewHolder
    // TODO (8) Within onBindViewHolder, call holder.bind and pass in the position

    // TODO (9) Override getItemCount and return the number of items to display

    /**
     * Cache of the children views for a list item.
     */
    class NumberViewHolder extends RecyclerView.ViewHolder {

        // Will display the position in the list, ie 0 through getItemCount() - 1
        TextView listItemNumberView;

        /**
         * Constructor for our ViewHolder. Within this constructor, we get a reference to our
         * TextViews and set an onClickListener to listen for clicks. Those will be handled in the
         * onClick method below.
         * @param itemView The View that you inflated in
         *                 {@link GreenAdapter#onCreateViewHolder(ViewGroup, int)}
         */
        public NumberViewHolder(View itemView) {
            super(itemView);

            listItemNumberView = (TextView) itemView.findViewById(R.id.tv_item_number);
        }

        /**
         * A method we wrote for convenience. This method will take an integer as input and
         * use that integer to display the appropriate text within a list item.
         * @param listIndex Position of the item in the list
         */
        void bind(int listIndex) {
            listItemNumberView.setText(String.valueOf(listIndex));
        }
    }
}

@@ -675,38 +675,106 @@
 oid.
-support.v7.widget.RecyclerView
+content.Context;%0Aimport android.support.v7.widget.RecyclerView;%0Aimport android.view.LayoutInflater
 ;%0Aim
@@ -1815,211 +1815,953 @@
     
-@Override%0A    public NumberViewHolder onCreateViewHolder(ViewGroup parent, int viewType) %7B%0A        return null;%0A    %7D%0A%0A    @Override%0A    public void onBindViewHolder(NumberViewHolder holder, int position
+// completed (5) Override the onCreateViewHolder method%0A    // completed (6) Create and return a new NumberViewHolder within this method%0A    @Override%0A    /**%0A     *%0A     * This gets called when each new ViewHolder is created. This happens when the RecyclerView%0A     * is laid out. Enough ViewHolders will be created to fill the screen and allow for scrolling.%0A     *%0A     * @param viewGroup The ViewGroup that these ViewHolders are contained within.%0A     * @param viewType  If your RecyclerView has more than one type of item (which ours doesn't) you%0A     *                  can use this viewType integer to provide a different layout. See%0A     *                  %7B@link android.support.v7.widget.RecyclerView.Adapter#getItemViewType(int)%7D%0A     *                  for more details.%0A     * @return A new NumberViewHolder that holds the View for each list item%0A     */%0A    public NumberViewHolder onCreateViewHolder(ViewGroup parent, int viewType
 ) %7B%0A
@@ -2769,245 +2769,451 @@
     
-%7D%0A%0A
     
-@Override%0A    public int getItemCount() %7B%0A        return 0
+Context context = parent.getContext();%0A        int layoutIdForListItem = R.layout.number_list_item;%0A        LayoutInflater inflater = LayoutInflater.from(context)
 ;%0A    
-%7D%0A%0A
     
-mNumberItems =%0A%0A    // TODO (5) Override the onCreateViewHolder method%0A    // TODO (6) Create and return a new NumberViewHolder within this method%0A%0A    // TODO
+boolean shouldAttachToParentImmediately = false;%0A%0A        View view = inflater.inflate(layoutIdForListItem, parent, shouldAttachToParentImmediately);%0A%0A        NumberViewHolder viewHolder = new NumberViewHolder(view);%0A        return viewHolder;%0A    %7D%0A%0A    // completed
  (7)
@@ -3246,20 +3246,25 @@
 %0A    // 
-TODO
+completed
  (8) Wit
@@ -3331,88 +3331,301 @@
 ion%0A
-%0A    // TODO (9) Override getItemCount and return the number of items to display
+    @Override%0A    public void onBindViewHolder(NumberViewHolder holder, int position) %7B%0A        holder.bind(position);%0A    %7D%0A%0A    // completed (9) Override getItemCount and return the number of items to display%0A    @Override%0A    public int getItemCount() %7B%0A%0A        return mNumberItems;%0A    %7D%0A
 %0A%0A  

complete TODO 6-9