Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / ChambersViewModel.cs @ 957bebf1

Historique | Voir | Annoter | Télécharger (1,796 ko)

1 42456640 lbihannic
using GES_PAC.Model;
2
using GES_PAC.Services;
3 4e39035b lbihannic
using GES_PAC.View;
4 e837cdf1 lbihannic
using GES_PAC.ViewModel.Controls;
5
using System.Collections.ObjectModel;
6 09d4a0de lbihannic
using System.Windows.Input;
7
8
namespace GES_PAC.ViewModel
9
{
10
    public class ChambersViewModel : BaseViewModel
11
    {
12
        #region Attributs
13
        #endregion
14
15
        #region Commandes
16 42456640 lbihannic
        public Serie? CurrentSet { get; set; }
17 12ddf7ef lbihannic
        public ICommand TerminateSetCommand { get; }
18 09d4a0de lbihannic
        #endregion
19
20
        #region Propriétés
21 e837cdf1 lbihannic
        public TimerPublisher Timer { get; }
22 957bebf1 lbihannic
        public List<ChamberButtonViewModel> Buttons { get; } = new();
23
24 09d4a0de lbihannic
        #endregion
25
26
        #region Constructeurs
27
        public ChambersViewModel()
28
        {
29 4e39035b lbihannic
            TerminateSetCommand = new Command(async () => await TerminateSet());
30 e837cdf1 lbihannic
31 42456640 lbihannic
            CurrentSet = JourneeViewModel.Instance.GetCurrentSet();
32
33 e837cdf1 lbihannic
            Timer = new TimerPublisher();
34
            Timer.Start();
35 09d4a0de lbihannic
        }
36
        #endregion
37
38
        #region Méthodes
39 4e39035b lbihannic
        private async Task TerminateSet()
40
        {
41
            if (IsBusy) return;
42
            IsBusy = true;
43
            await Shell.Current.GoToAsync(nameof(EndSetView));
44
            IsBusy = false;
45
        }
46 42456640 lbihannic
47
        internal async void OnAppearing()
48
        {
49
            CurrentSet = JourneeViewModel.Instance.GetCurrentSet();
50 957bebf1 lbihannic
            RefreshAll();
51
52 42456640 lbihannic
            if (CurrentSet == null)
53
            {
54
                IsBusy = true;
55
                await Shell.Current.GoToAsync(nameof(MainView));
56
                IsBusy = false;
57
            }
58
        }
59 957bebf1 lbihannic
        public void RegisterButton(ChamberButtonViewModel vm)
60
        {
61
            if (!Buttons.Contains(vm))
62
                Buttons.Add(vm);
63
        }
64
        public void RefreshAll()
65
        {
66
            foreach (var btn in Buttons)
67
                btn.UpdateProperties();
68
        }
69
70 09d4a0de lbihannic
        #endregion
71
    }
72
}