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

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

Loading…
Cancel
Save