From 6ac6c731d0588141efae0a2fbf1436846bd04649 Mon Sep 17 00:00:00 2001 From: "maxime.BATISTA@etu.uca.fr" Date: Tue, 9 May 2023 22:14:59 +0200 Subject: [PATCH 1/6] split AppShell in MainAppShell and ConnectAppShell --- App.xaml.cs | 20 +- ConnectAppShell.xaml | 31 ++ AppShell.xaml.cs => ConnectAppShell.xaml.cs | 8 +- LocalEndpoint/Class1.cs | 7 + LocalEndpoint/LocalEndpoint.csproj | 13 + AppShell.xaml => MainAppShell.xaml | 49 +-- MainAppShell.xaml.cs | 11 + MauiProgram.cs | 1 - Models/Account.cs | 2 +- Models/{API => Endpoint}/IAccountManager.cs | 30 +- Models/{API => Endpoint}/IEndpoint.cs | 32 +- Models/{API => Endpoint}/ISearchEngine.cs | 26 +- Models/Ingredient.cs | 6 +- Models/Models.csproj | 9 + Models/PreparationStep.cs | 7 +- Models/Quantity.cs | 3 +- Models/Recipe.cs | 3 +- Models/RecipeInfo.cs | 3 +- Models/User.cs | 7 +- ShoopNCook.csproj | 369 +++++++++++--------- ShoopNCook.sln | 14 +- Views/LoginPage.xaml.cs | 2 +- Views/RegisterPage.xaml | 2 - Views/Splash.xaml.cs | 2 - 24 files changed, 355 insertions(+), 302 deletions(-) create mode 100644 ConnectAppShell.xaml rename AppShell.xaml.cs => ConnectAppShell.xaml.cs (51%) create mode 100644 LocalEndpoint/Class1.cs create mode 100644 LocalEndpoint/LocalEndpoint.csproj rename AppShell.xaml => MainAppShell.xaml (55%) create mode 100644 MainAppShell.xaml.cs rename Models/{API => Endpoint}/IAccountManager.cs (83%) rename Models/{API => Endpoint}/IEndpoint.cs (85%) rename Models/{API => Endpoint}/ISearchEngine.cs (82%) create mode 100644 Models/Models.csproj diff --git a/App.xaml.cs b/App.xaml.cs index 3fa94c2..e77a22c 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,23 +1,17 @@ -namespace ShoopNCook; -using ShoopNCook.Pages; -using ShoopNCook.Models; -using ShoopNCook.Models.API; +namespace ShoopNCook; +using ShoopNCook.Pages; +using Models; public partial class App : Application { + public App() { InitializeComponent(); - Account account = getUserAccount(); - - var appShell = new AppShell(); - MainPage = appShell; - appShell.GoToAsync("//Splash"); + Shell main = new ConnectAppShell(); + main.GoToAsync("//Splash"); + MainPage = main; } - private Account getUserAccount() - { - return new Account(new User(new Uri("https://www.pngkey.com/png/full/115-1150152_default-profile-picture-avatar-png-green.png"), "Stub Account"), "test@example.com"); - } } \ No newline at end of file diff --git a/ConnectAppShell.xaml b/ConnectAppShell.xaml new file mode 100644 index 0000000..5a68f99 --- /dev/null +++ b/ConnectAppShell.xaml @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AppShell.xaml.cs b/ConnectAppShell.xaml.cs similarity index 51% rename from AppShell.xaml.cs rename to ConnectAppShell.xaml.cs index 373ef48..d3568ea 100644 --- a/AppShell.xaml.cs +++ b/ConnectAppShell.xaml.cs @@ -1,13 +1,11 @@ namespace ShoopNCook; -using ShoopNCook.Pages; using Microsoft.Maui.Controls; +using Models; - -public partial class AppShell : Shell +public partial class ConnectAppShell : Shell { - public AppShell() + public ConnectAppShell() { InitializeComponent(); - } } diff --git a/LocalEndpoint/Class1.cs b/LocalEndpoint/Class1.cs new file mode 100644 index 0000000..29fb9ea --- /dev/null +++ b/LocalEndpoint/Class1.cs @@ -0,0 +1,7 @@ +namespace LocalEndpoint +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/LocalEndpoint/LocalEndpoint.csproj b/LocalEndpoint/LocalEndpoint.csproj new file mode 100644 index 0000000..e45d1d7 --- /dev/null +++ b/LocalEndpoint/LocalEndpoint.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/AppShell.xaml b/MainAppShell.xaml similarity index 55% rename from AppShell.xaml rename to MainAppShell.xaml index ea876cf..549c9f7 100644 --- a/AppShell.xaml +++ b/MainAppShell.xaml @@ -1,9 +1,8 @@ + + - - + - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MainAppShell.xaml.cs b/MainAppShell.xaml.cs new file mode 100644 index 0000000..4bc1297 --- /dev/null +++ b/MainAppShell.xaml.cs @@ -0,0 +1,11 @@ +namespace ShoopNCook; +using Microsoft.Maui.Controls; +using Models; + +public partial class MainAppShell : Shell +{ + public MainAppShell() + { + InitializeComponent(); + } +} diff --git a/MauiProgram.cs b/MauiProgram.cs index c09f521..7dc9f23 100644 --- a/MauiProgram.cs +++ b/MauiProgram.cs @@ -16,7 +16,6 @@ public static class MauiProgram fonts.AddFont("Poppins-Bold.ttf", "PoppinsBold"); fonts.AddFont("Poppins-Regular.ttf", "Poppins"); fonts.AddFont("Poppins-Medium.ttf", "PoppinsMedium"); - fonts.AddFont("Poppins-Regular.ttf", "Poppins"); }); #if DEBUG builder.Logging.AddDebug(); diff --git a/Models/Account.cs b/Models/Account.cs index 75aac63..6d5a31c 100644 --- a/Models/Account.cs +++ b/Models/Account.cs @@ -1,4 +1,4 @@ -namespace ShoopNCook.Models +namespace Models { public class Account { diff --git a/Models/API/IAccountManager.cs b/Models/Endpoint/IAccountManager.cs similarity index 83% rename from Models/API/IAccountManager.cs rename to Models/Endpoint/IAccountManager.cs index 107270f..d3adc77 100644 --- a/Models/API/IAccountManager.cs +++ b/Models/Endpoint/IAccountManager.cs @@ -1,15 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShoopNCook.Models.API -{ - public interface IAccountManager - { - public Account login(string email, string password); - - - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Models.Endpoint +{ + public interface IAccountManager + { + public Account login(string email, string password); + + + } +} diff --git a/Models/API/IEndpoint.cs b/Models/Endpoint/IEndpoint.cs similarity index 85% rename from Models/API/IEndpoint.cs rename to Models/Endpoint/IEndpoint.cs index d569f21..397ac9b 100644 --- a/Models/API/IEndpoint.cs +++ b/Models/Endpoint/IEndpoint.cs @@ -1,16 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShoopNCook.Models.API -{ - public interface IEndpoint - { - public IAccountManager AccountManager { get; } - public ISearchEngine SearchEngine { get; } - - } -} - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Models.Endpoint +{ + public interface IEndpoint + { + public IAccountManager AccountManager { get; } + public ISearchEngine SearchEngine { get; } + + } +} + diff --git a/Models/API/ISearchEngine.cs b/Models/Endpoint/ISearchEngine.cs similarity index 82% rename from Models/API/ISearchEngine.cs rename to Models/Endpoint/ISearchEngine.cs index 130951d..5f4e533 100644 --- a/Models/API/ISearchEngine.cs +++ b/Models/Endpoint/ISearchEngine.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShoopNCook.Models.API -{ - public interface ISearchEngine - { - //TODO define methods to search recipes - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Models.Endpoint +{ + public interface ISearchEngine + { + //TODO define methods to search recipes + } +} diff --git a/Models/Ingredient.cs b/Models/Ingredient.cs index 26e90d5..48f1f21 100644 --- a/Models/Ingredient.cs +++ b/Models/Ingredient.cs @@ -1,10 +1,10 @@ - -namespace ShoopNCook.Models +namespace Models { public class Ingredient { - public Ingredient(string name, float amount, Quantity quantity) { + public Ingredient(string name, float amount, Quantity quantity) + { Name = name; Amount = amount; Quantity = quantity; diff --git a/Models/Models.csproj b/Models/Models.csproj new file mode 100644 index 0000000..cfadb03 --- /dev/null +++ b/Models/Models.csproj @@ -0,0 +1,9 @@ + + + + net7.0 + enable + enable + + + diff --git a/Models/PreparationStep.cs b/Models/PreparationStep.cs index ffb3ae7..d85cf91 100644 --- a/Models/PreparationStep.cs +++ b/Models/PreparationStep.cs @@ -1,13 +1,12 @@ - -namespace ShoopNCook.Models +namespace Models { public class PreparationStep { public PreparationStep(string name, string description) { - this.Name = name; - this.Description = description; + Name = name; + Description = description; } public string Name { get; init; } diff --git a/Models/Quantity.cs b/Models/Quantity.cs index e7516ff..51433d5 100644 --- a/Models/Quantity.cs +++ b/Models/Quantity.cs @@ -1,5 +1,4 @@ - -namespace ShoopNCook.Models +namespace Models { public class Quantity { diff --git a/Models/Recipe.cs b/Models/Recipe.cs index c5963d8..15d09ae 100644 --- a/Models/Recipe.cs +++ b/Models/Recipe.cs @@ -1,5 +1,4 @@ - -namespace ShoopNCook.Models +namespace Models { public class Recipe { diff --git a/Models/RecipeInfo.cs b/Models/RecipeInfo.cs index ba37ea1..4640626 100644 --- a/Models/RecipeInfo.cs +++ b/Models/RecipeInfo.cs @@ -1,5 +1,4 @@ - -namespace ShoopNCook.Models +namespace Models { public class RecipeInfo { diff --git a/Models/User.cs b/Models/User.cs index c9893c7..2f19f35 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -1,5 +1,4 @@ - -namespace ShoopNCook.Models +namespace Models { public class User { @@ -10,7 +9,7 @@ namespace ShoopNCook.Models Name = name; } - public Uri ProfilePicture { get; init; } - public string Name { get; init; } + public Uri ProfilePicture { get; init; } + public string Name { get; init; } } } diff --git a/ShoopNCook.csproj b/ShoopNCook.csproj index e727121..cff5220 100644 --- a/ShoopNCook.csproj +++ b/ShoopNCook.csproj @@ -1,174 +1,203 @@ - - - - net7.0;net7.0-android - $(TargetFrameworks);net7.0-windows10.0.19041.0 - - - Exe - ShoopNCook - true - true - enable - - - ShoopNCook - - - com.companyname.shoopncook - bf17e1fe-a722-42f6-a24d-3327d351c924 - - - 1.0 - 1 - - 11.0 - 13.1 - 21.0 - 10.0.17763.0 - 10.0.17763.0 - 6.5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MyListPage.xaml - + + + + net7.0;net7.0-android + $(TargetFrameworks);net7.0-windows10.0.19041.0 + + + Exe + ShoopNCook + true + true + enable + + + ShoopNCook + + + com.companyname.shoopncook + bf17e1fe-a722-42f6-a24d-3327d351c924 + + + 1.0 + 1 + + 11.0 + 13.1 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ConnectAppShell.xaml + + + MainAppShell.xaml + + + MyListPage.xaml + IngredientEntry.xaml - - - - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - - - MSBuild:Compile - + + + + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + MSBuild:Compile - - - MSBuild:Compile - - - - - - - - - - + + + MSBuild:Compile + + + + + + + + + + diff --git a/ShoopNCook.sln b/ShoopNCook.sln index 7ffa604..f0e9130 100644 --- a/ShoopNCook.sln +++ b/ShoopNCook.sln @@ -4,7 +4,11 @@ VisualStudioVersion = 17.0.31611.283 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShoopNCook", "ShoopNCook.csproj", "{8ED2FB1D-C04D-478D-9271-CC91FE110396}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{E50D92DC-0BB1-4998-B085-EF47C55675AC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{E50D92DC-0BB1-4998-B085-EF47C55675AC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalEndpoint", "LocalEndpoint\LocalEndpoint.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -22,6 +26,14 @@ Global {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.Build.0 = Debug|Any CPU {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.ActiveCfg = Release|Any CPU {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.Build.0 = Release|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.Build.0 = Release|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Views/LoginPage.xaml.cs b/Views/LoginPage.xaml.cs index 3e6250e..44b5208 100644 --- a/Views/LoginPage.xaml.cs +++ b/Views/LoginPage.xaml.cs @@ -22,6 +22,6 @@ public partial class LoginPage : ContentPage } private async void RegisterLabbelTapped(object sender, EventArgs e) { - await Shell.Current.GoToAsync("//RegisterPage"); + await Shell.Current.Navigation.PushAsync(new RegisterPage()); } } \ No newline at end of file diff --git a/Views/RegisterPage.xaml b/Views/RegisterPage.xaml index 92f4313..a7ca053 100644 --- a/Views/RegisterPage.xaml +++ b/Views/RegisterPage.xaml @@ -84,8 +84,6 @@ - - Date: Wed, 10 May 2023 09:56:21 +0200 Subject: [PATCH 2/6] Implement stub endpoints and stub login logic --- App.xaml.cs | 19 ++++- ConnectAppShell.xaml | 6 +- ConnectAppShell.xaml.cs | 10 ++- ConnectionObserver.cs | 14 ++++ Controllers/ConnectionController.cs | 26 ++++++ Controllers/LoginController.cs | 13 +++ Controllers/RegisterController.cs | 13 +++ LocalEndpoint/AccountManager.cs | 34 ++++++++ LocalEndpoint/Class1.cs | 7 -- LocalEndpoint/LocalEndpoint.cs | 11 +++ LocalEndpoint/LocalEndpoint.csproj | 2 +- MainAppShell.xaml | 18 ----- MainAppShell.xaml.cs | 2 +- Models/{Endpoint => API}/IAccountManager.cs | 4 +- Models/{Endpoint => API}/IEndpoint.cs | 0 Models/{Endpoint => API}/ISearchEngine.cs | 0 Platforms/Android/AndroidManifest.xml | 2 +- ShoopNCook.csproj | 7 +- ShoopNCook.sln | 88 ++++++++++----------- Views/Components/RecipeView.xaml | 2 +- Views/LoginPage.xaml | 6 +- Views/LoginPage.xaml.cs | 19 ++--- Views/MorePage.xaml.cs | 2 +- Views/RegisterPage.xaml | 9 ++- Views/RegisterPage.xaml.cs | 15 +++- Views/Splash.xaml.cs | 2 +- 26 files changed, 220 insertions(+), 111 deletions(-) create mode 100644 ConnectionObserver.cs create mode 100644 Controllers/ConnectionController.cs create mode 100644 Controllers/LoginController.cs create mode 100644 Controllers/RegisterController.cs create mode 100644 LocalEndpoint/AccountManager.cs delete mode 100644 LocalEndpoint/Class1.cs create mode 100644 LocalEndpoint/LocalEndpoint.cs rename Models/{Endpoint => API}/IAccountManager.cs (58%) rename Models/{Endpoint => API}/IEndpoint.cs (100%) rename Models/{Endpoint => API}/ISearchEngine.cs (100%) diff --git a/App.xaml.cs b/App.xaml.cs index e77a22c..031cc02 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,17 +1,28 @@ namespace ShoopNCook; using ShoopNCook.Pages; using Models; +using Models.Endpoint; +using LocalEndpoint; -public partial class App : Application +public partial class App : Application, ConnectionObserver { + private IEndpoint endpoint = new LocalEndpoint(); + public App() { InitializeComponent(); - Shell main = new ConnectAppShell(); - main.GoToAsync("//Splash"); - MainPage = main; + + Shell shell = new ConnectAppShell(this, endpoint.AccountManager); + shell.GoToAsync("//Splash"); + MainPage = shell; } + public void OnAccountConnected(Account account) + { + Shell shell = new MainAppShell(account); + shell.GoToAsync("//MainPage"); + MainPage = shell; + } } \ No newline at end of file diff --git a/ConnectAppShell.xaml b/ConnectAppShell.xaml index 5a68f99..6fb0bb9 100644 --- a/ConnectAppShell.xaml +++ b/ConnectAppShell.xaml @@ -19,13 +19,11 @@ + Route="Login"/> + Route="Register"/> \ No newline at end of file diff --git a/ConnectAppShell.xaml.cs b/ConnectAppShell.xaml.cs index d3568ea..8cc6953 100644 --- a/ConnectAppShell.xaml.cs +++ b/ConnectAppShell.xaml.cs @@ -1,11 +1,17 @@ namespace ShoopNCook; using Microsoft.Maui.Controls; using Models; - +using Models.Endpoint; +using ShoopNCook.Controllers; +using ShoopNCook.Pages; + public partial class ConnectAppShell : Shell { - public ConnectAppShell() + public ConnectAppShell(ConnectionObserver observer, IAccountManager accounts) { + ConnectionController controller = new ConnectionController(observer, accounts); InitializeComponent(); + LoginPage.ContentTemplate = new DataTemplate(() => new LoginPage(controller)); + RegisterPage.ContentTemplate = new DataTemplate(() => new RegisterPage(controller)); } } diff --git a/ConnectionObserver.cs b/ConnectionObserver.cs new file mode 100644 index 0000000..e4955f7 --- /dev/null +++ b/ConnectionObserver.cs @@ -0,0 +1,14 @@ +using Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook +{ + public interface ConnectionObserver + { + public void OnAccountConnected(Account account); + } +} diff --git a/Controllers/ConnectionController.cs b/Controllers/ConnectionController.cs new file mode 100644 index 0000000..8aa7803 --- /dev/null +++ b/Controllers/ConnectionController.cs @@ -0,0 +1,26 @@ +using Models.Endpoint; +using Models; + +namespace ShoopNCook.Controllers +{ + public class ConnectionController : LoginController, RegisterController + { + private readonly ConnectionObserver observer; + private readonly IAccountManager accounts; + public ConnectionController(ConnectionObserver observer, IAccountManager accounts) { + this.observer = observer; + this.accounts = accounts; + } + public void Login(string email, string password) + { + Account acc = accounts.Login(email, password); + observer.OnAccountConnected(acc); + } + + public void Register(string username, string email, string password) + { + Account acc = accounts.Register(username, email, password); + observer.OnAccountConnected(acc); + } + } +} diff --git a/Controllers/LoginController.cs b/Controllers/LoginController.cs new file mode 100644 index 0000000..2006643 --- /dev/null +++ b/Controllers/LoginController.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook.Controllers +{ + public interface LoginController + { + public void Login(string email, string password); + } +} diff --git a/Controllers/RegisterController.cs b/Controllers/RegisterController.cs new file mode 100644 index 0000000..b73b075 --- /dev/null +++ b/Controllers/RegisterController.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook.Controllers +{ + public interface RegisterController + { + public void Register(string username, string email, string password); + } +} diff --git a/LocalEndpoint/AccountManager.cs b/LocalEndpoint/AccountManager.cs new file mode 100644 index 0000000..5f79089 --- /dev/null +++ b/LocalEndpoint/AccountManager.cs @@ -0,0 +1,34 @@ +using Models; +using Models.Endpoint; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LocalEndpoint +{ + internal class AccountManager : IAccountManager + { + private static readonly Uri DEFAULT_ACCOUNT_IMAGE = new Uri("https://www.pngkey.com/png/full/115-1150152_default-profile-picture-avatar-png-green.png"); + + 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) + { + return userAccount; + } + return null; + } + + public Account? Register(string email, string username, string password) + { + userAccount = new Account(new User(DEFAULT_ACCOUNT_IMAGE, username), email); + userPassword = password; + return userAccount; + } + } +} diff --git a/LocalEndpoint/Class1.cs b/LocalEndpoint/Class1.cs deleted file mode 100644 index 29fb9ea..0000000 --- a/LocalEndpoint/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LocalEndpoint -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/LocalEndpoint/LocalEndpoint.cs b/LocalEndpoint/LocalEndpoint.cs new file mode 100644 index 0000000..f45112a --- /dev/null +++ b/LocalEndpoint/LocalEndpoint.cs @@ -0,0 +1,11 @@ +using Models.Endpoint; + +namespace LocalEndpoint +{ + public class LocalEndpoint : IEndpoint + { + public IAccountManager AccountManager => new AccountManager(); + + public ISearchEngine SearchEngine => throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/LocalEndpoint/LocalEndpoint.csproj b/LocalEndpoint/LocalEndpoint.csproj index e45d1d7..a913705 100644 --- a/LocalEndpoint/LocalEndpoint.csproj +++ b/LocalEndpoint/LocalEndpoint.csproj @@ -1,4 +1,4 @@ - + net7.0 diff --git a/MainAppShell.xaml b/MainAppShell.xaml index 549c9f7..53d2736 100644 --- a/MainAppShell.xaml +++ b/MainAppShell.xaml @@ -10,24 +10,6 @@ Shell.TabBarTitleColor="{StaticResource Selected}" Shell.TabBarUnselectedColor="{StaticResource TextColorSecondary}"> - - - - - - - + \ No newline at end of file diff --git a/ShoopNCook.csproj b/ShoopNCook.csproj index cff5220..f220635 100644 --- a/ShoopNCook.csproj +++ b/ShoopNCook.csproj @@ -48,27 +48,22 @@ - - - - - @@ -118,7 +113,7 @@ - + diff --git a/ShoopNCook.sln b/ShoopNCook.sln index f0e9130..f914fd4 100644 --- a/ShoopNCook.sln +++ b/ShoopNCook.sln @@ -1,44 +1,44 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31611.283 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShoopNCook", "ShoopNCook.csproj", "{8ED2FB1D-C04D-478D-9271-CC91FE110396}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{E50D92DC-0BB1-4998-B085-EF47C55675AC}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalEndpoint", "LocalEndpoint\LocalEndpoint.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Build.0 = Release|Any CPU - {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Deploy.0 = Release|Any CPU - {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.Build.0 = Release|Any CPU - {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.Build.0 = Release|Any CPU - {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31611.283 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShoopNCook", "ShoopNCook.csproj", "{8ED2FB1D-C04D-478D-9271-CC91FE110396}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{E50D92DC-0BB1-4998-B085-EF47C55675AC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalEndpoint", "LocalEndpoint\LocalEndpoint.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Build.0 = Release|Any CPU + {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Deploy.0 = Release|Any CPU + {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.Build.0 = Release|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.Build.0 = Release|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} + EndGlobalSection +EndGlobal diff --git a/Views/Components/RecipeView.xaml b/Views/Components/RecipeView.xaml index 1842b45..8e794da 100644 --- a/Views/Components/RecipeView.xaml +++ b/Views/Components/RecipeView.xaml @@ -23,7 +23,7 @@ StrokeShape="RoundRectangle 20" BackgroundColor="{StaticResource ImageBackground}"> - + + Placeholder="Mail address" + x:Name="EmailEntry"/> @@ -57,7 +58,8 @@ + Placeholder="Password" + x:Name="PasswordEntry"/> + Placeholder="User Name" + x:Name="UserNameEntry"/> @@ -59,7 +60,8 @@ + Placeholder="Mail address" + x:Name="EmailEntry"/> @@ -76,7 +78,8 @@ + Placeholder="Password" + x:Name="PasswordEntry"/> Date: Wed, 10 May 2023 14:07:29 +0200 Subject: [PATCH 3/6] add UserNotifier for user notifications with a logger implementation --- App.xaml.cs | 5 +++-- ConnectAppShell.xaml.cs | 4 ++-- ConsoleUserNotifier.cs | 30 +++++++++++++++++++++++++++++ Controllers/ConnectionController.cs | 19 +++++++++++++++--- LocalEndpoint/AccountManager.cs | 3 +++ UserNotifier.cs | 18 +++++++++++++++++ 6 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 ConsoleUserNotifier.cs create mode 100644 UserNotifier.cs diff --git a/App.xaml.cs b/App.xaml.cs index 031cc02..a9fce9e 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -7,14 +7,15 @@ using LocalEndpoint; public partial class App : Application, ConnectionObserver { - private IEndpoint endpoint = new LocalEndpoint(); + private IEndpoint Endpoint = new LocalEndpoint(); + private UserNotifier Notifier = new ConsoleUserNotifier(); public App() { InitializeComponent(); - Shell shell = new ConnectAppShell(this, endpoint.AccountManager); + Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier); shell.GoToAsync("//Splash"); MainPage = shell; } diff --git a/ConnectAppShell.xaml.cs b/ConnectAppShell.xaml.cs index 8cc6953..84655c8 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, IAccountManager accounts) + public ConnectAppShell(ConnectionObserver observer, IAccountManager accounts, UserNotifier notifier) { - ConnectionController controller = new ConnectionController(observer, accounts); + ConnectionController controller = new ConnectionController(observer, accounts, notifier); InitializeComponent(); LoginPage.ContentTemplate = new DataTemplate(() => new LoginPage(controller)); RegisterPage.ContentTemplate = new DataTemplate(() => new RegisterPage(controller)); diff --git a/ConsoleUserNotifier.cs b/ConsoleUserNotifier.cs new file mode 100644 index 0000000..bcde5d5 --- /dev/null +++ b/ConsoleUserNotifier.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook +{ + /// + /// A notice reporter implementation that prints in console the applications's user notices. + /// + public class ConsoleUserNotifier : + UserNotifier + { + 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 8aa7803..d099efc 100644 --- a/Controllers/ConnectionController.cs +++ b/Controllers/ConnectionController.cs @@ -7,19 +7,32 @@ namespace ShoopNCook.Controllers { private readonly ConnectionObserver observer; private readonly IAccountManager accounts; - public ConnectionController(ConnectionObserver observer, IAccountManager accounts) { + private readonly UserNotifier notifier; + public ConnectionController(ConnectionObserver observer, IAccountManager accounts, UserNotifier notifier) { this.observer = observer; this.accounts = accounts; + this.notifier = notifier; } + public void Login(string email, string password) { - Account acc = accounts.Login(email, password); + Account? acc = accounts.Login(email, password); + if (acc == null) + { + notifier.Error("Email or password invalid."); + return; + } observer.OnAccountConnected(acc); } public void Register(string username, string email, string password) { - Account acc = accounts.Register(username, email, password); + Account? acc = accounts.Register(username, email, password); + if (acc == null) + { + notifier.Error("Invalid credentials."); + return; + } observer.OnAccountConnected(acc); } } diff --git a/LocalEndpoint/AccountManager.cs b/LocalEndpoint/AccountManager.cs index 5f79089..591e0a5 100644 --- a/LocalEndpoint/AccountManager.cs +++ b/LocalEndpoint/AccountManager.cs @@ -26,6 +26,9 @@ namespace LocalEndpoint public Account? Register(string email, string username, string password) { + if (email == null || username == null || password == null) + return null; + userAccount = new Account(new User(DEFAULT_ACCOUNT_IMAGE, username), email); userPassword = password; return userAccount; diff --git a/UserNotifier.cs b/UserNotifier.cs new file mode 100644 index 0000000..bfd4c07 --- /dev/null +++ b/UserNotifier.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook +{ + public interface UserNotifier + + { + public void Notice(string message); + + public void Error(string message); + + public void Warn(string message); + } +} From 7a0eb8d0da6c72fd01e153af14b2a851bb789871 Mon Sep 17 00:00:00 2001 From: Maxime BATISTA Date: Wed, 10 May 2023 14:20:20 +0200 Subject: [PATCH 4/6] bind profile picture image between HomePage and Account --- App.xaml.cs | 2 +- ConnectionObserver.cs | 5 ----- ConsoleUserNotifier.cs | 14 ++++---------- MainAppShell.xaml | 6 +----- MainAppShell.xaml.cs | 9 +++++++-- Views/FavoritesPage.xaml.cs | 4 +++- Views/HomePage.xaml | 8 +++----- Views/HomePage.xaml.cs | 7 +++++-- Views/MorePage.xaml.cs | 11 +++++------ Views/MyListPage.xaml.cs | 6 ++++-- 10 files changed, 33 insertions(+), 39 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index a9fce9e..bf135ad 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -22,7 +22,7 @@ public partial class App : Application, ConnectionObserver public void OnAccountConnected(Account account) { - Shell shell = new MainAppShell(account); + Shell shell = new MainAppShell(account, Notifier); shell.GoToAsync("//MainPage"); MainPage = shell; } diff --git a/ConnectionObserver.cs b/ConnectionObserver.cs index e4955f7..6cd2772 100644 --- a/ConnectionObserver.cs +++ b/ConnectionObserver.cs @@ -1,9 +1,4 @@ using Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ShoopNCook { diff --git a/ConsoleUserNotifier.cs b/ConsoleUserNotifier.cs index bcde5d5..04b7221 100644 --- a/ConsoleUserNotifier.cs +++ b/ConsoleUserNotifier.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShoopNCook +namespace ShoopNCook { /// /// A notice reporter implementation that prints in console the applications's user notices. @@ -14,17 +8,17 @@ namespace ShoopNCook { public void Error(string message) { - Console.WriteLine(" Error: " + message); + Console.WriteLine(" Error: " + message); } public void Notice(string message) { - Console.WriteLine(" Notice: " + message); + Console.WriteLine(" Notice: " + message); } public void Warn(string message) { - Console.WriteLine(" Warn: " + message); + Console.WriteLine(" Warn: " + message); } } } diff --git a/MainAppShell.xaml b/MainAppShell.xaml index 53d2736..7290c2f 100644 --- a/MainAppShell.xaml +++ b/MainAppShell.xaml @@ -14,28 +14,24 @@ diff --git a/MainAppShell.xaml.cs b/MainAppShell.xaml.cs index fba7fc1..ace991b 100644 --- a/MainAppShell.xaml.cs +++ b/MainAppShell.xaml.cs @@ -1,11 +1,16 @@ namespace ShoopNCook; using Microsoft.Maui.Controls; using Models; - +using ShoopNCook.Pages; + public partial class MainAppShell : Shell { - public MainAppShell(Account account) + public MainAppShell(Account account, UserNotifier notifier) { InitializeComponent(); + HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, notifier)); + FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, notifier)); + MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, notifier)); + MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, notifier)); } } diff --git a/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index 636662e..f0034ce 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -1,8 +1,10 @@ +using Models; + namespace ShoopNCook.Pages; public partial class FavoritesPage : ContentPage { - public FavoritesPage() + public FavoritesPage(Account account, UserNotifier notifier) { InitializeComponent(); } diff --git a/Views/HomePage.xaml b/Views/HomePage.xaml index 92d7809..5f16b74 100644 --- a/Views/HomePage.xaml +++ b/Views/HomePage.xaml @@ -13,16 +13,14 @@ JustifyContent="SpaceBetween" AlignItems="Center" AlignContent="Center" - Margin="20,35,20,20" - > + Margin="20,35,20,20"> + StrokeShape="RoundRectangle 1500"> diff --git a/Views/HomePage.xaml.cs b/Views/HomePage.xaml.cs index e245dde..0498d67 100644 --- a/Views/HomePage.xaml.cs +++ b/Views/HomePage.xaml.cs @@ -1,10 +1,13 @@ +using Models; + namespace ShoopNCook.Pages; public partial class HomePage : ContentPage { - public HomePage() - { + public HomePage(Account account, UserNotifier notifier) + { InitializeComponent(); + ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture); } private async void OnSyncButtonClicked(object sender, EventArgs e) { diff --git a/Views/MorePage.xaml.cs b/Views/MorePage.xaml.cs index 64f5116..36a9a04 100644 --- a/Views/MorePage.xaml.cs +++ b/Views/MorePage.xaml.cs @@ -1,16 +1,15 @@ +using Models; + namespace ShoopNCook.Pages; public partial class MorePage : ContentPage { - public MorePage(): this("Adom Shafi", ImageSource.FromFile("default_profile_picture.png")) - { - } - public MorePage(string userName, ImageSource userImage) + public MorePage(Account account, UserNotifier notifier) { InitializeComponent(); - ProfileImage.Source = userImage; - ProfileName.Text = userName; + ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture); + ProfileName.Text = account.User.Name; } private async void OnMyRecipesButtonTapped(object sender, EventArgs e) { diff --git a/Views/MyListPage.xaml.cs b/Views/MyListPage.xaml.cs index 3dfaaaa..a527ff6 100644 --- a/Views/MyListPage.xaml.cs +++ b/Views/MyListPage.xaml.cs @@ -1,9 +1,11 @@ +using Models; + namespace ShoopNCook.Pages; public partial class MyListPage : ContentPage { - public MyListPage() - { + public MyListPage(Account account, UserNotifier notifier) + { InitializeComponent(); } } \ No newline at end of file From bf95cc70a5684ab7933e4dbabba7789b3714dafb Mon Sep 17 00:00:00 2001 From: Maxime BATISTA Date: Wed, 10 May 2023 14:44:56 +0200 Subject: [PATCH 5/6] fix logout --- App.xaml.cs | 20 ++++++++++++-------- Controllers/MorePageController.cs | 24 ++++++++++++++++++++++++ IApp.cs | 16 ++++++++++++++++ MainAppShell.xaml.cs | 11 ++++++----- Views/FavoritesPage.xaml.cs | 2 +- Views/HomePage.xaml | 8 +++++--- Views/HomePage.xaml.cs | 3 ++- Views/MorePage.xaml.cs | 11 ++++++++--- Views/MyListPage.xaml.cs | 2 +- 9 files changed, 75 insertions(+), 22 deletions(-) create mode 100644 Controllers/MorePageController.cs create mode 100644 IApp.cs diff --git a/App.xaml.cs b/App.xaml.cs index bf135ad..5800cdd 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -4,26 +4,30 @@ using Models; using Models.Endpoint; using LocalEndpoint; -public partial class App : Application, ConnectionObserver +public partial class App : Application, ConnectionObserver, IApp { private IEndpoint Endpoint = new LocalEndpoint(); - private UserNotifier Notifier = new ConsoleUserNotifier(); + + public UserNotifier Notifier => new ConsoleUserNotifier(); public App() { InitializeComponent(); + ForceLogin(); //start in login state + } - - Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier); - shell.GoToAsync("//Splash"); + public void OnAccountConnected(Account account) + { + Shell shell = new MainAppShell(account, this); + shell.GoToAsync("//Main"); MainPage = shell; } - public void OnAccountConnected(Account account) + public void ForceLogin() { - Shell shell = new MainAppShell(account, Notifier); - shell.GoToAsync("//MainPage"); + Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier); + shell.GoToAsync("//Splash"); MainPage = shell; } } \ No newline at end of file diff --git a/Controllers/MorePageController.cs b/Controllers/MorePageController.cs new file mode 100644 index 0000000..f4698fa --- /dev/null +++ b/Controllers/MorePageController.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook.Controllers +{ + public class MorePageController + { + + private readonly IApp app; + + public MorePageController(IApp app) { + this.app = app; + } + + public void Logout() + { + app.Notifier.Notice("You have been loged out."); + app.ForceLogin(); + } + } +} diff --git a/IApp.cs b/IApp.cs new file mode 100644 index 0000000..32a77b0 --- /dev/null +++ b/IApp.cs @@ -0,0 +1,16 @@ +using Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShoopNCook +{ + public interface IApp + { + public UserNotifier Notifier { get; } + + public void ForceLogin(); + } +} diff --git a/MainAppShell.xaml.cs b/MainAppShell.xaml.cs index ace991b..d8df598 100644 --- a/MainAppShell.xaml.cs +++ b/MainAppShell.xaml.cs @@ -1,16 +1,17 @@ namespace ShoopNCook; using Microsoft.Maui.Controls; using Models; +using ShoopNCook.Controllers; using ShoopNCook.Pages; public partial class MainAppShell : Shell { - public MainAppShell(Account account, UserNotifier notifier) + public MainAppShell(Account account, IApp app) { InitializeComponent(); - HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, notifier)); - FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, notifier)); - MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, notifier)); - MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, notifier)); + HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, app)); + 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/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index f0034ce..e5c5733 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -4,7 +4,7 @@ namespace ShoopNCook.Pages; public partial class FavoritesPage : ContentPage { - public FavoritesPage(Account account, UserNotifier notifier) + public FavoritesPage(Account account, IApp app) { InitializeComponent(); } diff --git a/Views/HomePage.xaml b/Views/HomePage.xaml index 5f16b74..a9e3715 100644 --- a/Views/HomePage.xaml +++ b/Views/HomePage.xaml @@ -14,7 +14,7 @@ AlignItems="Center" AlignContent="Center" Margin="20,35,20,20"> - + - + + +