add CounterView and fix RecipesPage

pull/34/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent 96c33ccb30
commit 58773d678e

@ -43,5 +43,10 @@
Title="Favorites Page"
ContentTemplate="{DataTemplate pages:FavoritesPage}"
Route="Favorites" />
<ShellContent
Title="MyList Page"
ContentTemplate="{DataTemplate pages:MyListPage}"
Route="MyList" />
</TabBar>
</Shell>

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Pages.MyList"
Title="MyList">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentPage>

@ -1,9 +0,0 @@
namespace ShoopNCook.Pages;
public partial class MyList : ContentPage
{
public MyList()
{
InitializeComponent();
}
}

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Pages.MyListPage"
Title="MyList"
BackgroundColor="{StaticResource BackgroundPrimary}"
xmlns:views="clr-namespace:ShoopNCook.Views">
<Grid
RowDefinitions="Auto, *, Auto">
<!-- Header label and return button -->
<Grid
Grid.Row="0"
Padding="20, 40, 0, 30"
ColumnDefinitions="*"
MaximumHeightRequest="60">
<ImageButton
Grid.Column="0"
HeightRequest="50"
WidthRequest="50"
Source="arrow_back.svg"
HorizontalOptions="Start"/>
<Label
Grid.Column="0"
FontSize="24"
TextColor="{StaticResource TextColorPrimary}"
Text="My Weekly List"
MaximumHeightRequest="60"
FontFamily="PoppinsBold"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Grid>
<!-- Favorite items -->
<ScrollView
Grid.Row="1">
<FlexLayout
JustifyContent="Center"
AlignItems="Start"
AlignContent="Start"
Direction="Row"
Wrap="Wrap">
<views:RecipeView Margin="5" Note="4.5" Title="Spaghetti Bolognese" Subtitle="30 min"/>
<views:RecipeView Margin="5" Note="3" Title="Chickend Curry" Subtitle="45 min"/>
<views:RecipeView Margin="5" Note="0.2" Title="Beef Stroganoff" Subtitle="10 min"/>
<views:RecipeView Margin="5" Note="1.6" Title="Fish And Ships" Subtitle="15 min"/>
<views:RecipeView Margin="5" Note="5" Title="Caesar Salad" Subtitle="20 min"/>
<views:RecipeView Margin="5" Note="3.5" Title="Vegetables" Subtitle="60 min"/>
<views:RecipeView Margin="5" Note="4.6" Title="Guacamole" Subtitle="90 min"/>
<views:RecipeView Margin="5" Note="4" Title="Pad Thai" Subtitle="10 min"/>
<views:RecipeView Margin="5" Note="3" Title="French Toast" Subtitle="5 min"/>
<views:RecipeView Margin="5" Note="2" Title="Margherita Pizza" Subtitle="2 min"/>
</FlexLayout>
</ScrollView>
</Grid>
</ContentPage>

@ -0,0 +1,9 @@
namespace ShoopNCook.Pages;
public partial class MyListPage : ContentPage
{
public MyListPage()
{
InitializeComponent();
}
}

@ -4,6 +4,7 @@
x:Class="ShoopNCook.Pages.RecipePage"
Title="RecipePage"
x:Name="RecipeViewPage"
xmlns:views="clr-namespace:ShoopNCook.Views"
BackgroundColor="{StaticResource BackgroundPrimary}">
<Grid
@ -154,51 +155,10 @@
JustifyContent="SpaceBetween"
AlignItems="Center"
>
<Grid
ColumnDefinitions="*, Auto, *">
<Border
Grid.Column="0"
Stroke="Transparent"
StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}">
<ImageButton
Source="minus.svg"
WidthRequest="40"
HeightRequest="40"
Clicked="OnMinus"/>
</Border>
<HorizontalStackLayout
Grid.Column="1">
<Label
x:Name="NbPersLabel"
Text="1"
Margin="10, 0, 0, 0"
TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>
<Label
Text=" pers"
Margin="0, 0, 10, 0"
TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>
</HorizontalStackLayout>
<Border
Grid.Column="2"
Stroke="Transparent"
StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}">
<ImageButton
Source="plus.svg"
WidthRequest="40"
HeightRequest="40"
Clicked="OnPlus"/>
</Border>
</Grid>
<views:CounterView
x:Name="Counter"
CounterText="pers"
Count="1"/>
<Button
Grid.Column="1"

@ -7,7 +7,6 @@ public partial class RecipePage : ContentPage
{
private uint note;
private uint nbPers;
private bool isFavorite;
public ICommand StarCommand => new Command<string>(count =>
@ -39,7 +38,7 @@ public partial class RecipePage : ContentPage
)
{
InitializeComponent();
SetNbPers(nbPers);
Counter.Count = nbPers;
SetFavorite(isFavorite);
SetNote(note);
@ -97,19 +96,4 @@ public partial class RecipePage : ContentPage
}
}
private void OnPlus(object o, EventArgs e)
{
SetNbPers(nbPers + 1);
}
private void OnMinus(object o, EventArgs e)
{
SetNbPers(nbPers - 1);
}
private void SetNbPers(uint nbPers)
{
this.nbPers = nbPers <= 1 ? 1 : nbPers;
NbPersLabel.Text = this.nbPers.ToString();
}
}

@ -86,6 +86,15 @@
</ItemGroup>
<ItemGroup>
<Compile Update="Pages\MyListPage.xaml.cs">
<DependentUpon>MyListPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<MauiXaml Update="Views\CounterView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\HeadedButton.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
@ -119,6 +128,9 @@
<MauiXaml Update="Views\SearchPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\StoredRecipeView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionShoopNCookHideInfoBar="True" XamarinHotReloadUnhandledDeviceExceptionShoopNCookHideInfoBar="True" /></VisualStudio></ProjectExtensions>

