From d269e2708cfd1976bf3755b6749cc7d5e9f6ce16 Mon Sep 17 00:00:00 2001 From: "maxime.BATISTA@etu.uca.fr" Date: Sun, 14 May 2023 12:12:10 +0200 Subject: [PATCH 1/4] add toolkit --- App.xaml.cs | 4 +-- ConnectAppShell.xaml.cs | 4 +-- ConsoleUserNotifier.cs | 31 --------------------- Controllers/ConnectionController.cs | 8 +++--- Controllers/MorePageController.cs | 4 +-- IApp.cs | 2 -- IUserNotifier.cs | 19 ------------- MainAppShell.xaml.cs | 6 ++--- MauiProgram.cs | 4 ++- ShoopNCook.csproj | 4 +++ UserNotifier.cs | 40 ++++++++++++++++++++++++++++ Views/Components/NoticePopup.xaml | 11 ++++++++ Views/Components/NoticePopup.xaml.cs | 9 +++++++ Views/CreateRecipePage.xaml.cs | 6 ++--- Views/FavoritesPage.xaml.cs | 6 ++--- Views/HomePage.xaml.cs | 4 +-- Views/MyListPage.xaml.cs | 6 ++--- Views/MyRecipesPage.xaml.cs | 17 +++++------- Views/RecipePage.xaml.cs | 10 +++---- 19 files changed, 97 insertions(+), 98 deletions(-) delete mode 100644 ConsoleUserNotifier.cs delete mode 100644 IUserNotifier.cs create mode 100644 UserNotifier.cs create mode 100644 Views/Components/NoticePopup.xaml create mode 100644 Views/Components/NoticePopup.xaml.cs diff --git a/App.xaml.cs b/App.xaml.cs index c873ce2..b769638 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -8,8 +8,6 @@ public partial class App : Application, ConnectionObserver, IApp private IEndpoint Endpoint = new LocalEndpoint(); - public IUserNotifier Notifier => new ConsoleUserNotifier(); - public App() { InitializeComponent(); @@ -25,7 +23,7 @@ public partial class App : Application, ConnectionObserver, IApp public void ForceLogin() { - Shell shell = new ConnectAppShell(this, Endpoint.AuthService, Notifier); + Shell shell = new ConnectAppShell(this, Endpoint.AuthService); shell.GoToAsync("//Splash"); MainPage = shell; } diff --git a/ConnectAppShell.xaml.cs b/ConnectAppShell.xaml.cs index dd44352..8e831eb 100644 --- a/ConnectAppShell.xaml.cs +++ b/ConnectAppShell.xaml.cs @@ -7,9 +7,9 @@ using ShoopNCook.Pages; public partial class ConnectAppShell : Shell { - public ConnectAppShell(ConnectionObserver observer, IAuthService accounts, IUserNotifier notifier) + public ConnectAppShell(ConnectionObserver observer, IAuthService accounts) { - ConnectionController controller = new ConnectionController(observer, accounts, notifier); + ConnectionController controller = new ConnectionController(observer, accounts); InitializeComponent(); LoginPage.ContentTemplate = new DataTemplate(() => new LoginPage(controller)); RegisterPage.ContentTemplate = new DataTemplate(() => new RegisterPage(controller)); diff --git a/ConsoleUserNotifier.cs b/ConsoleUserNotifier.cs deleted file mode 100644 index 1a06c28..0000000 --- a/ConsoleUserNotifier.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace ShoopNCook -{ - /// - /// A notice reporter implementation that prints in console the applications's user notices. - /// - public class ConsoleUserNotifier : - IUserNotifier - { - - public void Success(string message) - { - Console.WriteLine(" Success: " + message); - } - - - public void Error(string message) - { - Console.WriteLine(" Error: " + message); - } - - public void Notice(string message) - { - Console.WriteLine(" Notice: " + message); - } - - public void Warn(string message) - { - Console.WriteLine(" Warn: " + message); - } - } -} diff --git a/Controllers/ConnectionController.cs b/Controllers/ConnectionController.cs index 0e59bb7..5958a6a 100644 --- a/Controllers/ConnectionController.cs +++ b/Controllers/ConnectionController.cs @@ -7,11 +7,9 @@ namespace ShoopNCook.Controllers { private readonly ConnectionObserver observer; private readonly IAuthService accounts; - private readonly IUserNotifier notifier; - public ConnectionController(ConnectionObserver observer, IAuthService accounts, IUserNotifier notifier) { + public ConnectionController(ConnectionObserver observer, IAuthService accounts) { this.observer = observer; this.accounts = accounts; - this.notifier = notifier; } public void Login(string email, string password) @@ -19,7 +17,7 @@ namespace ShoopNCook.Controllers Account? acc = accounts.Login(email, password); if (acc == null) { - notifier.Error("Email or password invalid."); + UserNotifier.Error("Email or password invalid."); return; } observer.OnAccountConnected(acc); @@ -30,7 +28,7 @@ namespace ShoopNCook.Controllers Account? acc = accounts.Register(username, email, password); if (acc == null) { - notifier.Error("Invalid credentials."); + UserNotifier.Error("Invalid credentials."); return; } observer.OnAccountConnected(acc); diff --git a/Controllers/MorePageController.cs b/Controllers/MorePageController.cs index c8ecee8..5b5fd56 100644 --- a/Controllers/MorePageController.cs +++ b/Controllers/MorePageController.cs @@ -20,13 +20,13 @@ namespace ShoopNCook.Controllers public void Logout() { - app.Notifier.Notice("You have been loged out."); + UserNotifier.Notice("You have been loged out."); app.ForceLogin(); } public void GoToMyRecipesPage() { - Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService, app.Notifier)); + Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService)); } public void GoToProfilePage() diff --git a/IApp.cs b/IApp.cs index dad1336..bfc7b8f 100644 --- a/IApp.cs +++ b/IApp.cs @@ -9,8 +9,6 @@ namespace ShoopNCook { public interface IApp { - public IUserNotifier Notifier { get; } - public void ForceLogin(); } } diff --git a/IUserNotifier.cs b/IUserNotifier.cs deleted file mode 100644 index 4576a70..0000000 --- a/IUserNotifier.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShoopNCook -{ - public interface IUserNotifier - { - public void Success(string message); - - public void Notice(string message); - - public void Error(string message); - - public void Warn(string message); - } -} diff --git a/MainAppShell.xaml.cs b/MainAppShell.xaml.cs index d3f6bc1..decb72a 100644 --- a/MainAppShell.xaml.cs +++ b/MainAppShell.xaml.cs @@ -9,9 +9,9 @@ public partial class MainAppShell : Shell public MainAppShell(Account account, IEndpoint endpoint, IApp app) { InitializeComponent(); - HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, app.Notifier, endpoint)); - FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, app.Notifier, endpoint.RecipesService)); - MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, app.Notifier, endpoint.RecipesService)); + 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(account, endpoint, app))); } } diff --git a/MauiProgram.cs b/MauiProgram.cs index 7dc9f23..420e008 100644 --- a/MauiProgram.cs +++ b/MauiProgram.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using CommunityToolkit.Maui; +using Microsoft.Extensions.Logging; namespace ShoopNCook; @@ -9,6 +10,7 @@ public static class MauiProgram var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() + .UseMauiCommunityToolkit() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); diff --git a/ShoopNCook.csproj b/ShoopNCook.csproj index 8a80861..f6b7dbe 100644 --- a/ShoopNCook.csproj +++ b/ShoopNCook.csproj @@ -113,6 +113,7 @@ + @@ -142,6 +143,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile diff --git a/UserNotifier.cs b/UserNotifier.cs new file mode 100644 index 0000000..aa97bf2 --- /dev/null +++ b/UserNotifier.cs @@ -0,0 +1,40 @@ +using CommunityToolkit.Maui.Views; +using ShoopNCook.Views.Components; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook +{ + internal class UserNotifier + { + + private static void Show(NoticePopup popup) + { + var page = Shell.Current.CurrentPage; + page.ShowPopup(new Popup + { + Content = popup + }); + } + + public static void Error(string message) + { + Show(new NoticePopup()); + } + public static void Warn(string message) + { + Show(new NoticePopup()); + } + public static void Notice(string message) + { + Show(new NoticePopup()); + } + public static void Success(string message) + { + Show(new NoticePopup()); + } + } +} diff --git a/Views/Components/NoticePopup.xaml b/Views/Components/NoticePopup.xaml new file mode 100644 index 0000000..ab69bae --- /dev/null +++ b/Views/Components/NoticePopup.xaml @@ -0,0 +1,11 @@ + + + + + diff --git a/Views/Components/NoticePopup.xaml.cs b/Views/Components/NoticePopup.xaml.cs new file mode 100644 index 0000000..1957bc7 --- /dev/null +++ b/Views/Components/NoticePopup.xaml.cs @@ -0,0 +1,9 @@ +namespace ShoopNCook.Views.Components; + +public partial class NoticePopup : ContentView +{ + public NoticePopup() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Views/CreateRecipePage.xaml.cs b/Views/CreateRecipePage.xaml.cs index 8c5bea0..f6f468d 100644 --- a/Views/CreateRecipePage.xaml.cs +++ b/Views/CreateRecipePage.xaml.cs @@ -8,14 +8,12 @@ public partial class CreateRecipePage : ContentPage private User owner; private Action onRecipeCreated; - private IUserNotifier notifier; - public CreateRecipePage(User owner, IUserNotifier notifier, Action onRecipeCreated) + public CreateRecipePage(User owner, Action onRecipeCreated) { InitializeComponent(); this.owner = owner; this.onRecipeCreated = onRecipeCreated; - this.notifier = notifier; } private void OnAddIngredientTapped(object sender, TappedEventArgs e) @@ -53,7 +51,7 @@ public partial class CreateRecipePage : ContentPage if (hadErrors) { - notifier.Error("You need to fix input errors before upload."); + UserNotifier.Error("You need to fix input errors before upload."); return; } diff --git a/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index 20b9ef2..a02523e 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -10,14 +10,12 @@ public partial class FavoritesPage : ContentPage { private readonly Account account; - private readonly IUserNotifier notifier; private IRecipesService service; - public FavoritesPage(Account account, IUserNotifier notifier, IRecipesService service) + public FavoritesPage(Account account, IRecipesService service) { InitializeComponent(); this.account = account; - this.notifier = notifier; this.service = service; UpdateFavorites(); @@ -32,7 +30,7 @@ public partial class FavoritesPage : ContentPage RecipeViewLayout.Children.Add(new RecipeView(info, () => { Recipe recipe = service.GetRecipe(info); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); })); }); } diff --git a/Views/HomePage.xaml.cs b/Views/HomePage.xaml.cs index b74cfd2..333b718 100644 --- a/Views/HomePage.xaml.cs +++ b/Views/HomePage.xaml.cs @@ -7,7 +7,7 @@ using LocalEndpoint; public partial class HomePage : ContentPage { - public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint) + public HomePage(Account account, IEndpoint endpoint) { InitializeComponent(); @@ -21,7 +21,7 @@ public partial class HomePage : ContentPage layout.Children.Add(new RecipeView(info, () => { Recipe recipe = service.GetRecipe(info); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); })); } diff --git a/Views/MyListPage.xaml.cs b/Views/MyListPage.xaml.cs index 87cddb5..f6f8f08 100644 --- a/Views/MyListPage.xaml.cs +++ b/Views/MyListPage.xaml.cs @@ -9,15 +9,13 @@ public partial class MyListPage : ContentPage { private readonly IAccountRecipesPreferences preferences; - private readonly IUserNotifier notifier; private readonly IRecipesService service; - public MyListPage(Account account, IUserNotifier notifier, IRecipesService service) + public MyListPage(Account account, IRecipesService service) { InitializeComponent(); this.preferences = service.GetPreferencesOf(account); - this.notifier = notifier; this.service = service; UpdateMyList(); @@ -32,7 +30,7 @@ public partial class MyListPage : ContentPage RecipesLayout.Children.Add(new StoredRecipeView(info, tuple.Item2, amount => { Recipe recipe = service.GetRecipe(info); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, amount)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, amount)); })); }); } diff --git a/Views/MyRecipesPage.xaml.cs b/Views/MyRecipesPage.xaml.cs index 952d786..78bcc85 100644 --- a/Views/MyRecipesPage.xaml.cs +++ b/Views/MyRecipesPage.xaml.cs @@ -8,18 +8,15 @@ namespace ShoopNCook.Pages; public partial class MyRecipesPage : ContentPage { - private IUserNotifier notifier; private IRecipesService service; private Account account; public MyRecipesPage( Account account, - IRecipesService service, - IUserNotifier notifier) + IRecipesService service) { InitializeComponent(); - this.notifier = notifier; this.service = service; this.account = account; @@ -35,7 +32,7 @@ public partial class MyRecipesPage : ContentPage { Recipe recipe = service.GetRecipe(info); IAccountRecipesPreferences preferences = service.GetPreferencesOf(account); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); }, () => RemoveRecipe(info) )); @@ -47,7 +44,7 @@ public partial class MyRecipesPage : ContentPage if (!recipes.RemoveRecipe(info)) { - notifier.Error("Could not remove recipe"); + UserNotifier.Error("Could not remove recipe"); return; } foreach (OwnedRecipeView view in RecipesLayout.Children) @@ -58,7 +55,7 @@ public partial class MyRecipesPage : ContentPage break; } } - notifier.Success("Recipe successfully removed"); + UserNotifier.Success("Recipe successfully removed"); } private void OnBackButtonClicked(object sender, EventArgs e) @@ -69,14 +66,14 @@ public partial class MyRecipesPage : ContentPage { IAccountOwnedRecipes recipes = service.GetRecipesOf(account); - var page = new CreateRecipePage(account.User, notifier, recipe => + var page = new CreateRecipePage(account.User, recipe => { if (!recipes.UploadRecipe(recipe)) { - notifier.Error("Could not upload recipe."); + UserNotifier.Error("Could not upload recipe."); return; } - notifier.Success("Recipe Successfuly uploaded !"); + UserNotifier.Success("Recipe Successfuly uploaded !"); AddRecipeView(recipe.Info); Shell.Current.Navigation.PopAsync(); //go back to current recipe page. }); diff --git a/Views/RecipePage.xaml.cs b/Views/RecipePage.xaml.cs index 33531f3..583fa33 100644 --- a/Views/RecipePage.xaml.cs +++ b/Views/RecipePage.xaml.cs @@ -14,17 +14,15 @@ public partial class RecipePage : ContentPage private IAccountRecipesPreferences preferences; - private IUserNotifier notifier; private RecipeInfo info; public ICommand StarCommand => new Command(count => SetNote(uint.Parse(count))); - public RecipePage(Recipe recipe, IUserNotifier notifier, IAccountRecipesPreferences preferences, uint amount) + public RecipePage(Recipe recipe, IAccountRecipesPreferences preferences, uint amount) { InitializeComponent(); this.preferences = preferences; - this.notifier = notifier; this.info = recipe.Info; RecipeRate rate = preferences.GetRate(recipe.Info); @@ -89,15 +87,15 @@ public partial class RecipePage : ContentPage private void OnSubmitReviewClicked(object o, EventArgs e) { preferences.SetReviewScore(info, note); - notifier.Success("Your review has been successfuly submited"); + UserNotifier.Success("Your review has been successfuly submited"); } private void OnAddToMyListClicked(object o, EventArgs e) { if (!preferences.AddToWeeklyList(info, Counter.Count)) - notifier.Notice("You already added this recipe to you weekly list!"); + UserNotifier.Notice("You already added this recipe to you weekly list!"); else - notifier.Success("Recipe added to your weekly list."); + UserNotifier.Success("Recipe added to your weekly list."); } private void SetFavorite(bool isFavorite) From 6c61fbe1a46030fc874767a4d9041e0de9dddb06 Mon Sep 17 00:00:00 2001 From: Leo TUAILLON Date: Mon, 15 May 2023 11:46:29 +0200 Subject: [PATCH 2/4] user-notifier --- .editorconfig | 4 ++ ShoopNCook.sln | 7 +++- UserNotifier.cs | 62 ++++++++++++++++------------ Views/Components/NoticePopup.xaml | 3 +- Views/Components/NoticePopup.xaml.cs | 40 +++++++++++++++--- 5 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a0c05f8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS0618: Le type ou le membre est obsolète +dotnet_diagnostic.CS0618.severity = silent diff --git a/ShoopNCook.sln b/ShoopNCook.sln index 3b6c720..17d11be 100644 --- a/ShoopNCook.sln +++ b/ShoopNCook.sln @@ -10,7 +10,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalServices", "LocalServices\LocalServices.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6DEA92EF-71CD-4A21-9CC0-67F228E1155D}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/UserNotifier.cs b/UserNotifier.cs index aa97bf2..6846a0d 100644 --- a/UserNotifier.cs +++ b/UserNotifier.cs @@ -1,4 +1,6 @@ -using CommunityToolkit.Maui.Views; +using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Maui.Core; +using CommunityToolkit.Maui.Views; using ShoopNCook.Views.Components; using System; using System.Collections.Generic; @@ -8,33 +10,39 @@ using System.Threading.Tasks; namespace ShoopNCook { - internal class UserNotifier - { - - private static void Show(NoticePopup popup) - { - var page = Shell.Current.CurrentPage; - page.ShowPopup(new Popup - { - Content = popup - }); + internal class UserNotifier + { + private static async Task Show(string message, string messageType) + { + CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + + // Vous pouvez configurer la durée et la taille de police ici. + ToastDuration duration = ToastDuration.Short; + double fontSize = 14; + + var toast = Toast.Make(message, duration, fontSize); + + await toast.Show(cancellationTokenSource.Token); } - public static void Error(string message) - { - Show(new NoticePopup()); - } - public static void Warn(string message) - { - Show(new NoticePopup()); - } - public static void Notice(string message) - { - Show(new NoticePopup()); - } - public static void Success(string message) - { - Show(new NoticePopup()); - } + + + public static void Error(string message) + { + Show(message, "Error"); + } + public static void Warn(string message) + { + Show(message, "Warning"); + } + public static void Notice(string message) + { + Show(message, "Notice"); + } + public static void Success(string message) + { + Show(message, "Success"); + } } + } diff --git a/Views/Components/NoticePopup.xaml b/Views/Components/NoticePopup.xaml index ab69bae..d4ac661 100644 --- a/Views/Components/NoticePopup.xaml +++ b/Views/Components/NoticePopup.xaml @@ -1,10 +1,9 @@ - diff --git a/Views/Components/NoticePopup.xaml.cs b/Views/Components/NoticePopup.xaml.cs index 1957bc7..700634a 100644 --- a/Views/Components/NoticePopup.xaml.cs +++ b/Views/Components/NoticePopup.xaml.cs @@ -1,9 +1,39 @@ namespace ShoopNCook.Views.Components; +using Microsoft.Maui.Graphics; public partial class NoticePopup : ContentView { - public NoticePopup() - { - InitializeComponent(); - } -} \ No newline at end of file + public NoticePopup(string message, string messageType) + { + + InitializeComponent(); + MessageLabel.Text = message; + + switch (messageType) + { + case "Error": + this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Red; + break; + case "Warning": + this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Yellow; + break; + case "Notice": + this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Blue; + break; + case "Success": + this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Green; + break; + } + + // Display the toast for 3 seconds + + Device.StartTimer(TimeSpan.FromSeconds(3), () => + { + // Close the toast + // You need to replace this with your actual code to close the toast + this.IsVisible = false; + return false; + }); + + } +} From 036c3cd1cd25c8981c13668003e2502d68ceddee Mon Sep 17 00:00:00 2001 From: letuaillon Date: Fri, 26 May 2023 09:45:13 +0200 Subject: [PATCH 3/4] final toasts --- Resources/Images/error.png | Bin 0 -> 826 bytes Resources/Images/notice.png | Bin 0 -> 499 bytes Resources/Images/success.png | Bin 0 -> 812 bytes Resources/Images/warning.png | Bin 0 -> 633 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Resources/Images/error.png create mode 100644 Resources/Images/notice.png create mode 100644 Resources/Images/success.png create mode 100644 Resources/Images/warning.png diff --git a/Resources/Images/error.png b/Resources/Images/error.png new file mode 100644 index 0000000000000000000000000000000000000000..57c47ae52fafdd7155ee81f994bf909d5723dcd9 GIT binary patch literal 826 zcmV-A1I7G_P)Px%^hrcPRA@u(nTt&vK@5gXC4owkR6?jENhL`t2~-lO1oWTQC*$>d?s7Vbkyaeq z9gjc1=5<3?-fpg3fBFEpv82*3Gx-XQT8&kGSfZqG9RDgY~ezbV{N z2rz$$==TQJ>3jTk1>gq}eIJebz7vB$Ub{^Iz7Wx0V}GVl@_ht%gS)U=2Z zNEg7eItKo^g+j-I0QyBlFo)09KcSLGgzZBqL-3ggpfqtqP!(M~Hk) zrPn{;Vjy#>1W^IdVbgMPo#F6hd#nsVC+s9#CQuT3KHizVHHc;AP2C4-bHa<3rE- zEBPViV+_wgvig}u@&IJ)d%{OmW2^b_8n>uiYA@_^!2^)tlO=km^l8giYJC{WmU6HT z212V0Q1!$_dB_gK$O4c9g*8}ZbmWPt@)$yf(Jmh?07)Fhzf~bE2yAewF>lFi1IPqM z((FoCQrn|_LNz4i5SSC76WVT4vpmpAV2{Oum?#hV7Xi>Q4@D-E9UI6ss^x*z5VDkK zMJ5n!53D4yRc&wzA=mj`h;|Z7B|23oDwUndPUlrPFJ%*1bqQUm^HYd$Ua|nfm@~>w zMS1Qvfe3TbTjx~spriZ*LWYkS4IV&cGozQ&ojR{QQCUu#@;v|m7$ z1~PSxmdet7(Z2K?Tgr45%2tQ~;05FYA2>~{oGhE%*ZLgF)ic|yNH44|2dXgD{5Z(V z0IHjns&d(P?J`>dupp`vT&A#mKRUjw0$694(^F{;WgYI84O9j2CL!KrOiro)`|&zM zSQcXtSnf$&Zoo_Wf&>3sH#?)_`mP5U!V0NQyz6hfOYCF+DS!sSwUNGQ$$&;zN?PbD zfRqQX00J=CHS5yNq#X2=0GY+l^8N$hEM{#8y?PJ40mdThF||5hwg3PC07*qoM6N<$ Ef?Zx`NdN!< literal 0 HcmV?d00001 diff --git a/Resources/Images/notice.png b/Resources/Images/notice.png new file mode 100644 index 0000000000000000000000000000000000000000..85c3bfe1467d924cdb5df26b6fe2196058a1d4ef GIT binary patch literal 499 zcmVPx$tw}^dRA@u(nT<`uKn#UnH=&!rB+yBKNq|WTlfWjRCvuW?O1bl&%1O3VsZx^0 z-+Q)my&SN392U84`<<2Q|3G5jFuQ!Jm zV6RzOCLddwFnI<6_+fd`EeYg;@BsA6Gg*$xQGM@~n;F6iKm|XA@0JnSyLa3kda81= z0!a0#Ja29ZiqOi*@EJ^h=`wsweD5!g?00K&=92hlOe>}R0%Ykx0t3Y>t zm5^4zYT_y(p+GGqYANyipSW!hq^w52wPPyy{6EWlrUweZ>4@6_=lydppDCf-44l87 z0U&qV`t;OOX2h2Pu(xB~@=$M^Tmyh}oeRGHoj|zygv)S%zsuy?8ykM7^4!I1?+Zr4 pP9M(#m`=cZVgYy+^j^Qb13x$!fib60XIuaP002ovPDHLkV1l^S(zpNs literal 0 HcmV?d00001 diff --git a/Resources/Images/success.png b/Resources/Images/success.png new file mode 100644 index 0000000000000000000000000000000000000000..1bd8d589ee225fa432ba9b553205518f105a90b9 GIT binary patch literal 812 zcmV+{1JnG8P)Px%=1D|BRA@u(nT<^YF${&>Nq|X!Nq|X!Nq|X!Nq|W}55>s%?AUScT2*SKs-WvR z{_N-c?&!$d?#TV86TqP}xMl{E zR@Bk)W0S&21OfC!LnQD-nebe>r?1f+y)m@NYM5ZYW@HofFX2-Mm|1wb0v zr}I4I$`Q(~hh7H01vLs55c_OWzQ_W6;AP35A07bcv93YeI{Fxa7LK*P<>+VDp9dhd zzh(4!GUGW#XIN)pQ41b`luuOXRaxno*wcAe%9eAG4kUz@noJ4=)-uAAYF9=UfYg6? z3@$isjWAK2Nf|95EdWWpw*E&V&+!=skOhpQ@kR(oN~O$_U1zV%C|!;nnP^h2D>wzV?>NGJV~BX>m~( zy%ug}V4w$pEWik_dA3?wTOj%z%JnnatjH{&qeC34bmbcX!0F+`rbru|=fizv04#{v z;V~ndR3BLY>+G_6Dy^Nj4tG<|M@4K!$va-JoKo-oc%6Z)i1BU-k$V@H8_1Hr;K2XZ z%}(jKJ}V)e4NFoJwOb$EssQXPgJ9;>H!TrR=}Ji(oduBg00RiX@O_v(Hk8+_Q#X^c q(=`F2h;Q=z1h7e12aFzl27UnTxY#kWkK$qg0000Px%Gf6~2RA@u(nBh$WF${&>O<)t)1SSC{flXkO!X%(4T`FU8v7I~%Rl5A@wbz_K zJAQe&lU(^YU3vU+0Q`3at1ED~0e)10Rs)>3!0$!mvjUEfRZXy0Q9n7R)q?HcM-Abqp#7>w7~{Ipa9Sr$7g(p%3wT-$Qz4* z4e+f3(`#P$1mu(^t4shJBveNas8Xu}t)W=}wsCs_T4kchDhuFML>{(uV~N=8w@T2f zzyPq>$NJv$KD{PivKR~iomB+x$)v6p?uRN(L#zVWbsd=x71Of1)XH$z>brwMTojuv~0I)Q56<{xrh}4(?h)Q7u z0QW$Z+73OE;4atX!01(ttLuUcJ#?@Jh0xZdD2Eda|TjD5ytpcvYJ}Co`$v%R} z0N92OZ*Eb5jNfUM$O6C&qM`L+$h8gsQLy zFe95ikQT(uyP%MG>;WvhL{c-j$Il+X%rTJ^@1JR0pJV|Tjmw4^%BltEy%uK&v^w7} zpQHgsuf9M!lMGogwb!m`U?C2(siaW Ti8&>W00000NkvXXu0mjfy{sD! literal 0 HcmV?d00001 From fdca99b5890451dbff448707ab80e62d0d14ddd4 Mon Sep 17 00:00:00 2001 From: Maxime BATISTA Date: Fri, 26 May 2023 10:36:03 +0200 Subject: [PATCH 4/4] add nullchecks for user's entry in login and register pages --- Controllers/ConnectionController.cs | 25 +++++++++++++++++++++++++ Views/CreateRecipePage.xaml.cs | 8 ++++---- Views/FavoritesPage.xaml.cs | 4 ++-- Views/HomePage.xaml.cs | 5 +---- Views/LoginPage.xaml.cs | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Controllers/ConnectionController.cs b/Controllers/ConnectionController.cs index 5958a6a..8d1ebb8 100644 --- a/Controllers/ConnectionController.cs +++ b/Controllers/ConnectionController.cs @@ -14,6 +14,16 @@ namespace ShoopNCook.Controllers public void Login(string email, string password) { + if (email == null) + { + UserNotifier.Notice("Please provide an email address"); + return; + } + if (password == null) + { + UserNotifier.Notice("Please provide your password"); + return; + } Account? acc = accounts.Login(email, password); if (acc == null) { @@ -25,6 +35,21 @@ namespace ShoopNCook.Controllers public void Register(string username, string email, string password) { + if (email == null) + { + UserNotifier.Notice("Please provide an email address"); + return; + } + if (password == null) + { + UserNotifier.Notice("Please provide your password"); + return; + } + if (username == null) + { + UserNotifier.Notice("Please provide an username"); + return; + } Account? acc = accounts.Register(username, email, password); if (acc == null) { diff --git a/Views/CreateRecipePage.xaml.cs b/Views/CreateRecipePage.xaml.cs index f39d3f7..d5bf8ec 100644 --- a/Views/CreateRecipePage.xaml.cs +++ b/Views/CreateRecipePage.xaml.cs @@ -16,21 +16,21 @@ public partial class CreateRecipePage : ContentPage this.onRecipeCreated = onRecipeCreated; } - private async void OnAddIngredientTapped(object sender, TappedEventArgs e) + private void OnAddIngredientTapped(object sender, TappedEventArgs e) { IngredientList.Children.Add(new IngredientEntry()); } - private async void OnAddStepTapped(object sender, TappedEventArgs e) + private void OnAddStepTapped(object sender, TappedEventArgs e) { StepList.Children.Add(new StepEntry((uint) StepList.Children.Count() + 1)); } private async void OnBackButtonClicked(object sender, EventArgs e) { - Navigation.PopAsync(); + await Navigation.PopAsync(); } - private async void OnUploadRecipeClicked(object sender, EventArgs e) + private void OnUploadRecipeClicked(object sender, EventArgs e) { uint callPerPers; diff --git a/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index 4bdda6e..9bf6cae 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -29,13 +29,13 @@ public partial class FavoritesPage : ContentPage { RecipeViewLayout.Children.Add(new RecipeView(info, async () => { - Recipe? recipe = service.GetRecipe(info); + Recipe recipe = service.GetRecipe(info); await Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); })); }); } - private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) + private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) { UpdateFavorites(); } diff --git a/Views/HomePage.xaml.cs b/Views/HomePage.xaml.cs index f38fb0f..e4b1233 100644 --- a/Views/HomePage.xaml.cs +++ b/Views/HomePage.xaml.cs @@ -19,7 +19,7 @@ public partial class HomePage : ContentPage { layout.Children.Add(new RecipeView(info, () => { - Recipe? recipe = service.GetRecipe(info); + Recipe recipe = service.GetRecipe(info); if (recipe != null) Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); else @@ -36,9 +36,6 @@ public partial class HomePage : ContentPage ProfilePictureName.Text = account.User.Name; } - - - private async void OnSyncButtonClicked(object sender, EventArgs e) { await Shell.Current.Navigation.PushAsync(new SearchPage()); diff --git a/Views/LoginPage.xaml.cs b/Views/LoginPage.xaml.cs index 6d2293a..c3eaeb8 100644 --- a/Views/LoginPage.xaml.cs +++ b/Views/LoginPage.xaml.cs @@ -11,7 +11,7 @@ public partial class LoginPage : ContentPage InitializeComponent(); this.controller = controller; } - private async void OnLoginButtonClicked(object sender, EventArgs e) + private void OnLoginButtonClicked(object sender, EventArgs e) { string email = EmailEntry.Text; string password = PasswordEntry.Text;