You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ShopNCook/Views/RecipePage.xaml.cs

89 lines
2.3 KiB

using ShoopNCook.Views;
using System.Windows.Input;
using Models;
namespace ShoopNCook.Pages;
public partial class RecipePage : ContentPage
{
private uint note;
private bool isFavorite;
public ICommand StarCommand => new Command<string>(count => SetNote(uint.Parse(count)));
public RecipePage(Recipe recipe, AccountRecipeRate? rate, uint amount)
{
InitializeComponent();
Counter.Count = amount;
note = rate?.Rate ?? 0;
isFavorite = rate?.IsFavorite ?? false;
SetFavorite(isFavorite);
SetNote(note);
RecipeInfo info = recipe.Info;
CookTime.Text = info.CookTimeMins.ToString();
Energy.Text = info.CalPerPers.ToString() + " cal/pers";
RecipeName.Text = info.Name;
foreach (Ingredient ingredient in recipe.Ingredients)
IngredientList.Add(new IngredientView(ingredient));
//retrieves the app's styles
var styles = Application.Current.Resources.MergedDictionaries.ElementAt(1);
int count = 0;
foreach (PreparationStep step in recipe.Steps) {
//TODO display name of PreparationSteps.
Label label = new Label();
label.Style = (Style)styles["Small"];
label.Text = "Step " + ++count + ": " + step.Description;
StepList.Add(label);
}
}
private void SetNote(uint note)
{
this.note = note;
int i = 1;
foreach (ImageButton img in Stars.Children)
{
if (i <= note)
{
img.Source = ImageSource.FromFile("star_full.svg");
i++;
}
else
{
img.Source = ImageSource.FromFile("star_empty.svg");
}
}
}
private void OnFavorite(object o, EventArgs e)
{
SetFavorite(!isFavorite);
}
private void SetFavorite(bool isFavorite)
{
this.isFavorite = isFavorite;
if (isFavorite)
{
Favorite.Source = ImageSource.FromFile("hearth_on.svg");
}
else
{
Favorite.Source = ImageSource.FromFile("hearth_off.svg");
}
}
private async void OnBackButtonClicked(object sender, EventArgs e)
{
await Navigation.PopAsync();
}
}