@ -0,0 +1,52 @@
<?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.CounterView"
x:Name="Counter">
<Grid
ColumnDefinitions="*, Auto, *">
<Border
Grid.Column="0"
Stroke="Transparent"
StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}">
<ImageButton
Source="minus.svg"
WidthRequest="40"
HeightRequest="40"
Clicked="OnMinus"/>
</Border>
<HorizontalStackLayout
Grid.Column="1"
Spacing="3"
Margin="10, 0, 10, 0">
<Label
x:Name="CountLabel"
Text="{Binding Count, Source={x:Reference Counter}}"
TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>
<Label
x:Name="CounterLabel"
Text="{Binding CounterText, Source={x:Reference Counter}}"
TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/>
</HorizontalStackLayout>
<Border
Grid.Column="2"
Stroke="Transparent"
StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}">
<ImageButton
Source="plus.svg"
WidthRequest="40"
HeightRequest="40"
Clicked="OnPlus"/>
</Border>
</Grid>
</ContentView>

@ -0,0 +1,51 @@
namespace ShoopNCook.Views;
public partial class CounterView : ContentView
{
private readonly BindableProperty CountProperty =
BindableProperty.Create(nameof(CountLabel), typeof(uint), typeof(CounterView), default(uint) + 1);
private readonly BindableProperty CounterLabelProperty =
BindableProperty.Create(nameof(CounterLabel), typeof(string), typeof(CounterView), default(string));
public CounterView()
{
InitializeComponent();
CountLabel.BindingContext = this;
CountLabel.SetBinding(Label.TextProperty, nameof(Count));
CounterLabel.BindingContext = this;
CounterLabel.SetBinding(Label.TextProperty, nameof(CounterText));
}
public uint Count
{
get => (uint)GetValue(CountProperty);
set
{
SetValue(CountProperty, value <= 1 ? 1 : uint.Parse(value.ToString()));
OnPropertyChanged(nameof(Count));
}
}
public string CounterText
{
get => (string)GetValue(CounterLabelProperty);
set
{
SetValue(CounterLabelProperty, value);
OnPropertyChanged(nameof(CounterText));
}
}
private void OnPlus(object o, EventArgs e)
{
Count += 1;
}
private void OnMinus(object o, EventArgs e)
{
Count -= 1;
}
}

@ -4,13 +4,13 @@ public partial class HeadedButton : ContentView
{
private readonly BindableProperty TextProperty =
BindableProperty.Create("Text", typeof(string), typeof(HeadedButton), "No Text Defined.");
BindableProperty.Create(nameof(BtnLabel), typeof(string), typeof(HeadedButton), "No Text Defined.");
private readonly BindableProperty HeadColorProperty =
BindableProperty.Create("HeadColor", typeof(string), typeof(HeadedButton), "#FFFFFF");
BindableProperty.Create(nameof(PrefixBorder), typeof(string), typeof(HeadedButton), "#FFFFFF");
private readonly BindableProperty HeadSourceProperty =
BindableProperty.Create("HeadSource", typeof(string), typeof(HeadedButton), default(string));
BindableProperty.Create(nameof(PrefixImage), typeof(string), typeof(HeadedButton), default(string));
public string Text
{

@ -0,0 +1,57 @@
<?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.StoredRecipeView">
<Border
Style="{StaticResource SecondaryBorderShadow}"
StrokeShape="RoundRectangle 30">
<Grid
BackgroundColor="{StaticResource BackgroundSecondary}"
Padding="10"
MinimumHeightRequest="175"
MinimumWidthRequest="150"
RowDefinitions="*, Auto">
<Border
Grid.Row="0"
Stroke="Transparent"
StrokeShape="RoundRectangle 20"
BackgroundColor="AliceBlue">
<Grid>
<Image />
<HorizontalStackLayout
x:Name="Stars"
VerticalOptions="End"
HorizontalOptions="End"
Margin="0, 0, 15, 2">
<Image
WidthRequest="10"
Source="star_full.svg"/>
<Image
WidthRequest="10"
Source="star_full.svg"/>
<Image
WidthRequest="10"
Source="star_full.svg"/>
<Image
WidthRequest="10"
Source="star_full.svg"/>
<Image
WidthRequest="10"
Source="star_full.svg"/>
</HorizontalStackLayout>
</Grid>
</Border>
<VerticalStackLayout Grid.Row="1">
<Label
TextColor="{StaticResource TextColorPrimary}"
x:Name="TitleLabel"/>
<Label
TextColor="{StaticResource TextColorSecondary}"
x:Name="SubtitleLabel"/>
</VerticalStackLayout>
</Grid>
</Border>
</ContentView>

@ -0,0 +1,46 @@
namespace ShoopNCook.Views;
public partial class StoredRecipeView : ContentView
{
public StoredRecipeView() : this(5, "Title", "Subtitle")
{ }
public StoredRecipeView(float note, string title, string subtitle)
{
InitializeComponent();
Note = note;
Title = title;
Subtitle = subtitle;
}
public float Note
{
set => SetNote(value);
}
public string Title
{
set => TitleLabel.Text = value;
}
public string Subtitle
{
set => SubtitleLabel.Text = value;
}
private void SetNote(float note)
{
int i = 1;
foreach (Image img in Stars.Children)
{
if (i <= note)
{
img.Opacity = 0;
i++;
}
else img.Opacity = 1;
}
}
}
Loading…
Cancel
Save