private async void RecipeCards_SelectionChanged(object sender, SelectionChangedEventArgs e) { RecipeItems selectedItem = (e.CurrentSelection.FirstOrDefault() as RecipeItems); SingleRecipeData selected = new SingleRecipeData(selectedItem); selected.RecipeImage = await FirebaseHelper.GetImage(selectedItem.RecipeName); await Navigation.PushModalAsync(new RecipeTabbedViewPage(selected)); selectedItem = null; }
public void UpdateValues() { thisRecipe = (BindingContext as SingleRecipeData); thisRecipe.UpdateNutrition(); // Update Views thisTabbedPage.UpdateViews(); ServingView.Text = thisRecipe.NutritionValues.Servings.ToString() + " Servings per Recipe"; CaloriesView.Text = "Calories per Serving : " + thisRecipe.NutritionValues.CaloriesPerServing.ToString(); WeightView.Text = "Approx. Weight per Serving : " + thisRecipe.NutritionValues.WeightPerServing.ToString() + " grams"; TotalWeightView.Text = "Approx. Total Weight of Recipe : " + thisRecipe.NutritionValues.TotalWeight.ToString() + " grams"; }
private void RatingStarButton_Clicked(object sender, EventArgs e) { if (RatingFrame.IsVisible == true && RatingEntry.Text != string.Empty) { thisRecipe = (BindingContext as SingleRecipeData); thisRecipe.RatingStars = Convert.ToDouble(RatingEntry.Text); FirebaseHelper.UpdateRating(thisRecipe); RatingEntry.Placeholder = RatingEntry.Text; RatingEntry.Text = string.Empty; thisTabbedPage.UpdateViews(); } RatingFrame.IsVisible = !RatingFrame.IsVisible; }
private void ServingSizeButton_Clicked(object sender, EventArgs e) { if (ServingFrame.IsVisible == true && ServingEntry.Text != string.Empty && Convert.ToInt32(ServingEntry.Text) != 0) { thisRecipe = (BindingContext as SingleRecipeData); thisRecipe.NutritionValues.Servings = Convert.ToInt32(ServingEntry.Text); FirebaseHelper.UpdateNutrition(thisRecipe); ServingEntry.Placeholder = ServingEntry.Text; ServingEntry.Text = string.Empty; UpdateValues(); } ServingFrame.IsVisible = !ServingFrame.IsVisible; }
public RecipeTabbedViewPage(SingleRecipeData objectInstance) { Shell.SetTabBarIsVisible(this, false); InitializeComponent(); thisRecipe = objectInstance; BindingContext = thisRecipe; recipeDetails.BindingContext = thisRecipe; recipeDetails.thisNutrition = recipeNutrition; recipeInstructions.BindingContext = thisRecipe; recipeInstructions.preSavedRecipe = thisRecipe; recipeInstructions.InitializeInstructions(); recipeNutrition.BindingContext = thisRecipe; recipeNutrition.thisTabbedPage = this; }
private async void ImageButton_Clicked(object sender, EventArgs e) { RecipeItems newRecipe = new RecipeItems(); newRecipe.RecipeImage = await FirebaseHelper.GetDefaultImage(); newRecipe.RecipeName = "New Recipe"; newRecipe.RecipeRating = 3; newRecipe.Instructions.Add(new InstructionItem(1, null)); // End example entry changes await FirebaseHelper.AddRecipe(newRecipe); SingleRecipeData selected = new SingleRecipeData(newRecipe); await Navigation.PushModalAsync(new RecipeTabbedViewPage(selected)); }
private void Entry_TextChanged(object sender, TextChangedEventArgs e) { if (calorieCalculator.TextColor == Color.White) { calorieEntry.PlaceholderColor = Color.Accent; calorieCalculator.TextColor = Color.Accent; } if (calorieEntry.Text != string.Empty) { thisRecipe = (BindingContext as SingleRecipeData); double caloriesPerGram = (thisRecipe.NutritionValues.TotalCalories / thisRecipe.NutritionValues.TotalWeight); calorieCalculator.Text = (caloriesPerGram * Convert.ToDouble(calorieEntry.Text)).ToString() + " cal."; } // if (calorieCalculator.TextColor != Color.White) // calorieCalculator.Text = "0 cal."; }
private void newItemEntry_Completed() { if (AddButton.IsVisible) { NewItemEntry.IsVisible = false; thisRecipe = (BindingContext as SingleRecipeData); RecipeItems currentRecipe = new RecipeItems(); currentRecipe.RecipeName = thisRecipe.RecipeTitle; currentRecipe.IngredientsList = thisRecipe.Items.ToList(); thisRecipe.Items.Add(singleItem); thisNutrition.UpdateValues(); FirebaseHelper.UpdateRecipeAdd(currentRecipe, singleItem); ResetNewItemFrame(); } else { SaveEdit(); } }
private async void TitleEntry_Completed(object sender, EventArgs e) { var recipeNames = await FirebaseHelper.GetRecipeNames(); if (recipeNames.Contains(TitleEntry.Text)) { await App.Current.MainPage.DisplayAlert("Alert", "This name already exists, please enter a different name.", "Cancel"); RecipeTitleLabel.Text = null; } else { thisRecipe = (BindingContext as SingleRecipeData); await FirebaseHelper.UpdateRecipeTitle(TitleEntry.Text, thisRecipe); RecipeTitleLabel.Text = TitleEntry.Text; TitleEntry.IsEnabled = false; TitleEntry.IsVisible = false; UpdateTitleButton.IsEnabled = true; thisRecipe.RecipeTitle = TitleEntry.Text; } }
private async void DeleteButton_Clicked(object sender, EventArgs e) { bool answer = await App.Current.MainPage.DisplayAlert("Notification", "Are you sure you wish to delete this recipe?", "Delete", "Cancel"); thisRecipe = (BindingContext as SingleRecipeData); if (answer == true) { if (await FirebaseHelper.DeleteRecipe(thisRecipe)) { await FirebaseHelper.DeleteImage(thisRecipe.RecipeTitle); thisTabbedPage.GoToRecipe(); } else { Debug.WriteLine("Delete Failed"); } } else if (answer == false) { return; } }
private void SaveEdit() { //todo Edit in firebase thisRecipe = (BindingContext as SingleRecipeData); for (int i = 0; i < thisRecipe.Items.Count; i++) { if (selectedItem == thisRecipe.Items.ElementAt(i)) { thisRecipe.Items.ElementAt(i).Equals(singleItem); thisNutrition.UpdateValues(); FirebaseHelper.UpdateRecipeEdit(thisRecipe, selectedItem, singleItem); IngredientsList.SelectedItem = null; previousItem = null; selectedItem = null; EditButton.PlayFrameSegment(44, 63); EditButton.PlayFrameSegment(63, 2); ResetNewItemFrame(); EditButtonFrame.IsVisible = false; AddButton.IsVisible = true; AddButton.PlayFrameSegment(45, 125); AddButton.PlayFrameSegment(0, 25); CurrentFrame = 25; } } }