/// <summary>
        /// Handles the actions when an item of the context menu is clicked
        /// </summary>
        /// <param name="sender">the item</param>
        /// <param name="e">the event args</param>
        void OnContextMenuItemClick(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            switch (e.Item.ItemId)
            {
            case Resource.Id.menu_deleteItem:
                if (ViewModel.Ingredients[selectedItem].CanDelete)
                {
                    AlertDialog.Builder confirmAlert = new AlertDialog.Builder(this.Activity);
                    confirmAlert.SetTitle(ViewModel.Ingredients[selectedItem].Name);
                    confirmAlert.SetMessage(GetString(Resource.String.ingredient_confirmDelete));
                    confirmAlert.SetPositiveButton(GetString(Resource.String.yes), (senderFromAlert, args) =>
                    {
                        ViewModel.DeleteIngredientsCommand.Execute(ViewModel.Ingredients[selectedItem]);
                        adapter.NotifyItemRemoved(selectedItem);
                    });
                    Dialog dialog = confirmAlert.Create();
                    dialog.Show();
                    Utils.ForceRefreshLayout(refresher, recyclerView);
                }
                else
                {
                    Toast.MakeText(this.Context, Resource.String.cantDelete_toast, ToastLength.Long).Show();
                }
                break;

            case Resource.Id.menu_editItem:
                Intent intent = new Intent(Activity, typeof(AddIngredientsActivity));
                intent.PutExtra("ingredient", Newtonsoft.Json.JsonConvert.SerializeObject(ViewModel.Ingredients[selectedItem]));
                Activity.StartActivity(intent);
                Utils.ForceRefreshLayout(refresher, recyclerView);
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Handles the actions when an item of the context menu is clicked
        /// </summary>
        /// <param name="sender">the item</param>
        /// <param name="e">the event args</param>
        void OnContextMenuItemClick(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            switch (e.Item.ItemId)
            {
            case Resource.Id.menu_deleteItem:
                if (ViewModel.Recipes[selectedItem].CanDelete)
                {
                    AlertDialog.Builder confirmAlert = new AlertDialog.Builder(this.Activity);
                    confirmAlert.SetTitle(ViewModel.Recipes[selectedItem].Name);
                    confirmAlert.SetMessage(GetString(Resource.String.recipe_confirmDelete));
                    confirmAlert.SetPositiveButton(GetString(Resource.String.yes), (senderFromAlert, args) =>
                    {
                        List <Ingredient> ingList        = ItemParser.IdCSVToIngredientList(ViewModel.Recipes[selectedItem].Ingredients, BrowseIngredientFragment.ViewModel);
                        ingList.ForEach(i => i.CanDelete = true);
                        ViewModel.DeleteRecipesCommand.Execute(ViewModel.Recipes[selectedItem]);
                        adapter.NotifyItemRemoved(selectedItem);
                    });
                    Dialog dialog = confirmAlert.Create();
                    dialog.Show();
                    Utils.ForceRefreshLayout(refresher, recyclerView);
                }
                else
                {
                    Toast.MakeText(this.Context, Resource.String.recipe_cantDelete_toast, ToastLength.Long).Show();
                }
                break;

            case Resource.Id.menu_editItem:
                Intent intent = new Intent(Activity, typeof(AddRecipeActivity));
                intent.PutExtra("recipe", Newtonsoft.Json.JsonConvert.SerializeObject(ViewModel.Recipes[selectedItem]));
                Activity.StartActivity(intent);
                break;

            case Resource.Id.menu_addCalendar:
                buildDateAlert(ViewModel.Recipes[selectedItem]);
                break;
            }
            Utils.ForceRefreshLayout(refresher, recyclerView);
        }