From 4d91395456776d66d5b73ce746070f3eee0d1504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gabriel=2Ehuot-v=C3=A9zina?= Date: Thu, 20 Jun 2024 20:25:09 -0400 Subject: [PATCH] #345 testing code to fix issue in field books. Without luck. --- .../ViewModels/FieldBooksPageViewModel.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs index e44b115c..60c693fb 100644 --- a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs +++ b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs @@ -38,7 +38,7 @@ public class FieldBooksPageViewModel : ViewModelBase #region INITIALIZATION //UI - public ObservableCollection _projectCollection = new ObservableCollection(); + private ObservableCollection _projectCollection = new ObservableCollection(); public int _selectedProjectIndex = -1; private bool _noFieldBookWatermark = false; @@ -71,6 +71,7 @@ public class FieldBooksPageViewModel : ViewModelBase public ObservableCollection ProjectCollection { get { return _projectCollection; } + set { _projectCollection = value; } } public bool ProgressRingActive @@ -90,11 +91,8 @@ public bool ProgressRingVisibility public FieldBooksPageViewModel() { - _projectCollection = new ObservableCollection(); - RaisePropertyChanged("ProjectCollection"); - //Fill list view of projects - FillProjectCollectionAsync(); + _ = FillProjectCollectionAsync(); //Detect new field book save GSCFieldApp.Views.FieldBookDialog.newFieldBookSaved -= FieldBookDialog_newFieldBookSaved; @@ -119,9 +117,9 @@ private void FieldBookDialog_newFieldBookSaved(object sender, EventArgs e) /// /// Will fill the project collection with information related to it /// - private async void FillProjectCollectionAsync() + private async Task> FillProjectCollectionAsync() { - _projectCollection.Clear(); + _projectCollection = new ObservableCollection(); RaisePropertyChanged("ProjectCollection"); List invalidFieldBookToDelete = new List(); @@ -189,16 +187,15 @@ private async void FillProjectCollectionAsync() { currentDB.StationNumber = 0.ToString(); } - + #endregion - _projectCollection.Add(currentDB); + if (!_projectCollection.Contains(currentDB)) + { + _projectCollection.Add(currentDB); + } currentConnection.Close(); - GC.Collect(); - GC.WaitForPendingFinalizers(); - - System.Runtime.InteropServices.Marshal.ReleaseComObject(sfi); break; //Forget about other files } @@ -207,7 +204,7 @@ private async void FillProjectCollectionAsync() } //Refresh UI - RaisePropertyChanged("ProjectCollection"); + //RaisePropertyChanged("ProjectCollection"); //Select the current active project, so it's highlighted in the list view ResourceLoader loadLocal = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); @@ -231,6 +228,7 @@ private async void FillProjectCollectionAsync() fieldBooksUpdate?.Invoke(this, true); } + return _projectCollection; } /// @@ -396,7 +394,7 @@ public async void DeleteFieldBook() } //Refresh page - FillProjectCollectionAsync(); + _ =FillProjectCollectionAsync(); } @@ -713,8 +711,9 @@ public async void ProjectDeleteButton_TappedAsync(object sender, Windows.UI.Xaml private void ViewModel_projectEdit(object sender) { //Refresh page - FillProjectCollectionAsync(); + _ =FillProjectCollectionAsync(); + RaisePropertyChanged("ProjectCollection"); } /// @@ -868,7 +867,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch SetFieldBook(restFieldBook); - FillProjectCollectionAsync(); + _ = FillProjectCollectionAsync(); } else { @@ -1149,7 +1148,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch private void upgradedDBDialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args) { //Send call to refresh other pages - FillProjectCollectionAsync(); + _ = FillProjectCollectionAsync(); EventHandler newFieldBookRequest = newFieldBookSelected; if (newFieldBookRequest != null) {