add toolkit
continuous-integration/drone/push Build is passing Details

pull/55/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent 211f313bce
commit d269e2708c

@ -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;
}

@ -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));

@ -1,31 +0,0 @@
namespace ShoopNCook
{
/// <summary>
/// A notice reporter implementation that prints in console the applications's user notices.
/// </summary>
public class ConsoleUserNotifier :
IUserNotifier
{
public void Success(string message)
{
Console.WriteLine("<User Notice> Success: " + message);
}
public void Error(string message)
{
Console.WriteLine("<User Notice> Error: " + message);
}
public void Notice(string message)
{
Console.WriteLine("<User Notice> Notice: " + message);
}
public void Warn(string message)
{
Console.WriteLine("<User Notice> Warn: " + message);
}
}
}

@ -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);

@ -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()

@ -9,8 +9,6 @@ namespace ShoopNCook
{
public interface IApp
{
public IUserNotifier Notifier { get; }
public void ForceLogin();
}
}

@ -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);
}
}

@ -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)));
}
}

@ -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<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");

@ -113,6 +113,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
</ItemGroup>
@ -142,6 +143,9 @@
<MauiXaml Update="ConnectAppShell.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\Components\NoticePopup.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\CreateRecipePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -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());
}
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Views.Components.NoticePopup">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>

@ -0,0 +1,9 @@
namespace ShoopNCook.Views.Components;
public partial class NoticePopup : ContentView
{
public NoticePopup()
{
InitializeComponent();
}
}

@ -8,14 +8,12 @@ public partial class CreateRecipePage : ContentPage
private User owner;
private Action<Recipe> onRecipeCreated;
private IUserNotifier notifier;
public CreateRecipePage(User owner, IUserNotifier notifier, Action<Recipe> onRecipeCreated)
public CreateRecipePage(User owner, Action<Recipe> 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;
}

@ -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));
}));
});
}

@ -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));
}));
}

@ -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));
}));
});
}

@ -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.
});

@ -14,17 +14,15 @@ public partial class RecipePage : ContentPage
private IAccountRecipesPreferences preferences;
private IUserNotifier notifier;
private RecipeInfo info;
public ICommand StarCommand => new Command<string>(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)

Loading…
Cancel
Save