コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
 @Override
 protected List<Ingredient> doInBackground(Void... params) {
   RecipeViewerController controller = RecipeViewerController.Instance();
   return controller.getIngredientsForRecipeWithId(selectedRecipe.getId());
 }