package com.example.profbola.bakingtime.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.example.profbola.bakingtime.R;
import com.example.profbola.bakingtime.models.Recipe;
import com.example.profbola.bakingtime.utils.RecipePagerAdapter;

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

public class RecipeDetailActivity extends AppCompatActivity {

    private static final String INGREDIENT_TAB = "ingredients";
    private static final String STEP_TAB = "steps";

    private Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;

    private IngredientsFragment mIngredientsFragment;
    private StepsFragment mStepsFragment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recipe_detail_activity);

        if (savedInstanceState == null) {
            Recipe recipe = (Recipe) getIntent().getExtras().get("NAME");
            mIngredientsFragment = new IngredientsFragment();
            mIngredientsFragment.addData(recipe.ingredients);

            mStepsFragment = new StepsFragment();
            mStepsFragment.addData(recipe.steps);
        }

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        viewPager = (ViewPager) findViewById(R.id.viewPager);
        setUpViewPager(mIngredientsFragment, mStepsFragment);

        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager, true);

    }

    private void setUpViewPager(IngredientsFragment ingredientsFragment, StepsFragment stepsFragment) {
        RecipePagerAdapter adapter = new RecipePagerAdapter(getSupportFragmentManager());
        //TODO: Add the fragments

        adapter.addFragment(ingredientsFragment, INGREDIENT_TAB);
        adapter.addFragment(stepsFragment, STEP_TAB);

        viewPager.setAdapter(adapter);
    }

}

@@ -57,15 +57,76 @@
 oid.
-os.Bund
+content.Intent;%0Aimport android.os.Bundle;%0Aimport android.os.Parcelab
 le;%0A
@@ -393,16 +393,74 @@
 time.R;%0A
+import com.example.profbola.bakingtime.models.Ingredient;%0A
 import c
@@ -505,16 +505,68 @@
 Recipe;%0A
+import com.example.profbola.bakingtime.models.Step;%0A
 import c
@@ -729,16 +729,113 @@
 ctivity 
+implements%0A        IngredientsFragment.OnIngredientSelected, StepsFragment.OnVideoPlayerSelected 
 %7B%0A%0A    p
@@ -1142,190 +1142,759 @@
 nt;%0A
-%0A    @Override%0A    protected void onCreate(@Nullable Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        setContentView(R.layout.recipe_detail_activity);
+    private FullDetailsFragment mFullDetailsFragment;%0A%0A    private boolean mTwoPane;%0A%0A    public static final String INGREDIENTS_KEY = %22ingredient%22;%0A    public static final String STEP_KEY = %22step%22;%0A%0A    @Override%0A    protected void onCreate(@Nullable Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        setContentView(R.layout.recipe_detail_activity);%0A%0A        if (findViewById(R.id.recipe_full_view) != null) %7B%0A            mTwoPane = true;%0A%0A            mFullDetailsFragment = new FullDetailsFragment();%0A%0A            getSupportFragmentManager().beginTransaction()%0A                    .add(R.id.recipe_full_view, mFullDetailsFragment)%0A                    .commit();%0A        %7D else %7B%0A            mTwoPane = false;%0A        %7D
 %0A%0A  
@@ -3043,10 +3043,916 @@
 %0A    %7D%0A%0A
+    @Override%0A    public void ingredientClicked(Ingredient ingredient) %7B%0A        routeToFragmentOrActivity(ingredient, INGREDIENTS_KEY);%0A    %7D%0A%0A    @Override%0A    public void videoClicked(Step step) %7B%0A        routeToFragmentOrActivity(step, STEP_KEY);%0A    %7D%0A%0A    private void routeToFragmentOrActivity(Parcelable object, String type) %7B%0A        if (mTwoPane) %7B%0A            FullDetailsFragment newFragment = new FullDetailsFragment();%0A            Bundle bundle = new Bundle();%0A            bundle.putParcelable(type, object);%0A            newFragment.setArguments(bundle);%0A            getSupportFragmentManager().beginTransaction()%0A                    .replace(R.id.recipe_full_view, newFragment)%0A                    .commit();%0A        %7D else %7B%0A            Intent intent = new Intent(this, FullDetailActivity.class);%0A            intent.putExtra(type, object);%0A            startActivity(intent);%0A        %7D%0A    %7D%0A
 %7D%0A

Implement OnVideoPlayerSelected and OnIngredientSelected