Add bindings to Recipe views

pull/26/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent c669811f0d
commit 03d02a606b

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="#FFFFFF" height="48" viewBox="0 96 960 960" width="48"><path d="M220.63 997.043q-32.19 0-54.747-22.556-22.557-22.557-22.557-54.748v-432.5q0-32.624 22.557-55.084 22.557-22.459 54.747-22.459h56.805v-90.739q0-85.228 59.245-144.636 59.246-59.408 143.234-59.408 83.989 0 143.32 59.408 59.331 59.408 59.331 144.636v90.739h56.805q32.289 0 54.916 22.459 22.627 22.46 22.627 55.084v432.5q0 32.191-22.627 54.748-22.627 22.556-54.916 22.556H220.63Zm0-77.304h518.74v-432.5H220.63v432.5Zm259.618-133.522q34.035 0 57.817-23.514 23.783-23.514 23.783-56.534 0-32.082-24.031-57.984-24.03-25.902-58.065-25.902t-57.817 25.947q-23.783 25.947-23.783 58.48 0 32.631 24.031 56.069 24.03 23.438 58.065 23.438ZM354.739 409.696h250.522v-90.684q0-53.389-36.478-89.972-36.478-36.583-88.727-36.583-52.248 0-88.782 36.583-36.535 36.583-36.535 89.972v90.684ZM220.63 919.739v-432.5 432.5Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" fill="#000000" height="48" viewBox="0 96 960 960" width="48"><path d="M220.63 997.043q-32.19 0-54.747-22.556-22.557-22.557-22.557-54.748v-432.5q0-32.624 22.557-55.084 22.557-22.459 54.747-22.459h56.805v-90.739q0-85.228 59.245-144.636 59.246-59.408 143.234-59.408 83.989 0 143.32 59.408 59.331 59.408 59.331 144.636v90.739h56.805q32.289 0 54.916 22.459 22.627 22.46 22.627 55.084v432.5q0 32.191-22.627 54.748-22.627 22.556-54.916 22.556H220.63Zm0-77.304h518.74v-432.5H220.63v432.5Zm259.618-133.522q34.035 0 57.817-23.514 23.783-23.514 23.783-56.534 0-32.082-24.031-57.984-24.03-25.902-58.065-25.902t-57.817 25.947q-23.783 25.947-23.783 58.48 0 32.631 24.031 56.069 24.03 23.438 58.065 23.438ZM354.739 409.696h250.522v-90.684q0-53.389-36.478-89.972-36.478-36.583-88.727-36.583-52.248 0-88.782 36.583-36.535 36.583-36.535 89.972v90.684ZM220.63 919.739v-432.5 432.5Z"/></svg>

Before

Width:  |  Height:  |  Size: 911 B

After

Width:  |  Height:  |  Size: 911 B

@ -1 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="#FFFFFF" height="48" viewBox="0 96 960 960" width="48"><path d="M479.825 856Q467 856 458.5 847.375T450 826V606H230q-12.75 0-21.375-8.675-8.625-8.676-8.625-21.5 0-12.825 8.625-21.325T230 546h220V326q0-12.75 8.675-21.375 8.676-8.625 21.5-8.625 12.825 0 21.325 8.625T510 326v220h220q12.75 0 21.375 8.675 8.625 8.676 8.625 21.5 0 12.825-8.625 21.325T730 606H510v220q0 12.75-8.675 21.375-8.676 8.625-21.5 8.625Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" fill="#FFFFFF" height="48" viewBox="0 96 960 960" width="48">
<path d="M479.825 856Q467 856 458.5 847.375T450 826V606H230q-12.75 0-21.375-8.675-8.625-8.676-8.625-21.5 0-12.825 8.625-21.325T230 546h220V326q0-12.75 8.675-21.375 8.676-8.625 21.5-8.625 12.825 0 21.325 8.625T510 326v220h220q12.75 0 21.375 8.675 8.625 8.676 8.625 21.5 0 12.825-8.625 21.325T730 606H510v220q0 12.75-8.675 21.375-8.676 8.625-21.5 8.625Z"/>
</svg>

Before

Width:  |  Height:  |  Size: 461 B

After

Width:  |  Height:  |  Size: 464 B

