package com.example.profbola.bakingtime.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.profbola.bakingtime.R;
import com.example.profbola.bakingtime.models.Ingredient;
import com.example.profbola.bakingtime.utils.IngredientAdapter;

/**
 * Created by prof.BOLA on 7/1/2017.
 */

public class IngredientsFragment extends Fragment {

    private RecyclerView mIngredientListing;
    private IngredientAdapter mAdapter;
    private Ingredient[] mIngredients;

    public static final String INGREDIENT_KEY = "ingredients_key";

    public IngredientsFragment() {
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if (savedInstanceState != null) {
            mIngredients = (Ingredient[]) savedInstanceState.getParcelableArray(INGREDIENT_KEY);
        }
        View view = inflater.inflate(R.layout.fragment_ingredients_listing, container, false);

        mIngredientListing = (RecyclerView) view.findViewById(R.id.ingredients_listing);
        setUpIngredientView();

        return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putParcelableArray(INGREDIENT_KEY, mIngredients);
    }

    private void setUpIngredientView() {
        mAdapter = new IngredientAdapter(getContext(), mIngredients);
        mIngredientListing.setAdapter(mAdapter);
        mIngredientListing.setLayoutManager(new LinearLayoutManager(getContext()));
        mIngredientListing.setHasFixedSize(true);
//        mAdapter.swapIngredients(mIngredients);
    }

    public void addData(Ingredient[] ingredients) {
        mIngredients = ingredients;
    }
}

@@ -38,16 +38,48 @@
 me.ui;%0A%0A
+import android.content.Context;%0A
 import a
@@ -769,21 +769,22 @@
 ;%0A%0A    p
-ublic
+rivate
  static 
@@ -833,16 +833,159 @@
 _key%22;%0A%0A
+    OnIngredientSelected mCallback;%0A%0A    public interface OnIngredientSelected %7B%0A        void ingredientClicked(Ingredient ingredient);%0A    %7D%0A%0A
     publ
@@ -1833,24 +1833,369 @@
 ts);%0A    %7D%0A%0A
+    @Override%0A    public void onAttach(Context context) %7B%0A        super.onAttach(context);%0A%0A        try %7B%0A            mCallback = (OnIngredientSelected) context;%0A        %7D catch (ClassCastException e) %7B%0A            throw new ClassCastException(context.toString()%0A                    + %22 must implement OnIngredientSelected%22);%0A        %7D%0A    %7D%0A%0A%0A%0A
     private 
@@ -2278,17 +2278,19 @@
 text(), 
-m
+(On
 Ingredie
@@ -2287,25 +2287,46 @@
 OnIngredient
-s
+Selected) getContext()
 );%0A        m
@@ -2503,10 +2503,8 @@
 e);%0A
-//
     

Add OnIngredientSelected interface