owned recipe et recipe view databinding
continuous-integration/drone/push Build is passing Details

master
Leo TUAILLON 2 years ago
parent 85d8b24d82
commit 5ab02adc1a

@ -28,7 +28,7 @@
StrokeShape="RoundRectangle 20" StrokeShape="RoundRectangle 20"
BackgroundColor="{StaticResource ImageBackground}"> BackgroundColor="{StaticResource ImageBackground}">
<Grid> <Grid>
<Image x:Name="RecipeImage" <Image Source="{Binding Image}"
MinimumHeightRequest="175" MinimumHeightRequest="175"
MinimumWidthRequest="150" MinimumWidthRequest="150"
MaximumHeightRequest="175" MaximumHeightRequest="175"
@ -61,7 +61,7 @@
<VerticalStackLayout Grid.Row="1"> <VerticalStackLayout Grid.Row="1">
<Label <Label
TextColor="{StaticResource TextColorPrimary}" TextColor="{StaticResource TextColorPrimary}"
x:Name="TitleLabel"/> Text="{Binding Name}"/>
<Border <Border
BackgroundColor="{StaticResource Selected}" BackgroundColor="{StaticResource Selected}"
Stroke="Transparent" Stroke="Transparent"

@ -13,12 +13,9 @@ public partial class OwnedRecipeView : ContentView
{ {
InitializeComponent(); InitializeComponent();
if (info.Image != null)
RecipeImage.Source = ImageSource.FromUri(info.Image);
Note = info.AverageNote; Note = info.AverageNote;
Title = info.Name;
this.recipeInfo = info; BindingContext = info;
this.clickCallback = onClickCallback; this.clickCallback = onClickCallback;
this.removeCallback = onRemoveCallback; this.removeCallback = onRemoveCallback;
} }
@ -32,11 +29,7 @@ public partial class OwnedRecipeView : ContentView
set => SetNote(value); set => SetNote(value);
} }
public string Title
{
set => TitleLabel.Text = value;
}
private void SetNote(float note) private void SetNote(float note)
{ {
note = (uint)note; //truncate integer as we currently do not handle semi stars note = (uint)note; //truncate integer as we currently do not handle semi stars

@ -4,7 +4,6 @@
x:Class="ShoopNCook.Views.RecipeView" x:Class="ShoopNCook.Views.RecipeView"
Margin="4,2"> Margin="4,2">
<Border <Border
Style="{StaticResource SecondaryBorderShadow}" Style="{StaticResource SecondaryBorderShadow}"
StrokeShape="RoundRectangle 30"> StrokeShape="RoundRectangle 30">
@ -17,25 +16,27 @@
MinimumWidthRequest="150" MinimumWidthRequest="150"
MaximumWidthRequest="150" MaximumWidthRequest="150"
RowDefinitions="*, Auto"> RowDefinitions="*, Auto">
<Grid.GestureRecognizers> <Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="OnRecipeTapped"/> <TapGestureRecognizer Tapped="OnRecipeTapped"/>
</Grid.GestureRecognizers> </Grid.GestureRecognizers>
<Border <Border
Grid.Row="0" Grid.Row="0"
Stroke="Transparent" Stroke="Transparent"
StrokeShape="RoundRectangle 20" StrokeShape="RoundRectangle 20"
BackgroundColor="{StaticResource ImageBackground}"> BackgroundColor="{StaticResource ImageBackground}">
<Grid> <Grid>
<Image x:Name="RecipeImage" <Image
Aspect="AspectFill" Source="{Binding Image}"
MinimumHeightRequest="155" Aspect="AspectFill"
MinimumWidthRequest="130" MinimumHeightRequest="155"
MaximumHeightRequest="155" MinimumWidthRequest="130"
MaximumWidthRequest="130"/> MaximumHeightRequest="155"
MaximumWidthRequest="130"/>
<HorizontalStackLayout <HorizontalStackLayout
x:Name="Stars"
VerticalOptions="End" VerticalOptions="End"
x:Name="Stars"
HorizontalOptions="End" HorizontalOptions="End"
Margin="0, 0, 15, 2"> Margin="0, 0, 15, 2">
<Image <Image
@ -60,10 +61,10 @@
<VerticalStackLayout Grid.Row="1"> <VerticalStackLayout Grid.Row="1">
<Label <Label
TextColor="{StaticResource TextColorPrimary}" TextColor="{StaticResource TextColorPrimary}"
x:Name="TitleLabel"/> Text="{Binding Name}"/>
<Label <Label
TextColor="{StaticResource TextColorSecondary}" TextColor="{StaticResource TextColorSecondary}"
x:Name="SubtitleLabel"/> Text="{Binding CookTimeMins, StringFormat='{0} mins'}"/>
</VerticalStackLayout> </VerticalStackLayout>
</Grid> </Grid>
</Border> </Border>

@ -1,4 +1,4 @@
using ShoopNCook.Pages; /*using ShoopNCook.Pages;
using Models; using Models;
namespace ShoopNCook.Views; namespace ShoopNCook.Views;
@ -56,4 +56,52 @@ public partial class RecipeView : ContentView
{ {
callback(); callback();
} }
} }*/
using ShoopNCook.Pages;
using Models;
namespace ShoopNCook.Views
{
public partial class RecipeView : ContentView
{
private readonly Action callback;
public RecipeView(RecipeInfo info, Action callback)
{
this.callback = callback;
BindingContext = info;
InitializeComponent();
Note = info.AverageNote;
}
public float Note
{
set => SetNote(value);
}
private void SetNote(float note)
{
note = (uint)note; //truncate integer as we currently do not handle semi stars
foreach (Image img in Stars.Children.Reverse())
{
if (note > 0)
{
img.Opacity = 1;
note--;
}
else img.Opacity = 0;
}
}
private void OnRecipeTapped(object sender, EventArgs e)
{
callback();
}
}
}

@ -26,7 +26,7 @@
MaximumHeightRequest="300" MaximumHeightRequest="300"
BackgroundColor="{StaticResource ImageBackground}"> BackgroundColor="{StaticResource ImageBackground}">
<Grid> <Grid>
<Image x:Name="RecipeImage" <Image Source="{Binding Image}"
Aspect="AspectFill"/> Aspect="AspectFill"/>
<HorizontalStackLayout <HorizontalStackLayout
x:Name="Stars" x:Name="Stars"
@ -57,7 +57,7 @@
Grid.Row="1"> Grid.Row="1">
<Label <Label
TextColor="{StaticResource TextColorPrimary}" TextColor="{StaticResource TextColorPrimary}"
x:Name="TitleLabel"/> Text="{Binding Name}"/>
<views:CounterView <views:CounterView
CounterText="pers" CounterText="pers"
x:Name="Counter"/> x:Name="Counter"/>

@ -12,11 +12,8 @@ public partial class StoredRecipeView : ContentView
{ {
InitializeComponent(); InitializeComponent();
if (info.Image != null)
RecipeImage.Source = ImageSource.FromUri(info.Image);
Note = info.AverageNote; Note = info.AverageNote;
Title = info.Name; BindingContext = info;
clickCallback = onClickCallback; clickCallback = onClickCallback;
Counter.Count = personCount; Counter.Count = personCount;
} }
@ -26,11 +23,7 @@ public partial class StoredRecipeView : ContentView
set => SetNote(value); set => SetNote(value);
} }
public string Title
{
set => TitleLabel.Text = value;
}
private void SetNote(float note) private void SetNote(float note)
{ {
note = (uint)note; //truncate integer as we currently do not handle semi stars note = (uint)note; //truncate integer as we currently do not handle semi stars

Loading…
Cancel
Save