integrate recipes in MyList and Favorite pages, fixed rating bugs in RecipeViews
continuous-integration/drone/push Build is passing Details

pull/50/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent 60d3d6267c
commit b213edb4ef

@ -9,12 +9,17 @@ namespace Endpoint
{ {
public interface IRecipesService public interface IRecipesService
{ {
public List<RecipeInfo> RecommendedRecipes(Account account);
public List<RecipeInfo> PopularRecipes(); public List<RecipeInfo> PopularRecipes();
public Recipe GetRecipe(RecipeInfo info); public Recipe GetRecipe(RecipeInfo info);
public List<RecipeInfo> RecommendedRecipesOf(Account account);
public List<RecipeInfo> LookupFavoritesOf(Account account);
public List<(RecipeInfo, uint)> LookupWeeklyListOf(Account account);
public AccountRecipeRate GetRateOf(Account account, Recipe recipe); public AccountRecipeRate GetRateOf(Account account, Recipe recipe);
} }
} }

@ -17,8 +17,16 @@ namespace LocalEndpoint
}; };
} }
public Recipe GetRecipe(RecipeInfo info)
{
User owner = new User(new Uri("https://i.ibb.co/L6t6bGR/DALL-E-2023-05-10-20-27-31-cook-looking-at-the-camera-with-a-chef-s-hat-laughing-in-an-exaggerated-w.png"), "The Funny Chief");
List<Ingredient> ingredients = new List<Ingredient> { new Ingredient("Banana", 12), new Ingredient("Apple", 2) };
List<PreparationStep> steps = new List<PreparationStep> { new PreparationStep("Step 1", "This step is an hardcoded step from a stub implementation of IRecipesSeervice") };
return new Recipe(info, owner, ingredients, steps);
}
public List<RecipeInfo> RecommendedRecipes(Account account) public List<RecipeInfo> RecommendedRecipesOf(Account account)
{ {
return new List<RecipeInfo> { return new List<RecipeInfo> {
new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4), new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4),
@ -29,14 +37,26 @@ namespace LocalEndpoint
}; };
} }
public Recipe GetRecipe(RecipeInfo info) public List<RecipeInfo> LookupFavoritesOf(Account account)
{ {
User owner = new User(new Uri("https://i.ibb.co/L6t6bGR/DALL-E-2023-05-10-20-27-31-cook-looking-at-the-camera-with-a-chef-s-hat-laughing-in-an-exaggerated-w.png"), "The Funny Chief"); return new List<RecipeInfo> {
List<Ingredient> ingredients = new List<Ingredient> { new Ingredient("Banana", 12), new Ingredient("Apple", 2) }; new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4),
List<PreparationStep> steps = new List<PreparationStep> { new PreparationStep("Step 1", "This step is an hardcoded step from a stub implementation of IRecipesSeervice") }; new RecipeInfo("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5),
return new Recipe(info, owner, ingredients, steps); new RecipeInfo("Fish And Ships", 450, 15, new Uri("https://upload.wikimedia.org/wikipedia/commons/f/ff/Fish_and_chips_blackpool.jpg"), 4),
new RecipeInfo("Caesar Salad", 150, 20, new Uri("https://www.galbani.fr/wp-content/uploads/2020/04/AdobeStock_157570276-2.jpeg"), 1)
};
} }
public List<(RecipeInfo, uint)> LookupWeeklyListOf(Account account)
{
return new List<(RecipeInfo, uint)> {
(new RecipeInfo("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5), 4),
(new RecipeInfo("Chicken Curry", 500, 45, new Uri("https://cdn.chefclub.tools/uploads/recipes/cover-thumbnail/f287b191-dc8e-4c85-bbb6-e26387c354d3.jpg"), 3), 4),
(new RecipeInfo("Spaghetti Bolognese", 1000, 30, new Uri("https://media.istockphoto.com/id/1144823591/fr/photo/spaghetti-dans-un-plat-sur-un-fond-blanc.jpg?s=612x612&w=0&k=20&c=qFzd8iE185mpsX7hWqYaieOWlzJVCkzFdYsxmwUT3-Q="), 1), 1),
};
}
public AccountRecipeRate GetRateOf(Account account, Recipe recipe) public AccountRecipeRate GetRateOf(Account account, Recipe recipe)
{ {
Random random = new Random(); Random random = new Random();

@ -10,8 +10,8 @@ public partial class MainAppShell : Shell
{ {
InitializeComponent(); InitializeComponent();
HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, endpoint)); HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, endpoint));
FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, app)); FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, endpoint.RecipesService));
MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, app)); MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, endpoint.RecipesService));
MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, new MorePageController(app))); MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, new MorePageController(app)));
} }
} }

