From b1ce8f74e7470afbfaac1f3d72a2e7585270371c Mon Sep 17 00:00:00 2001 From: Anthony RICHARD Date: Mon, 5 Jun 2023 10:44:49 +0200 Subject: [PATCH] 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)