@ -77,6 +77,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MauiXaml Update="Views\IngredientView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ProfilePage.xaml"> <MauiXaml Update="Views\ProfilePage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Views.IngredientView"
x:Name="Ingredient">
<HorizontalStackLayout
Spacing="2">
<Label
Text="•"
Style="{StaticResource Small}"/>
<Label
Text="{Binding Name, Source={x:Reference Ingredient}}"
Style="{StaticResource Small}"/>
<Label
Text="{Binding Quantity, Source={x:Reference Ingredient}}"
Style="{StaticResource Small}"/>
<Label
Text="{Binding Unit, Source={x:Reference Ingredient}}"
Style="{StaticResource Small}"/>
</HorizontalStackLayout>
</ContentView>

@ -0,0 +1,41 @@
namespace ShoopNCook.Views;
public partial class IngredientView : ContentView
{
public static readonly BindableProperty NameProperty =
BindableProperty.Create(nameof(Name), typeof(string), typeof(IngredientView), default(string));
public static readonly BindableProperty QuantityProperty =
BindableProperty.Create(nameof(Quantity), typeof(float), typeof(IngredientView), default(float));
public static readonly BindableProperty UnitProperty =
BindableProperty.Create(nameof(Unit), typeof(string), typeof(IngredientView), default(string));
public string Name
{
get => (string)GetValue(NameProperty);
set => SetValue(NameProperty, value);
}
public float Quantity
{
get => (float)GetValue(QuantityProperty);
set => SetValue(QuantityProperty, value);
}
public string Unit
{
get => (string)GetValue(UnitProperty);
set => SetValue(UnitProperty, value);
}
public IngredientView(string name, float quantity, string unit)
{
InitializeComponent();
Name = name;
Quantity = quantity;
Unit = unit;
}
}

@ -25,12 +25,14 @@
Source="arrow_back.svg"/> Source="arrow_back.svg"/>
<Label <Label
Style="{StaticResource h1}" Style="{StaticResource h1}"
x:Name="RecipeName"
Text="Recipe name"/> Text="Recipe name"/>
<ImageButton <ImageButton
x:Name="Favorite"
Source="earth_off.svg" Source="earth_off.svg"
Margin="0, 0, 5, 0" Margin="0, 0, 5, 0"
/> Clicked="OnFavorite"/>
</FlexLayout> </FlexLayout>
<!--Recipe image--> <!--Recipe image-->
@ -50,50 +52,52 @@
<VerticalStackLayout <VerticalStackLayout
Grid.Row="2" Grid.Row="2"
Padding="30, 0, 30, 0"> Padding="30, 0, 30, 0">
<Label
Style="{StaticResource h2}"
Text="Ingredients"/>
<VerticalStackLayout>
<Label
Style="{StaticResource Small}"
Text="• Ingredient 1 45 kg"/>
<Label <!--Cook time-->
Style="{StaticResource Small}" <VerticalStackLayout>
Text="• Ingredient 1 32 g"/> <HorizontalStackLayout>
<Label
<Label Style="{StaticResource Small}"
Style="{StaticResource Small}" Text="Cooking time: "/>
Text="• Ingredient 1 101 kt"/> <Label
Style="{StaticResource Small}"
x:Name="CookTime"/>
<Label
Style="{StaticResource Small}"
Text=" min"/>
</HorizontalStackLayout>
<!--Energy-->
<HorizontalStackLayout>
<Label
Style="{StaticResource Small}"
Text="Energy: "/>
<Label
Style="{StaticResource Small}"
x:Name="Energy"/>
<Label
Style="{StaticResource Small}"
Text="/pers"/>
</HorizontalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout> <!--Ingredient list-->
<Label <Label
Style="{StaticResource Small}" Style="{StaticResource h2}"
Text="Cooking time: %Cook_Time%"/> Text="Ingredients"/>
<Label <VerticalStackLayout
Style="{StaticResource Small}" x:Name="IngredientList"/>
Text="Energy input: %Nb_Cal%/pers"/>
</VerticalStackLayout>
<!--Step list-->
<Label <Label
Style="{StaticResource h2}" Style="{StaticResource h2}"
Text="Preparation steps"/> Text="Preparation steps"/>
<VerticalStackLayout> <VerticalStackLayout
<Label x:Name="StepList"/>
Style="{StaticResource Small}"
Text="Step 1 : Frist step"/>
<Label
Style="{StaticResource Small}"
Text="Step 2 : Second step"/>
<Label
Style="{StaticResource Small}"
Text="Step 3 : Third step"/>
</VerticalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>
</Grid> </Grid>
</ScrollView> </ScrollView>
@ -114,35 +118,47 @@
Stroke="Transparent" Stroke="Transparent"
StrokeShape="RoundRectangle 100" StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}"> BackgroundColor="{StaticResource Selected}">
<Image <ImageButton
Source="minus.svg" Source="minus.svg"
WidthRequest="40" WidthRequest="40"
HeightRequest="40"/> HeightRequest="40"
Clicked="OnMinus"/>
</Border> </Border>
<Label <HorizontalStackLayout
Grid.Column="1" Grid.Column="1">
Text="%N% pers" <Label
Margin="10, 0, 10, 0" x:Name="NbPersLabel"
TextColor="{StaticResource TextColorPrimary}" Text="1"
VerticalTextAlignment="Center" Margin="10, 0, 0, 0"
FontFamily="PoppinsMedium"/> TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>
<Label
Text=" pers"
Margin="0, 0, 10, 0"
TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>
</HorizontalStackLayout>
<Border <Border
Grid.Column="2" Grid.Column="2"
Stroke="Transparent" Stroke="Transparent"
StrokeShape="RoundRectangle 100" StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}"> BackgroundColor="{StaticResource Selected}">
<Image <ImageButton
Source="add.svg" Source="add.svg"
WidthRequest="40" WidthRequest="40"
HeightRequest="40"/> HeightRequest="40"
Clicked="OnPlus"/>
</Border> </Border>
</Grid> </Grid>
<Button <Button
Grid.Column="1" Grid.Column="1"
Text="Most Recent" Text="Add to list"
Style="{StaticResource UserButton}" Style="{StaticResource UserButton}"
TextColor="White" TextColor="White"
BackgroundColor="Gray"> BackgroundColor="Gray">

