|
|
|
@ -8,24 +8,26 @@ namespace ShoopNCook.Pages;
|
|
|
|
|
|
|
|
|
|
public partial class RecipePage : ContentPage
|
|
|
|
|
{
|
|
|
|
|
private readonly IAccountRecipesPreferences preferences;
|
|
|
|
|
private readonly IUserNotifier notifier;
|
|
|
|
|
|
|
|
|
|
public Recipe Recipe { get; init; }
|
|
|
|
|
|
|
|
|
|
private uint note;
|
|
|
|
|
private bool isFavorite;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IAccountRecipesPreferences preferences;
|
|
|
|
|
private IUserNotifier notifier;
|
|
|
|
|
private RecipeInfo info;
|
|
|
|
|
|
|
|
|
|
public ICommand StarCommand => new Command<string>(count => SetNote(uint.Parse(count)));
|
|
|
|
|
|
|
|
|
|
public RecipePage(Recipe recipe, IUserNotifier notifier, IAccountRecipesPreferences preferences, uint amount)
|
|
|
|
|
{
|
|
|
|
|
Recipe = recipe;
|
|
|
|
|
BindingContext = this;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
this.preferences = preferences;
|
|
|
|
|
this.notifier = notifier;
|
|
|
|
|
this.info = recipe.Info;
|
|
|
|
|
|
|
|
|
|
RecipeRate rate = preferences.GetRate(recipe.Info);
|
|
|
|
|
|
|
|
|
@ -35,15 +37,10 @@ public partial class RecipePage : ContentPage
|
|
|
|
|
SetFavorite(isFavorite);
|
|
|
|
|
SetNote(note);
|
|
|
|
|
|
|
|
|
|
RecipeInfo info = recipe.Info;
|
|
|
|
|
|
|
|
|
|
Counter.Count = amount;
|
|
|
|
|
CookTime.Text = info.CookTimeMins.ToString();
|
|
|
|
|
Energy.Text = info.CalPerPers.ToString() + " cal/pers";
|
|
|
|
|
RecipeName.Text = info.Name;
|
|
|
|
|
|
|
|
|
|
if (info.Image != null)
|
|
|
|
|
RecipeImage.Source = ImageSource.FromUri(info.Image);
|
|
|
|
|
if (recipe.Info.Image != null)
|
|
|
|
|
RecipeImage.Source = ImageSource.FromUri(recipe.Info.Image);
|
|
|
|
|
|
|
|
|
|
foreach (Ingredient ingredient in recipe.Ingredients)
|
|
|
|
|
IngredientList.Add(new IngredientView(ingredient));
|
|
|
|
@ -81,20 +78,20 @@ public partial class RecipePage : ContentPage
|
|
|
|
|
{
|
|
|
|
|
SetFavorite(!isFavorite);
|
|
|
|
|
if (isFavorite)
|
|
|
|
|
preferences.AddToFavorites(info);
|
|
|
|
|
preferences.AddToFavorites(Recipe.Info);
|
|
|
|
|
else
|
|
|
|
|
preferences.RemoveFromFavorites(info);
|
|
|
|
|
preferences.RemoveFromFavorites(Recipe.Info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSubmitReviewClicked(object o, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
preferences.SetReviewScore(info, note);
|
|
|
|
|
preferences.SetReviewScore(Recipe.Info, note);
|
|
|
|
|
notifier.Success("Your review has been successfuly submited");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAddToMyListClicked(object o, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!preferences.AddToWeeklyList(info, Counter.Count))
|
|
|
|
|
if (!preferences.AddToWeeklyList(Recipe.Info, Counter.Count))
|
|
|
|
|
notifier.Notice("You already added this recipe to you weekly list!");
|
|
|
|
|
else
|
|
|
|
|
notifier.Success("Recipe added to your weekly list.");
|
|
|
|
|