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"> - + - + + +