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)