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 List<RecipeInfo> RecommendedRecipes(Account account);
public List<RecipeInfo> PopularRecipes();
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);
}
}

@ -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> {
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");
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);
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("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5),
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)
{
Random random = new Random();

@ -1,17 +1,17 @@
namespace ShoopNCook;
using Microsoft.Maui.Controls;
using Models;
namespace ShoopNCook;
using Microsoft.Maui.Controls;
using Models;
using ShoopNCook.Controllers;
using ShoopNCook.Pages;
using Endpoint;
public partial class MainAppShell : Shell
{
public MainAppShell(Account account, IEndpoint endpoint, IApp app)
{
InitializeComponent();
HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, endpoint));
FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, app));
MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, app));
MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, new MorePageController(app)));
}
}
public partial class MainAppShell : Shell
{
public MainAppShell(Account account, IEndpoint endpoint, IApp app)
{
InitializeComponent();
HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, endpoint));
FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, endpoint.RecipesService));
MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, endpoint.RecipesService));
MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, new MorePageController(app)));
}
}

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

@ -12,7 +12,7 @@ public partial class RecipeView : ContentView
InitializeComponent();
Note = info.AverageNote;
Title = info.Name;
Subtitle = info.CookTimeMins + " min";
Subtitle = info.CookTimeMins + " min";
RecipeImage.Source = ImageSource.FromUri(info.Image);
callback = onClickCallback;
@ -40,7 +40,7 @@ public partial class RecipeView : ContentView
int i = 1;
foreach (Image img in Stars.Children)
{
if (i <= note)
if (i < note)
{
img.Opacity = 0;
i++;

@ -14,13 +14,18 @@
MinimumHeightRequest="250"
MinimumWidthRequest="150"
RowDefinitions="*, Auto">
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="OnRecipeTapped"/>
</Grid.GestureRecognizers>
<Border
Grid.Row="0"
Stroke="Transparent"
StrokeShape="RoundRectangle 20"
BackgroundColor="{StaticResource ImageBackground}">
<Grid>
<Image />
<Image x:Name="RecipeImage"/>
<HorizontalStackLayout
x:Name="Stars"
VerticalOptions="End"
@ -51,8 +56,9 @@
<Label
TextColor="{StaticResource TextColorPrimary}"
x:Name="TitleLabel"/>
<Grid></Grid>
<views:CounterView CounterText="pers"/>
<views:CounterView
CounterText="pers"
x:Name="Counter"/>
</VerticalStackLayout>
</Grid>
</Border>

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

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

@ -1,16 +1,28 @@
using Models;
namespace ShoopNCook.Pages;
using Endpoint;
using Models;
using ShoopNCook.Views;
public partial class FavoritesPage : ContentPage
{
public FavoritesPage(Account account, IApp app)
public FavoritesPage(Account account, IRecipesService service)
{
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;
//TODO this code can be factorised
void PushRecipe(Layout layout, RecipeInfo info)
{
layout.Children.Add(new RecipeView(info, () =>
@ -24,7 +26,7 @@ public partial class HomePage : ContentPage
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);
ProfilePictureName.Text = account.User.Name;

@ -32,23 +32,13 @@
VerticalOptions="Center"/>
</Grid>
<!-- Favorite items -->
<!-- Account Recipe List items -->
<ScrollView
Grid.Row="1">
<VerticalStackLayout
Padding="30, 0, 30, 0"
Spacing="12">
<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"/>
Spacing="12"
x:Name="RecipesLayout">
</VerticalStackLayout>
</ScrollView>

@ -1,11 +1,24 @@
using Endpoint;
using Models;
using ShoopNCook.Views;
namespace ShoopNCook.Pages;
public partial class MyListPage : ContentPage
{
public MyListPage(Account account, IApp app)
{
InitializeComponent();
}
namespace ShoopNCook.Pages;
public partial class MyListPage : ContentPage
{
public MyListPage(Account account, IRecipesService service)
{
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