From b1ce8f74e7470afbfaac1f3d72a2e7585270371c Mon Sep 17 00:00:00 2001 From: Anthony RICHARD Date: Mon, 5 Jun 2023 10:44:49 +0200 Subject: [PATCH 1/3] passage du selectedgame dans le manager --- Sources/Stim.Model/Manager.cs | 17 ++++------------- Sources/Stim/DetailledPage.xaml.cs | 19 +++++++++++-------- Sources/Stim/FollowPage.xaml.cs | 3 ++- Sources/Stim/MainPage.xaml.cs | 3 ++- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Sources/Stim.Model/Manager.cs b/Sources/Stim.Model/Manager.cs index 75c1608..258a8fa 100644 --- a/Sources/Stim.Model/Manager.cs +++ b/Sources/Stim.Model/Manager.cs @@ -5,28 +5,19 @@ namespace Model { public class Manager { - public IPersistance Mgrpersistance - { - get { return mgrpersistance; } - set { mgrpersistance = value; } - } - private IPersistance mgrpersistance; - public ObservableCollection GameList { get;} + private IPersistance Mgrpersistance { get; set; } + public ObservableCollection GameList { get; set; } public ObservableCollection ResearchedGame { get; set; } - public User CurrentUser { get; set; } + public Game? SelectedGame { get; set; } + public User? CurrentUser { get; set; } public HashSet Users { get; set; } public Manager(IPersistance persistance) { Mgrpersistance = persistance; - CurrentUser = new User("","", "", "", "Azerty123*"); GameList = persistance.LoadGame(); ResearchedGame = persistance.LoadGame(); Users = persistance.LoadUser(); - if (GameList == null) - { - GameList = new ObservableCollection(); - } } public void AddGametoGamesList(Game game) diff --git a/Sources/Stim/DetailledPage.xaml.cs b/Sources/Stim/DetailledPage.xaml.cs index 86faa64..011ec31 100644 --- a/Sources/Stim/DetailledPage.xaml.cs +++ b/Sources/Stim/DetailledPage.xaml.cs @@ -6,16 +6,19 @@ namespace Stim; public partial class DetailledPage : ContentPage { - public Game CurrGame { get; set; } - public DetailledPage(Game game) + private Game currentGame; + + public DetailledPage() { InitializeComponent(); - BindingContext = game; - CurrGame= game; - if (CurrGame != null) + currentGame = (App.Current as App).Manager.SelectedGame; + BindingContext = currentGame; + + if (currentGame is null) Navigation.PopAsync(); + else { - avgLabel.Text = game.GetAvgRate().ToString(); - AddStars(starsContainer, game.GetAvgRate()); + avgLabel.Text = currentGame.GetAvgRate().ToString(); + AddStars(starsContainer, currentGame.GetAvgRate()); } } @@ -46,6 +49,6 @@ public partial class DetailledPage : ContentPage private async void AddFollow(object sender, EventArgs e) { await this.ShowPopupAsync(new MessagePopup("Jeu ajouté dans les suivis !")); - ((App)App.Current).Manager.CurrentUser.FollowAGame(CurrGame); + ((App)App.Current).Manager.CurrentUser.FollowAGame(currentGame); } } \ No newline at end of file diff --git a/Sources/Stim/FollowPage.xaml.cs b/Sources/Stim/FollowPage.xaml.cs index 650b1c4..752060e 100644 --- a/Sources/Stim/FollowPage.xaml.cs +++ b/Sources/Stim/FollowPage.xaml.cs @@ -12,6 +12,7 @@ public partial class FollowPage : ContentPage public async void GoToDetail(object sender, EventArgs e) { - await Navigation.PushAsync(new DetailledPage((sender as CollectionView).SelectedItem as Game)); + (App.Current as App).Manager.SelectedGame = (sender as CollectionView).SelectedItem as Game; + await Navigation.PushAsync(new DetailledPage()); } } \ No newline at end of file diff --git a/Sources/Stim/MainPage.xaml.cs b/Sources/Stim/MainPage.xaml.cs index 29cfc33..484e0d3 100644 --- a/Sources/Stim/MainPage.xaml.cs +++ b/Sources/Stim/MainPage.xaml.cs @@ -17,7 +17,8 @@ public partial class MainPage : ContentPage private async void OnClickGameList(object sender, EventArgs e) { - await Navigation.PushAsync(new DetailledPage((sender as CollectionView).SelectedItem as Game)); + (App.Current as App).Manager.SelectedGame = (sender as CollectionView).SelectedItem as Game; + await Navigation.PushAsync(new DetailledPage()); } private async void GoToAddGamePage(object sender, EventArgs e) From 0b3df7e82838738558250c37d493e6dd2ce0da6c Mon Sep 17 00:00:00 2001 From: Anthony RICHARD Date: Mon, 5 Jun 2023 10:45:54 +0200 Subject: [PATCH 2/3] suppression des vertical stack layout dans les popups --- Sources/AppConsole/Program.cs | 7 +++---- Sources/Stim/App.xaml.cs | 17 ++++++++++++++--- Sources/Stim/EntryPopup.xaml | 3 +-- Sources/Stim/MessagePopup.xaml | 10 ++++------ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Sources/AppConsole/Program.cs b/Sources/AppConsole/Program.cs index 82354c2..ef64994 100644 --- a/Sources/AppConsole/Program.cs +++ b/Sources/AppConsole/Program.cs @@ -1,4 +1,5 @@ -using Model; +using Microsoft.VisualBasic; +using Model; using StimPersistance; using StimStub; using System.Diagnostics.CodeAnalysis; @@ -10,9 +11,7 @@ namespace AppConsole { static void Main(string[] args) { - Manager stub = new(new Stub()); - Manager persistance = new(new Persistance("../../../../")); - persistance.Mgrpersistance.SaveGame(stub.GameList); + Console.WriteLine(""); } } } \ No newline at end of file diff --git a/Sources/Stim/App.xaml.cs b/Sources/Stim/App.xaml.cs index 6d9c550..c1d580b 100644 --- a/Sources/Stim/App.xaml.cs +++ b/Sources/Stim/App.xaml.cs @@ -1,6 +1,7 @@ using Model; using StimPersistance; using StimStub; +using System.Diagnostics; namespace Stim; @@ -20,9 +21,19 @@ public partial class App : Application window.Stopped += (s, e) => { - Manager.Mgrpersistance = new Persistance(FileSystem.Current.AppDataDirectory); - Manager.SaveGames(); - Manager.SaveUser(); + if (!(File.Exists(Path.Combine(FileSystem.Current.AppDataDirectory, "games.xml")))) + { + Manager Manager2 = new(new Persistance(FileSystem.Current.AppDataDirectory)); + Manager2.GameList = Manager.GameList; + Manager2.Users = Manager2.Users; + Manager2.SaveGames(); + Manager2.SaveUser(); + } + else + { + Manager.SaveGames(); + Manager.SaveUser(); + } }; return window; diff --git a/Sources/Stim/EntryPopup.xaml b/Sources/Stim/EntryPopup.xaml index 2a0b30b..d01b91c 100644 --- a/Sources/Stim/EntryPopup.xaml +++ b/Sources/Stim/EntryPopup.xaml @@ -4,11 +4,10 @@ xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" x:Class="Stim.EntryPopup" CanBeDismissedByTappingOutsideOfPopup="False"> - +