fix basic bindings
continuous-integration/drone/push Build is passing Details

master
Maxime BATISTA 2 years ago
parent 00056c4aa2
commit 7777304ef3

@ -1,52 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Views.CounterView" x:Class="ShoopNCook.Views.CounterView"
x:Name="Counter"> x:Name="Counter">
<Grid <Grid
ColumnDefinitions="*, Auto, *"> ColumnDefinitions="*, Auto, *">
<Border <Border
Grid.Column="0" Grid.Column="0"
Stroke="Transparent" Stroke="Transparent"
StrokeShape="RoundRectangle 100" StrokeShape="RoundRectangle 100"
BackgroundColor="{StaticResource Selected}"> BackgroundColor="{StaticResource Selected}">
<ImageButton <ImageButton
Source="minus.svg" Source="minus.svg"
WidthRequest="40" WidthRequest="40"
HeightRequest="40" HeightRequest="40"
Clicked="OnMinus"/> Clicked="OnMinus"/>
</Border> </Border>
<HorizontalStackLayout <HorizontalStackLayout
Grid.Column="1" Grid.Column="1"
Spacing="3" Spacing="3"
Margin="10, 0, 10, 0"> Margin="10, 0, 10, 0">
<Label <Label
x:Name="CountLabel" x:Name="CountLabel"
Text="{Binding Count, Source={x:Reference Counter}}" Text="{Binding Count, Source={x:Reference Counter}}"
TextColor="{StaticResource TextColorPrimary}" TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center" VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/> FontFamily="PoppinsMedium"/>
<Label <Label
x:Name="CounterLabel" x:Name="CounterLabel"
Text="{Binding CounterText, Source={x:Reference Counter}}" Text="{Binding CounterText, Source={x:Reference Counter}}"
TextColor="{StaticResource TextColorPrimary}" TextColor="{StaticResource TextColorPrimary}"
VerticalTextAlignment="Center" VerticalTextAlignment="Center"
FontFamily="PoppinsMedium"/> FontFamily="PoppinsMedium"/>
</HorizontalStackLayout> </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}">
<ImageButton <ImageButton
Source="plus.svg" Source="plus.svg"
WidthRequest="40" WidthRequest="40"
HeightRequest="40" HeightRequest="40"
Clicked="OnPlus"/> Clicked="OnPlus"/>
</Border> </Border>
</Grid> </Grid>
</ContentView> </ContentView>

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

@ -25,7 +25,9 @@
HeightRequest="65"/> HeightRequest="65"/>
</Border> </Border>
<Label Style="{StaticResource h1}" x:Name="ProfilePictureName"/> <Label
Style="{StaticResource h1}"
Text="{Binding User.Name}"/>
</FlexLayout> </FlexLayout>
<Grid <Grid
ColumnDefinitions="*,Auto" ColumnDefinitions="*,Auto"
@ -89,8 +91,7 @@
JustifyContent="SpaceBetween" JustifyContent="SpaceBetween"
AlignItems="Center" AlignItems="Center"
Margin="20,0,20,20" Margin="20,0,20,20"
HeightRequest="30" HeightRequest="30">
>
<Label <Label
Text="Recommended for you" Text="Recommended for you"
Style="{StaticResource h2}"/> Style="{StaticResource h2}"/>

@ -7,15 +7,16 @@ using LocalEndpoint;
public partial class HomePage : ContentPage public partial class HomePage : ContentPage
{ {
public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint) public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint)
{ {
InitializeComponent();
InitializeComponent();
BindingContext = account;
IRecipesService service = endpoint.RecipesService; IRecipesService service = endpoint.RecipesService;
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account); IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
//TODO this code can be factorised
void PushRecipe(Layout layout, RecipeInfo info) void PushRecipe(Layout layout, RecipeInfo info)
{ {
layout.Children.Add(new RecipeView(info, () => layout.Children.Add(new RecipeView(info, () =>
@ -29,7 +30,6 @@ public partial class HomePage : ContentPage
preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe)); preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe));
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture); ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfilePictureName.Text = account.User.Name;
} }

@ -20,6 +20,7 @@
<Label <Label
x:Name="ProfileName" x:Name="ProfileName"
Text="{Binding Account.User.Name}"
Grid.Column="1" Grid.Column="1"
FontSize="24" FontSize="24"
VerticalTextAlignment="Center" VerticalTextAlignment="Center"

