diff --git a/Sources/Stim/AddGamePage.xaml.cs b/Sources/Stim/AddGamePage.xaml.cs index 568f718..c64ab19 100644 --- a/Sources/Stim/AddGamePage.xaml.cs +++ b/Sources/Stim/AddGamePage.xaml.cs @@ -4,12 +4,9 @@ namespace Stim; public partial class AddGamePage : ContentPage { - public Manager Manager { get; set; } - - public AddGamePage(Manager Mgr) + public AddGamePage() { InitializeComponent(); - Manager = Mgr; } private void AddGame(object sender, EventArgs e) @@ -17,7 +14,7 @@ public partial class AddGamePage : ContentPage int year; if (string.IsNullOrEmpty(NameEntry.Text) || string.IsNullOrEmpty(DescriptionEntry.Text) || string.IsNullOrEmpty(YearEntry.Text) || !int.TryParse(YearEntry.Text, out year) || string.IsNullOrWhiteSpace(LinkEntry.Text)) return; - Manager.AddGametoGamesList(new Game(NameEntry.Text, DescriptionEntry.Text, year, new List { TagEntry1.Text, TagEntry2.Text, TagEntry3.Text }, "nyancat.png", LinkEntry.Text)); + ((App)App.Current).Manager.AddGametoGamesList(new Game(NameEntry.Text, DescriptionEntry.Text, year, new List { TagEntry1.Text, TagEntry2.Text, TagEntry3.Text }, "nyancat.png", LinkEntry.Text)); Navigation.RemovePage(this); } } \ No newline at end of file diff --git a/Sources/Stim/App.xaml.cs b/Sources/Stim/App.xaml.cs index 277653f..592efd6 100644 --- a/Sources/Stim/App.xaml.cs +++ b/Sources/Stim/App.xaml.cs @@ -6,28 +6,11 @@ namespace Stim; public partial class App : Application { - Manager Mgr - { - get; set; - } - public App() - { - InitializeComponent(); - string mainDir = FileSystem.Current.AppDataDirectory; - if (File.Exists(Path.Combine(mainDir,"games.xml"))) Mgr = new Manager(new Persistance(mainDir)); - else Mgr = new Manager(new Stub()); - MainPage = new AppShell(); - } - protected override Window CreateWindow(IActivationState activationState) + public Manager Manager { get; set; } + public App() { - Window window = base.CreateWindow(activationState); - - window.Stopped += (s, e) => - { - Mgr._persistance = new Persistance(FileSystem.Current.AppDataDirectory); - Mgr.SaveGames(); - }; - - return window; + InitializeComponent(); + MainPage = new AppShell(); + Manager = new(new Stub()); } } diff --git a/Sources/Stim/MainPage.xaml.cs b/Sources/Stim/MainPage.xaml.cs index 41202c0..a556c9d 100644 --- a/Sources/Stim/MainPage.xaml.cs +++ b/Sources/Stim/MainPage.xaml.cs @@ -3,18 +3,14 @@ using Model; using StimPersistance; using StimStub; using Microsoft.Maui.Storage; +using Windows.System; public partial class MainPage : ContentPage { - - public IPersistance persistance = new Persistance(FileSystem.Current.AppDataDirectory); - public Manager Manager { get; set; } - public MainPage() { InitializeComponent(); - Manager = new(persistance); - BindingContext = Manager; + BindingContext = ((App)App.Current).Manager; } private async void OnClickGameList(object sender, EventArgs e) @@ -24,6 +20,6 @@ public partial class MainPage : ContentPage private async void GoToAddGamePage(object sender, EventArgs e) { - await Navigation.PushAsync(new AddGamePage(Manager)); + await Navigation.PushAsync(new AddGamePage()); } }