@ -28,7 +28,7 @@ public partial class OwnedRecipeView : ContentView
int i = 1; int i = 1;
foreach (Image img in Stars.Children) foreach (Image img in Stars.Children)
{ {
if (i <= note) if (i < note)
{ {
img.Opacity = 0; img.Opacity = 0;
i++; i++;

@ -40,7 +40,7 @@ public partial class RecipeView : ContentView
int i = 1; int i = 1;
foreach (Image img in Stars.Children) foreach (Image img in Stars.Children)
{ {
if (i <= note) if (i < note)
{ {
img.Opacity = 0; img.Opacity = 0;
i++; i++;

@ -14,13 +14,18 @@
MinimumHeightRequest="250" MinimumHeightRequest="250"
MinimumWidthRequest="150" MinimumWidthRequest="150"
RowDefinitions="*, Auto"> RowDefinitions="*, Auto">
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="OnRecipeTapped"/>
</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 /> <Image x:Name="RecipeImage"/>
<HorizontalStackLayout <HorizontalStackLayout
x:Name="Stars" x:Name="Stars"
VerticalOptions="End" VerticalOptions="End"
@ -51,8 +56,9 @@
<Label <Label
TextColor="{StaticResource TextColorPrimary}" TextColor="{StaticResource TextColorPrimary}"
x:Name="TitleLabel"/> x:Name="TitleLabel"/>
<Grid></Grid> <views:CounterView
<views:CounterView CounterText="pers"/> CounterText="pers"
x:Name="Counter"/>
</VerticalStackLayout> </VerticalStackLayout>
</Grid> </Grid>
</Border> </Border>

@ -1,16 +1,23 @@
using Models;
namespace ShoopNCook.Views; namespace ShoopNCook.Views;
public partial class StoredRecipeView : ContentView public partial class StoredRecipeView : ContentView
{ {
public StoredRecipeView() : this(5, "Title") private readonly Action<uint> clickCallback;
{ }
public StoredRecipeView(float note, string title) public StoredRecipeView(RecipeInfo info, uint personCount, Action<uint> onClickCallback)
{ {
InitializeComponent(); InitializeComponent();
Note = note;
Title = title; clickCallback = onClickCallback;
Note = info.AverageNote;
Title = info.Name;
RecipeImage.Source = ImageSource.FromUri(info.Image);
Counter.Count = personCount;
} }
public float Note public float Note
@ -23,14 +30,12 @@ public partial class StoredRecipeView : ContentView
set => TitleLabel.Text = value; set => TitleLabel.Text = value;
} }
private void SetNote(float note) private void SetNote(float note)
{ {
int i = 1; int i = 1;
foreach (Image img in Stars.Children) foreach (Image img in Stars.Children)
{ {
if (i <= note) if (i < note)
{ {
img.Opacity = 0; img.Opacity = 0;
i++; i++;
@ -38,4 +43,9 @@ public partial class StoredRecipeView : ContentView
else img.Opacity = 1; else img.Opacity = 1;
} }
} }
private void OnRecipeTapped(object sender, TappedEventArgs e)
{
clickCallback(Counter.Count);
}
} }

@ -15,7 +15,6 @@
ColumnDefinitions="*" ColumnDefinitions="*"
MaximumHeightRequest="60"> MaximumHeightRequest="60">
<Label <Label
Grid.Column="0" Grid.Column="0"
FontSize="24" FontSize="24"

@ -1,16 +1,28 @@
using Models; using Models;
namespace ShoopNCook.Pages; namespace ShoopNCook.Pages;
using Endpoint;
using Models; using Models;
using ShoopNCook.Views; using ShoopNCook.Views;
public partial class FavoritesPage : ContentPage public partial class FavoritesPage : ContentPage
{ {
public FavoritesPage(Account account, IApp app) public FavoritesPage(Account account, IRecipesService service)
{ {
InitializeComponent(); InitializeComponent();
//TODO //TODO this code can be factorised (see HomePage, MyListPage)
service.LookupFavoritesOf(account).ForEach(info =>
{
RecipeViewLayout.Children.Add(new RecipeView(info, () =>
{
Recipe recipe = service.GetRecipe(info);
AccountRecipeRate rate = service.GetRateOf(account, recipe);
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, rate, 1));
}));
});
} }
} }

@ -12,6 +12,8 @@ public partial class HomePage : ContentPage
IRecipesService service = endpoint.RecipesService; IRecipesService service = endpoint.RecipesService;
//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, () =>
@ -24,7 +26,7 @@ public partial class HomePage : ContentPage
service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe)); service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe));
service.RecommendedRecipes(account).ForEach(recipe => PushRecipe(RecommendedList, recipe)); service.RecommendedRecipesOf(account).ForEach(recipe => PushRecipe(RecommendedList, recipe));
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture); ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfilePictureName.Text = account.User.Name; ProfilePictureName.Text = account.User.Name;

@ -32,23 +32,13 @@
VerticalOptions="Center"/> VerticalOptions="Center"/>
</Grid> </Grid>
<!-- Favorite items --> <!-- Account Recipe List items -->
<ScrollView <ScrollView
Grid.Row="1"> Grid.Row="1">
<VerticalStackLayout <VerticalStackLayout
Padding="30, 0, 30, 0" Padding="30, 0, 30, 0"
Spacing="12"> Spacing="12"
x:Name="RecipesLayout">
<views:StoredRecipeView Note="4.5" Title="Spaghetti Bolognese"/>
<views:StoredRecipeView Note="3" Title="Chickend Curry"/>
<views:StoredRecipeView Note="0.2" Title="Beef Stroganoff"/>
<views:StoredRecipeView Note="1.6" Title="Fish And Ships" />
<views:StoredRecipeView Note="5" Title="Caesar Salad"/>
<views:StoredRecipeView Note="3.5" Title="Vegetables"/>
<views:StoredRecipeView Note="4.6" Title="Guacamole"/>
<views:StoredRecipeView Note="4" Title="Pad Thai"/>
<views:StoredRecipeView Note="3" Title="French Toast"/>
<views:StoredRecipeView Note="2" Title="Margherita Pizza"/>
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>

@ -1,11 +1,24 @@
using Endpoint;
using Models; using Models;
using ShoopNCook.Views;
namespace ShoopNCook.Pages; namespace ShoopNCook.Pages;
public partial class MyListPage : ContentPage public partial class MyListPage : ContentPage
{ {
public MyListPage(Account account, IApp app) public MyListPage(Account account, IRecipesService service)
{ {
InitializeComponent(); InitializeComponent();
service.LookupWeeklyListOf(account).ForEach(info =>
{
RecipesLayout.Children.Add(new StoredRecipeView(info.Item1, info.Item2, amount =>
{
Recipe recipe = service.GetRecipe(info.Item1);
AccountRecipeRate rate = service.GetRateOf(account, recipe);
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, rate, amount));
}));
});
} }
} }
Loading…
Cancel
Save