package pe.ironbit.android.baking.controller;

import pe.ironbit.android.baking.R;
import pe.ironbit.android.baking.activity.RecipeActivity;
import pe.ironbit.android.baking.event.base.BaseListener;
import pe.ironbit.android.baking.util.ConfigUtil;

public class RecipeController implements BaseListener {
    private boolean isTablet;

    private RecipeActivity activity;

    public RecipeController(RecipeActivity activity) {
        this.activity = activity;
        isTablet = ConfigUtil.isDeviceTablet(activity.getApplicationContext());
    }

    public void executeInitLogic() {
        if (isTablet) {
            activity.createRecipeDetailFragment(R.id.activity_recipe_framelayout_one);
            activity.createRecipeStepFragment(R.id.activity_recipe_framelayout_two, false);
        } else {
            activity.initPhoneView();
            activity.createRecipeDetailFragment(R.id.activity_recipe_framelayout_one);
            activity.createRecipeStepFragment(R.id.activity_recipe_framelayout_one, true);
            if (activity.getIsRecipeStepFragmentActive()) {
                activity.showFragment(activity.FRAGMENT_RECIPE_STEPS_TAG);
                activity.hideFragment(activity.FRAGMENT_RECIPE_DETAIL_TAG);
            } else {
                activity.hideFragment(activity.FRAGMENT_RECIPE_STEPS_TAG);
                activity.showFragment(activity.FRAGMENT_RECIPE_DETAIL_TAG);
            }
        }
    }

    private void executeStepLogic(int index) {
        activity.updateIndexRecipeStepFragment(index);

        if (isTablet == false) {
            activity.setIsRecipeStepFragmentActive(true);
            activity.showFragment(activity.FRAGMENT_RECIPE_STEPS_TAG);
            activity.hideFragment(activity.FRAGMENT_RECIPE_DETAIL_TAG);
        }
    }

    public boolean executeLogicBack() {
        if (activity.getIsRecipeStepFragmentActive()) {
            activity.setIsRecipeStepFragmentActive(false);
            activity.hideFragment(activity.FRAGMENT_RECIPE_STEPS_TAG);
            activity.showFragment(activity.FRAGMENT_RECIPE_DETAIL_TAG);
            return false;
        }
        activity.destroyAllFragments();
        return true;
    }

    @Override
    public void update(Object object) {
        executeStepLogic((int)object);
    }
}

@@ -1107,33 +1107,39 @@
 ty.showFragment(
-a
+RecipeA
 ctivity.FRAGMENT
@@ -1188,33 +1188,39 @@
 ty.hideFragment(
-a
+RecipeA
 ctivity.FRAGMENT
@@ -1291,33 +1291,39 @@
 ty.hideFragment(
-a
+RecipeA
 ctivity.FRAGMENT
@@ -1372,33 +1372,39 @@
 ty.showFragment(
-a
+RecipeA
 ctivity.FRAGMENT
@@ -1570,24 +1570,25 @@
     if (
+!
 isTablet
  == fals
@@ -1583,17 +1583,8 @@
 blet
- == false
 ) %7B%0A
@@ -1667,33 +1667,39 @@
 ty.showFragment(
-a
+RecipeA
 ctivity.FRAGMENT
@@ -1744,33 +1744,39 @@
 ty.hideFragment(
-a
+RecipeA
 ctivity.FRAGMENT
@@ -1994,33 +1994,39 @@
 ty.hideFragment(
-a
+RecipeA
 ctivity.FRAGMENT
@@ -2079,17 +2079,23 @@
 ragment(
-a
+RecipeA
 ctivity.

improve RecipeController