add simple bindings in RecipePage
continuous-integration/drone/push Build is passing Details

master
Maxime BATISTA 2 years ago
parent 211f313bce
commit 00056c4aa2

@ -30,8 +30,7 @@
<Label
Style="{StaticResource h1}"
x:Name="RecipeName"
Text="Recipe name"/>
Text="{Binding Recipe.Info.Name}"/>
<ImageButton
x:Name="Favorite"
@ -61,38 +60,22 @@
<!--Cook time-->
<VerticalStackLayout>
<HorizontalStackLayout>
<Label
Style="{StaticResource Small}"
Text="Cooking time: "/>
<Label
Style="{StaticResource Small}"
x:Name="CookTime"/>
<Label
Style="{StaticResource Small}"
Text=" min"/>
</HorizontalStackLayout>
<Label
Style="{StaticResource Small}"
Text="{Binding Recipe.Info.CookTimeMins, StringFormat='Cooking time: {0} mins'}"/>
<!--Energy-->
<HorizontalStackLayout>
<Label
Style="{StaticResource Small}"
Text="Energy: "/>
<Label
Style="{StaticResource Small}"
x:Name="Energy"/>
<Label
Style="{StaticResource Small}"
Text="/pers"/>
</HorizontalStackLayout>
<Label
Style="{StaticResource Small}"
Text="{Binding Recipe.Info.CalPerPers, StringFormat='Energy: {0}/pers'}"/>
</VerticalStackLayout>
<!--Ingredient list-->
<Label
Style="{StaticResource h2}"
Text="Ingredients"/>
<!--Ingredient list-->
<VerticalStackLayout
x:Name="IngredientList"/>

@ -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.");

Loading…
Cancel
Save