From adda823bf942a936b4fee7c84aa809554c3e675d Mon Sep 17 00:00:00 2001 From: "maxime.BATISTA@etu.uca.fr" Date: Wed, 10 May 2023 20:42:21 +0200 Subject: [PATCH] integrate recipes in HomePage --- App.xaml.cs | 4 +- Endpoint/IEndpoint.cs | 2 + Endpoint/IRecipesService.cs | 20 +++++++++ LocalEndpoint/AccountManager.cs | 3 +- LocalEndpoint/LocalEndpoint.cs | 1 + LocalEndpoint/RecipesService.cs | 48 ++++++++++++++++++++ MainAppShell.xaml.cs | 6 +-- Models/Ingredient.cs | 4 +- Models/Quantity.cs | 6 --- Models/RecipeInfo.cs | 9 ++-- Models/RecipeState.cs | 22 ++++++++++ ShoopNCook.csproj | 4 +- Views/Components/IngredientView.xaml.cs | 11 +++-- Views/Components/RecipeView.xaml.cs | 15 ++++--- Views/FavoritesPage.xaml.cs | 30 ++++++------- Views/HomePage.xaml | 6 +-- Views/HomePage.xaml.cs | 40 ++++++++++------- Views/RecipePage.xaml.cs | 58 ++++++++++--------------- Views/SearchPage.xaml.cs | 6 +-- 19 files changed, 189 insertions(+), 106 deletions(-) create mode 100644 Endpoint/IRecipesService.cs create mode 100644 LocalEndpoint/RecipesService.cs delete mode 100644 Models/Quantity.cs create mode 100644 Models/RecipeState.cs diff --git a/App.xaml.cs b/App.xaml.cs index 16b7b95..5e0f01e 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -13,12 +13,12 @@ public partial class App : Application, ConnectionObserver, IApp public App() { InitializeComponent(); - ForceLogin(); //start in login state + ForceLogin(); //start in login shell } public void OnAccountConnected(Account account) { - Shell shell = new MainAppShell(account, this); + Shell shell = new MainAppShell(account, Endpoint, this); shell.GoToAsync("//Home"); MainPage = shell; } diff --git a/Endpoint/IEndpoint.cs b/Endpoint/IEndpoint.cs index 649e501..10906ee 100644 --- a/Endpoint/IEndpoint.cs +++ b/Endpoint/IEndpoint.cs @@ -6,6 +6,8 @@ namespace Endpoint { public IAccountManager AccountManager { get; } + public IRecipesService RecipesService { get; } + } } diff --git a/Endpoint/IRecipesService.cs b/Endpoint/IRecipesService.cs new file mode 100644 index 0000000..9708611 --- /dev/null +++ b/Endpoint/IRecipesService.cs @@ -0,0 +1,20 @@ +using Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Endpoint +{ + public interface IRecipesService + { + public List RecommendedRecipes(Account account); + + public List PopularRecipes(); + + public Recipe GetRecipe(RecipeInfo info); + + public RecipeState RecipeStateOf(Account account, Recipe recipe); + } +} diff --git a/LocalEndpoint/AccountManager.cs b/LocalEndpoint/AccountManager.cs index 2a3dbc2..e3df8fc 100644 --- a/LocalEndpoint/AccountManager.cs +++ b/LocalEndpoint/AccountManager.cs @@ -14,7 +14,7 @@ namespace LocalEndpoint private Account userAccount = new Account(new User(DEFAULT_ACCOUNT_IMAGE, "Stub Account"), "test@example.com"); private string userPassword = "123456"; - + public Account? Login(string email, string password) { if (userAccount.Email == email && userPassword == password) @@ -24,6 +24,7 @@ namespace LocalEndpoint return null; } + public Account? Register(string email, string username, string password) { if (email == null || username == null || password == null) diff --git a/LocalEndpoint/LocalEndpoint.cs b/LocalEndpoint/LocalEndpoint.cs index d2696f7..1a8e310 100644 --- a/LocalEndpoint/LocalEndpoint.cs +++ b/LocalEndpoint/LocalEndpoint.cs @@ -6,5 +6,6 @@ namespace LocalEndpoint { public IAccountManager AccountManager => new AccountManager(); + public IRecipesService RecipesService => new RecipesService(); } } \ No newline at end of file diff --git a/LocalEndpoint/RecipesService.cs b/LocalEndpoint/RecipesService.cs new file mode 100644 index 0000000..b7891cc --- /dev/null +++ b/LocalEndpoint/RecipesService.cs @@ -0,0 +1,48 @@ +using Endpoint; +using Models; + +namespace LocalEndpoint +{ + internal class RecipesService : IRecipesService + { + + public List PopularRecipes() + { + return new List { + new RecipeInfo("Chicken Curry", 45, new Uri("https://cdn.chefclub.tools/uploads/recipes/cover-thumbnail/f287b191-dc8e-4c85-bbb6-e26387c354d3.jpg"), 3), + new RecipeInfo("Spaghetti Bolognese", 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), + new RecipeInfo("Beef Stroganoff", 10, new Uri("https://www.cookwithnabeela.com/wp-content/uploads/2023/02/BeefStroganoff.webp"), 5), + new RecipeInfo("Fish And Ships", 15, new Uri("https://upload.wikimedia.org/wikipedia/commons/f/ff/Fish_and_chips_blackpool.jpg"), 4), + new RecipeInfo("Caesar Salad", 20, new Uri("https://www.galbani.fr/wp-content/uploads/2020/04/AdobeStock_157570276-2.jpeg"), 1) + }; + } + + + public List RecommendedRecipes(Account account) + { + return new List { + new RecipeInfo("Chicken Salad", 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4), + new RecipeInfo("Chocolate Cake", 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3), + new RecipeInfo("Salmon", 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4), + new RecipeInfo("Fish", 30, new Uri("https://www.ciaanet.org/wp-content/uploads/2022/07/Atlantic-and-Pacific-whole-salmon-1024x683.jpg"), 4.5F), + new RecipeInfo("Space Cake", 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5) + }; + } + + 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 ingredients = new List { new Ingredient("Banana", 12), new Ingredient("Apple", 2) }; + List steps = new List { new PreparationStep("Step 1", "This step is an hardcoded step from a stub implementation of IRecipesSeervice") }; + return new Recipe(info, owner, ingredients, steps); + } + + public RecipeState RecipeStateOf(Account account, Recipe recipe) + { + Random random = new Random(); + return new RecipeState((uint) random.Next(1, 10), random.Next() % 2 == 0, (uint)random.Next(0, 6), recipe); + } + + + } +} diff --git a/MainAppShell.xaml.cs b/MainAppShell.xaml.cs index d8df598..70ce6aa 100644 --- a/MainAppShell.xaml.cs +++ b/MainAppShell.xaml.cs @@ -3,13 +3,13 @@ using Microsoft.Maui.Controls; using Models; using ShoopNCook.Controllers; using ShoopNCook.Pages; - +using Endpoint; public partial class MainAppShell : Shell { - public MainAppShell(Account account, IApp app) + public MainAppShell(Account account, IEndpoint endpoint, IApp app) { InitializeComponent(); - HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, app)); + 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))); diff --git a/Models/Ingredient.cs b/Models/Ingredient.cs index 48f1f21..ed74bff 100644 --- a/Models/Ingredient.cs +++ b/Models/Ingredient.cs @@ -3,15 +3,13 @@ public class Ingredient { - public Ingredient(string name, float amount, Quantity quantity) + public Ingredient(string name, float amount) { Name = name; Amount = amount; - Quantity = quantity; } public string Name { get; init; } public float Amount { get; init; } - public Quantity Quantity { get; init; } } } diff --git a/Models/Quantity.cs b/Models/Quantity.cs deleted file mode 100644 index 51433d5..0000000 --- a/Models/Quantity.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Models -{ - public class Quantity - { - } -} diff --git a/Models/RecipeInfo.cs b/Models/RecipeInfo.cs index 4640626..b43580a 100644 --- a/Models/RecipeInfo.cs +++ b/Models/RecipeInfo.cs @@ -3,14 +3,17 @@ public class RecipeInfo { public string Name { get; init; } - public string Description { get; init; } + public uint CookTimeMins { get; init; } + + public uint Energy { get; init; } + public Uri Image { get; init; } public float AverageNote { get; init; } - public RecipeInfo(string name, string description, Uri image, float averageNote) + public RecipeInfo(string name, uint cookTimeMins, Uri image, float averageNote) { Name = name; - Description = description; + CookTimeMins = cookTimeMins; Image = image; AverageNote = averageNote; } diff --git a/Models/RecipeState.cs b/Models/RecipeState.cs new file mode 100644 index 0000000..87a137a --- /dev/null +++ b/Models/RecipeState.cs @@ -0,0 +1,22 @@ + + +namespace Models +{ + public class RecipeState + { + + public uint PersonAmount { get; private init; } + public bool IsAccountFavorite { get; private init; } + public uint AccountNote { get; private init; } + + public Recipe Recipe { get; private init; } + + public RecipeState(uint personAmount, bool isAccountFavorite, uint accountNote, Recipe recipe) + { + PersonAmount = personAmount; + IsAccountFavorite = isAccountFavorite; + AccountNote = accountNote; + Recipe = recipe; + } + } +} diff --git a/ShoopNCook.csproj b/ShoopNCook.csproj index 8f865ed..063bc5b 100644 --- a/ShoopNCook.csproj +++ b/ShoopNCook.csproj @@ -196,9 +196,7 @@ - - - + diff --git a/Views/Components/IngredientView.xaml.cs b/Views/Components/IngredientView.xaml.cs index 2013447..466d557 100644 --- a/Views/Components/IngredientView.xaml.cs +++ b/Views/Components/IngredientView.xaml.cs @@ -1,3 +1,5 @@ +using Models; + namespace ShoopNCook.Views; public partial class IngredientView : ContentView @@ -30,12 +32,13 @@ public partial class IngredientView : ContentView set => SetValue(UnitProperty, value); } - public IngredientView(string name, float quantity, string unit) + public IngredientView(Ingredient ingredient) { InitializeComponent(); - Name = name; - Quantity = quantity; - Unit = unit; + Name = ingredient.Name; + Quantity = ingredient.Amount; + //TODO Unit implementation in IngredientView.xaml.cs + Unit = "TODO: Unit implementation in IngredientView.xaml.cs"; } } \ No newline at end of file diff --git a/Views/Components/RecipeView.xaml.cs b/Views/Components/RecipeView.xaml.cs index e4ed079..c5248aa 100644 --- a/Views/Components/RecipeView.xaml.cs +++ b/Views/Components/RecipeView.xaml.cs @@ -5,14 +5,19 @@ namespace ShoopNCook.Views; public partial class RecipeView : ContentView { - public RecipeView(RecipeInfo info) + private readonly Action callback; + + public RecipeView(RecipeInfo info, Action onClickCallback) { InitializeComponent(); Note = info.AverageNote; Title = info.Name; - Subtitle = info.Description; + Subtitle = info.CookTimeMins + " min"; RecipeImage.Source = ImageSource.FromUri(info.Image); - } + + callback = onClickCallback; + + } public float Note { @@ -43,8 +48,8 @@ public partial class RecipeView : ContentView else img.Opacity = 1; } } - private async void OnRecipeTapped(object sender, EventArgs e) + private void OnRecipeTapped(object sender, EventArgs e) { - await Shell.Current.Navigation.PushAsync(new RecipePage()); + callback(); } } \ No newline at end of file diff --git a/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index 07d716a..aa2cf24 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -1,20 +1,16 @@ using Models; -namespace ShoopNCook.Pages; -using Models; -using ShoopNCook.Views; - -public partial class FavoritesPage : ContentPage -{ - public FavoritesPage(Account account, IApp app) - { - InitializeComponent(); - RecipeViewLayout.Children.Add(new RecipeView(new RecipeInfo("Chicken Curry", "45 min", new Uri("https://cdn.chefclub.tools/uploads/recipes/cover-thumbnail/f287b191-dc8e-4c85-bbb6-e26387c354d3.jpg"), 3))); - RecipeViewLayout.Children.Add(new RecipeView(new RecipeInfo("Spaghetti Bolognese", "30 min", 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))); - RecipeViewLayout.Children.Add(new RecipeView(new RecipeInfo("Beef Stroganoff", "10 min", new Uri("https://www.cookwithnabeela.com/wp-content/uploads/2023/02/BeefStroganoff.webp"), 5))); - RecipeViewLayout.Children.Add(new RecipeView(new RecipeInfo("Fish And Ships", "15 min", new Uri("https://upload.wikimedia.org/wikipedia/commons/f/ff/Fish_and_chips_blackpool.jpg"), 4))); - RecipeViewLayout.Children.Add(new RecipeView(new RecipeInfo("Caesar Salad", "20 min", new Uri("https://www.galbani.fr/wp-content/uploads/2020/04/AdobeStock_157570276-2.jpeg"), 1))); - - } - +namespace ShoopNCook.Pages; +using Models; +using ShoopNCook.Views; + +public partial class FavoritesPage : ContentPage +{ + public FavoritesPage(Account account, IApp app) + { + InitializeComponent(); + + //TODO + } + } \ No newline at end of file diff --git a/Views/HomePage.xaml b/Views/HomePage.xaml index e0fab49..38dcd43 100644 --- a/Views/HomePage.xaml +++ b/Views/HomePage.xaml @@ -62,7 +62,7 @@ Margin="20" HeightRequest="30">