Manager commun à toutes les pages
continuous-integration/drone/push Build is passing Details

Popup_qui_marche_pas
Anthony RICHARD 2 years ago
parent bdc78ba250
commit 63eae4f24b

@ -4,12 +4,9 @@ namespace Stim;
public partial class AddGamePage : ContentPage public partial class AddGamePage : ContentPage
{ {
public Manager Manager { get; set; } public AddGamePage()
public AddGamePage(Manager Mgr)
{ {
InitializeComponent(); InitializeComponent();
Manager = Mgr;
} }
private void AddGame(object sender, EventArgs e) private void AddGame(object sender, EventArgs e)
@ -17,7 +14,7 @@ public partial class AddGamePage : ContentPage
int year; 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; 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<string> { TagEntry1.Text, TagEntry2.Text, TagEntry3.Text }, "nyancat.png", LinkEntry.Text)); ((App)App.Current).Manager.AddGametoGamesList(new Game(NameEntry.Text, DescriptionEntry.Text, year, new List<string> { TagEntry1.Text, TagEntry2.Text, TagEntry3.Text }, "nyancat.png", LinkEntry.Text));
Navigation.RemovePage(this); Navigation.RemovePage(this);
} }
} }

@ -6,28 +6,11 @@ namespace Stim;
public partial class App : Application public partial class App : Application
{ {
Manager Mgr public Manager Manager { get; set; }
{ public App()
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)
{ {
Window window = base.CreateWindow(activationState); InitializeComponent();
MainPage = new AppShell();
window.Stopped += (s, e) => Manager = new(new Stub());
{
Mgr._persistance = new Persistance(FileSystem.Current.AppDataDirectory);
Mgr.SaveGames();
};
return window;
} }
} }

@ -3,18 +3,14 @@ using Model;
using StimPersistance; using StimPersistance;
using StimStub; using StimStub;
using Microsoft.Maui.Storage; using Microsoft.Maui.Storage;
using Windows.System;
public partial class MainPage : ContentPage public partial class MainPage : ContentPage
{ {
public IPersistance persistance = new Persistance(FileSystem.Current.AppDataDirectory);
public Manager Manager { get; set; }
public MainPage() public MainPage()
{ {
InitializeComponent(); InitializeComponent();
Manager = new(persistance); BindingContext = ((App)App.Current).Manager;
BindingContext = Manager;
} }
private async void OnClickGameList(object sender, EventArgs e) 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) private async void GoToAddGamePage(object sender, EventArgs e)
{ {
await Navigation.PushAsync(new AddGamePage(Manager)); await Navigation.PushAsync(new AddGamePage());
} }
} }

Loading…
Cancel
Save