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">
-
+
-
+
+
+
diff --git a/Views/HomePage.xaml.cs b/Views/HomePage.xaml.cs
index 0498d67..56277fa 100644
--- a/Views/HomePage.xaml.cs
+++ b/Views/HomePage.xaml.cs
@@ -4,10 +4,11 @@ namespace ShoopNCook.Pages;
public partial class HomePage : ContentPage
{
- public HomePage(Account account, UserNotifier notifier)
+ public HomePage(Account account, IApp app)
{
InitializeComponent();
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
+ ProfilePictureName.Text = account.User.Name;
}
private async void OnSyncButtonClicked(object sender, EventArgs e)
{
diff --git a/Views/MorePage.xaml.cs b/Views/MorePage.xaml.cs
index 36a9a04..e9b8298 100644
--- a/Views/MorePage.xaml.cs
+++ b/Views/MorePage.xaml.cs
@@ -1,16 +1,21 @@
using Models;
+using ShoopNCook.Controllers;
namespace ShoopNCook.Pages;
public partial class MorePage : ContentPage
{
- public MorePage(Account account, UserNotifier notifier)
+ private readonly MorePageController controller;
+
+ public MorePage(Account account, MorePageController controller)
{
InitializeComponent();
ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfileName.Text = account.User.Name;
+ this.controller = controller;
}
+
private async void OnMyRecipesButtonTapped(object sender, EventArgs e)
{
await Shell.Current.Navigation.PushAsync(new MyRecipesPage());
@@ -21,9 +26,9 @@ public partial class MorePage : ContentPage
await Shell.Current.Navigation.PushAsync(new ProfilePage());
}
- private async void OnLogoutButtonTapped(object sender, EventArgs e)
+ private void OnLogoutButtonTapped(object sender, EventArgs e)
{
- await Shell.Current.GoToAsync("//Login");
+ controller.Logout();
}
private async void OnShareButtonClicked(object sender, EventArgs e)
{
diff --git a/Views/MyListPage.xaml.cs b/Views/MyListPage.xaml.cs
index a527ff6..d7ffcef 100644
--- a/Views/MyListPage.xaml.cs
+++ b/Views/MyListPage.xaml.cs
@@ -4,7 +4,7 @@ namespace ShoopNCook.Pages;
public partial class MyListPage : ContentPage
{
- public MyListPage(Account account, UserNotifier notifier)
+ public MyListPage(Account account, IApp app)
{
InitializeComponent();
}