@ -7,12 +7,14 @@ public partial class MorePage : ContentPage
{ {
private readonly MorePageController controller; private readonly MorePageController controller;
private Account Account { get; init; }
public MorePage(Account account, MorePageController controller) public MorePage(Account account, MorePageController controller)
{ {
Account = account;
BindingContext = this;
InitializeComponent(); InitializeComponent();
ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture); ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfileName.Text = account.User.Name;
this.controller = controller; this.controller = controller;
} }

@ -50,9 +50,7 @@
HorizontalOptions="Center" HorizontalOptions="Center"
Stroke="{StaticResource BackgroundPrimary}" Stroke="{StaticResource BackgroundPrimary}"
BackgroundColor="{StaticResource BackgroundSecondary}"> BackgroundColor="{StaticResource BackgroundSecondary}">
<ImageButton <ImageButton x:Name="ProfilePicture"/>
Grid.Row="0"
Source="default_profile_picture.png"/>
</Border> </Border>
<Label <Label
@ -60,7 +58,7 @@
FontSize="30" FontSize="30"
HorizontalOptions="Center" HorizontalOptions="Center"
TextColor="{StaticResource TextColorPrimary}" TextColor="{StaticResource TextColorPrimary}"
Text="%Profile_Name%" Text="{Binding Account.User.Name}"
FontFamily="PoppinsBold"/> FontFamily="PoppinsBold"/>
<Label <Label
Grid.Row="2" Grid.Row="2"
@ -88,7 +86,7 @@
Style="{StaticResource SecondaryBorderShadow}"> Style="{StaticResource SecondaryBorderShadow}">
<Entry <Entry
Style="{StaticResource UserInput}" Style="{StaticResource UserInput}"
Text="%Profile_Name%" Text="{Binding User.Name}"
Placeholder="Place your name here"/> Placeholder="Place your name here"/>
</Border> </Border>
@ -103,7 +101,7 @@
Style="{StaticResource SecondaryBorderShadow}"> Style="{StaticResource SecondaryBorderShadow}">
<Entry <Entry
Style="{StaticResource UserInput}" Style="{StaticResource UserInput}"
Text="%Profile_Mail%" Text="{Binding Email}"
Placeholder="Place your email address here"/> Placeholder="Place your email address here"/>
</Border> </Border>
<Border <Border
@ -118,9 +116,6 @@
Text="Change My Password" Text="Change My Password"
Clicked="ChangeMyPasswordClicked"/> Clicked="ChangeMyPasswordClicked"/>
</Border> </Border>
</Grid> </Grid>

@ -4,16 +4,21 @@ namespace ShoopNCook.Pages;
public partial class ProfilePage : ContentPage public partial class ProfilePage : ContentPage
{ {
public ProfilePage(Account account) public ProfilePage(Account account)
{ {
InitializeComponent(); BindingContext = account;
} InitializeComponent();
ProfilePicture.Source = ImageSource.FromUri(account.User.ProfilePicture);
}
private async void OnBackButtonClicked(object sender, EventArgs e) private async void OnBackButtonClicked(object sender, EventArgs e)
{ {
await Navigation.PopAsync(); await Navigation.PopAsync();
} }
private async void ChangeMyPasswordClicked(object sender, EventArgs e) private async void ChangeMyPasswordClicked(object sender, EventArgs e)
{ {
await Shell.Current.Navigation.PushAsync(new ChangePassword()) ; await Shell.Current.Navigation.PushAsync(new ChangePassword());
} }
} }

@ -63,8 +63,8 @@
<Label <Label
Style="{StaticResource Small}" Style="{StaticResource Small}"
Text="{Binding Recipe.Info.CookTimeMins, StringFormat='Cooking time: {0} mins'}"/> Text="{Binding Recipe.Info.CookTimeMins, StringFormat='Cooking time: {0} mins'}"/>
<!--Energy-->
<!--Energy-->
<Label <Label
Style="{StaticResource Small}" Style="{StaticResource Small}"
Text="{Binding Recipe.Info.CalPerPers, StringFormat='Energy: {0}/pers'}"/> Text="{Binding Recipe.Info.CalPerPers, StringFormat='Energy: {0}/pers'}"/>

@ -1,113 +1,113 @@
using ShoopNCook.Views; using ShoopNCook.Views;
using System.Windows.Input; using System.Windows.Input;
using Models; using Models;
using LocalEndpoint; using LocalEndpoint;
using Endpoint; using Endpoint;
namespace ShoopNCook.Pages; namespace ShoopNCook.Pages;
public partial class RecipePage : ContentPage public partial class RecipePage : ContentPage
{ {
private readonly IAccountRecipesPreferences preferences; private readonly IAccountRecipesPreferences preferences;
private readonly IUserNotifier notifier; private readonly IUserNotifier notifier;
public Recipe Recipe { get; init; } public Recipe Recipe { get; init; }
private uint note; private uint note;
private bool isFavorite; private bool isFavorite;
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; Recipe = recipe;
BindingContext = this; BindingContext = this;
InitializeComponent(); InitializeComponent();
this.preferences = preferences; this.preferences = preferences;
this.notifier = notifier; this.notifier = notifier;
RecipeRate rate = preferences.GetRate(recipe.Info); RecipeRate rate = preferences.GetRate(recipe.Info);
note = rate.Rate; note = rate.Rate;
isFavorite = rate.IsFavorite; isFavorite = rate.IsFavorite;
SetFavorite(isFavorite); SetFavorite(isFavorite);
SetNote(note); SetNote(note);
Counter.Count = amount; Counter.Count = amount;
if (recipe.Info.Image != null) if (recipe.Info.Image != null)
RecipeImage.Source = ImageSource.FromUri(recipe.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));
//retrieves the app's styles //retrieves the app's styles
var styles = Application.Current.Resources.MergedDictionaries.ElementAt(1); var styles = Application.Current.Resources.MergedDictionaries.ElementAt(1);
int count = 0; int count = 0;
foreach (PreparationStep step in recipe.Steps) { foreach (PreparationStep step in recipe.Steps) {
//TODO display name of PreparationSteps. //TODO display name of PreparationSteps.
Label label = new Label(); Label label = new Label();
label.Style = (Style)styles["Small"]; label.Style = (Style)styles["Small"];
label.Text = "Step " + ++count + ": " + step.Description; label.Text = "Step " + ++count + ": " + step.Description;
StepList.Add(label); StepList.Add(label);
} }
} }
private void SetNote(uint note) private void SetNote(uint note)
{ {
this.note = note; this.note = note;
int i = 1; int i = 1;
foreach (ImageButton img in Stars.Children) foreach (ImageButton img in Stars.Children)
{ {
if (i <= note) if (i <= note)
{ {
img.Source = ImageSource.FromFile("star_full.svg"); img.Source = ImageSource.FromFile("star_full.svg");
i++; i++;
} }
else else
img.Source = ImageSource.FromFile("star_empty.svg"); img.Source = ImageSource.FromFile("star_empty.svg");
} }
} }
private void OnFavorite(object o, EventArgs e) private void OnFavorite(object o, EventArgs e)
{ {
SetFavorite(!isFavorite); SetFavorite(!isFavorite);
if (isFavorite) if (isFavorite)
preferences.AddToFavorites(Recipe.Info); preferences.AddToFavorites(Recipe.Info);
else else
preferences.RemoveFromFavorites(Recipe.Info); preferences.RemoveFromFavorites(Recipe.Info);
} }
private void OnSubmitReviewClicked(object o, EventArgs e) private void OnSubmitReviewClicked(object o, EventArgs e)
{ {
preferences.SetReviewScore(Recipe.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(Recipe.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.");
} }
private void SetFavorite(bool isFavorite) private void SetFavorite(bool isFavorite)
{ {
this.isFavorite = isFavorite; this.isFavorite = isFavorite;
if (isFavorite) if (isFavorite)
Favorite.Source = ImageSource.FromFile("hearth_on.svg"); Favorite.Source = ImageSource.FromFile("hearth_on.svg");
else else
Favorite.Source = ImageSource.FromFile("hearth_off.svg"); Favorite.Source = ImageSource.FromFile("hearth_off.svg");
} }
private void OnBackButtonClicked(object sender, EventArgs e) private void OnBackButtonClicked(object sender, EventArgs e)
{ {
Navigation.PopAsync(); Navigation.PopAsync();
} }
} }
Loading…
Cancel
Save