@ -1,9 +1,87 @@
using Microsoft.Maui.Controls;
namespace ShoopNCook.Views; namespace ShoopNCook.Views;
public partial class RecipePage : ContentPage public partial class RecipePage : ContentPage
{ {
public RecipePage()
{ private uint nbPers;
InitializeComponent(); private bool isFavorite;
}
public RecipePage() :
this("Recipe Sample", 32, 250,
true, 1,
new List<IngredientView> {
new IngredientView("Chocolate", 25, "g"),
new IngredientView("Flour", 250, "g"),
new IngredientView("Sugar", 0.5F, "kg")
},
new List<string> { "This is the first preparation step", "add to furnace and wait", "Enjoy !" }
)
{}
public RecipePage(
string name,
uint cookTime,
uint energy,
bool isFavorite,
uint nbPers,
List<IngredientView> ingredients,
List<string> steps
)
{
InitializeComponent();
this.nbPers = nbPers;
this.isFavorite = isFavorite;
CookTime.Text = cookTime.ToString();
Energy.Text = energy.ToString();
RecipeName.Text = name;
foreach (IngredientView iv in ingredients)
IngredientList.Add(iv);
var styles = Application.Current.Resources.MergedDictionaries.ElementAt(1);
int count = 0;
foreach (string step in steps) {
Label label = new Label();
label.Style = (Style)styles["Small"];
label.Text = "Step " + ++count + ": " + step;
StepList.Add(label);
}
}
private void OnFavorite(object o, EventArgs e)
{
isFavorite = !isFavorite;
if (isFavorite)
{
Favorite.Source = ImageSource.FromFile("earth_on.svg");
}
else
{
Favorite.Source = ImageSource.FromFile("earth_off.svg");
}
}
private void OnPlus(object o, EventArgs e)
{
UpdateCounter(++nbPers);
}
private void OnMinus(object o, EventArgs e)
{
if (nbPers <= 1)
return;
nbPers--;
UpdateCounter(nbPers);
}
private void UpdateCounter(uint counter)
{
NbPersLabel.Text = counter.ToString();
}
} }
Loading…
Cancel
Save