@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); int selectedItem = args.getInt(RecipesListFragment.SELECTED_ITEM_KEY); this.isSavedList = args.getBoolean(RecipesMainActivity.NAVIGATE_TO_SAVED_RECIPES_KEY); RecipeViewerController controller = RecipeViewerController.Instance(); List<Recipe> recipes = controller.getRecipes(); this.selectedRecipe = recipes.get(selectedItem); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); RecipeViewerController controller = RecipeViewerController.Instance(); switch (id) { case R.id.action_save: ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "Save!", "Saving...", true); RecipeViewerDatabase database = new RecipeViewerDatabase(this.getActivity()); database.open(); database.addRecipe(this.selectedRecipe, this.getActivity()); database.close(); progressDialog.cancel(); Toast.makeText(getActivity(), "Saved!", Toast.LENGTH_SHORT).show(); return true; } return super.onOptionsItemSelected(item); }
@Override protected List<Ingredient> doInBackground(Void... params) { RecipeViewerController controller = RecipeViewerController.Instance(); return controller.getIngredientsForRecipeWithId(selectedRecipe.getId()); }