Révision e837cdf1

Voir les différences:

GES_PAC/GES_PAC.csproj.user
3 3
  <PropertyGroup>
4 4
    <IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
5 5
    <ActiveDebugFramework>net9.0-android</ActiveDebugFramework>
6
    <ActiveDebugProfile>Xiaomi 23090RA98G (Android 15.0 - API 35)</ActiveDebugProfile>
6
    <ActiveDebugProfile>Samsung SM-G556B (Android 14.0 - API 34)</ActiveDebugProfile>
7 7
    <SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
8 8
    <DefaultDevice>pixel_7_-_api_35</DefaultDevice>
9 9
    <SelectedDevice>Xiaomi 23090RA98G</SelectedDevice>
......
11 11
  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-android|AnyCPU'">
12 12
    <DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
13 13
  </PropertyGroup>
14
  <PropertyGroup Condition="'$(TargetPlatformIdentifier)'=='iOS'">
15
    <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
16
    <PlatformTarget>arm64</PlatformTarget>
17
  </PropertyGroup>
14 18
  <ItemGroup>
15 19
    <None Update="App.xaml">
16 20
      <SubType>Designer</SubType>
GES_PAC/Model/Serie.cs
95 95
        {
96 96
            return SeriesAnimales.Sum(sa => sa.Comportements.Count());
97 97
        }
98
        public SerieAnimal? GetSerieAnimalByNumBoite(int numBoite)
99
        {
100
            return SeriesAnimales.FirstOrDefault(sa => sa.NumeroBoite == numBoite);
101
        }
98 102
        #endregion
99 103
    }
100 104
}
GES_PAC/Model/SerieAnimal.cs
38 38
        {
39 39
            return Mesures.Last();
40 40
        }
41
        public Mesure GetFirstMeasure()
42
        {
43
            return Mesures.First();
44
        }
41 45

  
42 46
        public void AddBehaviour(Comportement newBehaviour)
43 47
        {
......
46 50

  
47 51
        public bool HasBehaviour()
48 52
        {
49
            return Comportements.Any();
53
            return Comportements.Count != 0;
54
        }
55
        public string GetTimeInChamber()
56
        {
57
            if (Mesures.Count == 0)
58
                return "";
59

  
60
            TimeSpan timeInChamber;
61
            if (IsOut)
62
                timeInChamber = GetLastMeasure().Time - GetFirstMeasure().Time;
63
            else
64
                timeInChamber = DateTime.Now - GetFirstMeasure().Time;
65

  
66
            return $"{timeInChamber.Hours:00}:{timeInChamber.Minutes:00}";
50 67
        }
51 68
    }
52 69
}
GES_PAC/View/ChambersView.xaml
48 48
                                </Grid.RowDefinitions>
49 49

  
50 50
                                <!-- Boutons Gauche -->
51
                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="0" ChamberId="1" />
52
                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="0" ChamberId="3" />
53
                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="0" ChamberId="5" />
54
                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="0" ChamberId="7" />
55
                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="0" ChamberId="9" />
56
                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="0" ChamberId="11" />
51
                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="0" ChamberId="1" Timer="{Binding Timer}"/>
52
                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="0" ChamberId="3" Timer="{Binding Timer}"/>
53
                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="0" ChamberId="5" Timer="{Binding Timer}"/>
54
                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="0" ChamberId="7" Timer="{Binding Timer}"/>
55
                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="0" ChamberId="9" Timer="{Binding Timer}"/>
56
                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="0" ChamberId="11" Timer="{Binding Timer}"/>
57 57

  
58 58
                                <!-- Boutons Droite -->
59
                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="2" ChamberId="2" />
60
                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="2" ChamberId="4" />
61
                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="2" ChamberId="6" />
62
                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="2" ChamberId="8" />
63
                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="2" ChamberId="10" />
64
                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="2" ChamberId="12" />
59
                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="2" ChamberId="2" Timer="{Binding Timer}"/>
60
                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="2" ChamberId="4" Timer="{Binding Timer}"/>
61
                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="2" ChamberId="6" Timer="{Binding Timer}"/>
62
                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="2" ChamberId="8" Timer="{Binding Timer}"/>
63
                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="2" ChamberId="10" Timer="{Binding Timer}"/>
64
                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="2" ChamberId="12" Timer="{Binding Timer}"/>
65 65

  
66 66
                                <!-- Couloir central -->
67 67
                                <BoxView Grid.Column="1" Grid.RowSpan="6" HeightRequest="500" WidthRequest="75" Color="Gray"/>
......
83 83
                </VerticalStackLayout>
84 84
            </ScrollView>
85 85
            <StackLayout
86
                Margin="-40"
86
                Margin="-90"
87 87
                HorizontalOptions="Center"
88 88
                Orientation="Horizontal"
89
                VerticalOptions="Fill">
89
                VerticalOptions="End">
90 90

  
91 91
                <Button 
92 92
                    Text="Terminer les mesures"
GES_PAC/View/Controls/ChamberButtonView.xaml
1 1
<?xml version="1.0" encoding="utf-8" ?>
2
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4
             xmlns:vm="clr-namespace:GES_PAC.ViewModel.Controls"
5
             x:Class="GES_PAC.View.Controls.ChamberButtonView"
6
             x:Name="ChamberButtonControl"
7
             x:DataType="vm:ChamberButtonViewModel">
2
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"  
3
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
4
            xmlns:vm="clr-namespace:GES_PAC.ViewModel.Controls"  
5
            x:Class="GES_PAC.View.Controls.ChamberButtonView"  
6
            x:Name="ChamberButtonControl"  
7
            x:DataType="vm:ChamberButtonViewModel">  
8 8

  
9
    <Grid>
10
        <Button Text="{Binding ButtonText}"
11
                Style="{StaticResource ChambreButtonStyle}"
12
                Command="{Binding OnClickChamberCommand}"
13
                CommandParameter="{Binding ButtonCommandParameter}"
14
                BackgroundColor="{Binding ButtonBackgroundColor}"
15
                IsEnabled="{Binding ButtonIsEnabled}" />
16
        <Label Text="{Binding ButtonLabel}"
17
               FontSize="10"
18
               Margin="3"
19
               HorizontalOptions="Start"
20
               VerticalOptions="Start" />
21
    </Grid>
9
   <Grid>  
10
       <Button Text="{Binding ButtonText}"  
11
           Style="{StaticResource ChambreButtonStyle}"  
12
           Command="{Binding OnClickChamberCommand}"  
13
           CommandParameter="{Binding ChamberId}"  
14
           BackgroundColor="{Binding ButtonBackgroundColor}"  
15
           IsEnabled="{Binding ButtonIsEnabled}" />  
16

  
17
       <Label Text="{Binding ButtonLabel}"  
18
           FontSize="12"  
19
           Margin="3"  
20
           HorizontalOptions="Start"  
21
           VerticalOptions="Start" />  
22

  
23
       <Label Text="{Binding TimeIn}"  
24
           FontSize="12"  
25
           Margin="3"  
26
           HorizontalOptions="End"  
27
           VerticalOptions="Start" />  
28
   </Grid>  
22 29
</ContentView>
GES_PAC/View/Controls/ChamberButtonView.xaml.cs
1
using GES_PAC.ViewModel.Controls;
1
using GES_PAC.ViewModel;
2
using GES_PAC.ViewModel.Controls;
2 3

  
3
namespace GES_PAC.View.Controls
4
namespace GES_PAC.View.Controls;
5

  
6
public partial class ChamberButtonView : ContentView
4 7
{
5
    public partial class ChamberButtonView : ContentView
8
    public static readonly BindableProperty ChamberIdProperty =
9
        BindableProperty.Create(nameof(ChamberId), typeof(int), typeof(ChamberButtonView), default(int), propertyChanged: OnChamberIdChanged);
10

  
11
    public static readonly BindableProperty TimerProperty =
12
        BindableProperty.Create(nameof(Timer), typeof(TimerPublisher), typeof(ChamberButtonView), propertyChanged: OnTimerChanged);
13

  
14
    public TimerPublisher? Timer
15
    {
16
        get => (TimerPublisher?)GetValue(TimerProperty);
17
        set => SetValue(TimerProperty, value);
18
    }
19

  
20
    public int ChamberId
21
    {
22
        get => (int)GetValue(ChamberIdProperty);
23
        set => SetValue(ChamberIdProperty, value);
24
    }
25
    public ChamberButtonView()
26
    {
27
        InitializeComponent();
28
    }
29

  
30
    protected override void OnBindingContextChanged()
6 31
    {
7
        public static readonly BindableProperty ChamberIdProperty =
8
            BindableProperty.Create(nameof(ChamberId), typeof(int), typeof(ChamberButtonView), default(int), propertyChanged: OnChamberIdChanged);
32
        base.OnBindingContextChanged();
9 33

  
10
        public int ChamberId
34
        if (BindingContext is not ChamberButtonViewModel && ChamberId != 0 && Timer != null)
11 35
        {
12
            get => (int)GetValue(ChamberIdProperty);
13
            set => SetValue(ChamberIdProperty, value);
36
            var vm = new ChamberButtonViewModel(ChamberId, Timer);
37
            BindingContext = vm;
14 38
        }
39
    }
40
    private static void OnChamberIdChanged(BindableObject bindable, object oldValue, object newValue)
41
    {
42
        var control = (ChamberButtonView)bindable;
43
        int id = (int)newValue;
15 44

  
16
        public ChamberButtonView()
45
        if (control.BindingContext is ChamberButtonViewModel vm)
17 46
        {
18
            BindingContext = new ChamberButtonViewModel();
19
            InitializeComponent();
47
            vm.UpdateChamberId(id);
20 48
        }
21

  
22
        private static void OnChamberIdChanged(BindableObject bindable, object oldValue, object newValue)
49
    }
50
    private static void OnTimerChanged(BindableObject bindable, object oldValue, object newValue)
51
    {
52
        if (bindable is ChamberButtonView view)
23 53
        {
24
            var control = (ChamberButtonView)bindable;
25

  
26
            if (control.BindingContext is ChamberButtonViewModel viewModel)
27
            {
28
                viewModel.UpdateProperties((int)newValue);
29
            }
54
            view.OnBindingContextChanged();
30 55
        }
31 56
    }
57

  
32 58
}
GES_PAC/ViewModel/ChambersViewModel.cs
1
using GES_PAC.Model;
2 1
using GES_PAC.View;
2
using GES_PAC.ViewModel.Controls;
3
using System.Collections.ObjectModel;
3 4
using System.Windows.Input;
4 5

  
5 6
namespace GES_PAC.ViewModel
6 7
{
7 8
    public class ChambersViewModel : BaseViewModel
8 9
    {
9

  
10 10
        #region Attributs
11
        
12 11
        #endregion
13 12

  
14 13
        #region Commandes
......
16 15
        #endregion
17 16

  
18 17
        #region Propriétés
19

  
18
        public ObservableCollection<ChamberButtonViewModel> Chambers { get; } = new();
19
        public TimerPublisher Timer { get; }
20 20
        #endregion
21 21

  
22 22
        #region Constructeurs
23 23
        public ChambersViewModel()
24 24
        {
25 25
            TerminateSetCommand = new Command(async () => await TerminateSet());
26

  
27
            Timer = new TimerPublisher();
28
            Timer.Start();
26 29
        }
27 30
        #endregion
28 31

  
GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs
7 7
    public class ChamberButtonViewModel : BaseViewModel
8 8
    {
9 9
        #region Attributs
10
        private Serie _currentSet;
10 11
        private string _buttonText;
11 12
        private int _chamberId;
12 13
        private Color _buttonBackgroundColor;
13 14
        private bool _buttonIsEnabled;
14 15
        private string _buttonLabel;
16
        private string _timeIn;
15 17
        private ICommand _onClickChamberCommand;
18
        private readonly TimerPublisher _timer;
19

  
16 20
        #endregion
17 21

  
18 22
        #region Propriétés
19

  
23
        public Serie CurrentSet
24
        {
25
            get => _currentSet;
26
            set
27
            {
28
                _currentSet = value;
29
                OnPropertyChanged();
30
            }
31
        }
20 32
        public string ButtonText {
21 33
            get => _buttonText;
22 34
            set
......
61 73
                OnPropertyChanged();
62 74
            }
63 75
        }
64
        public Serie CurrentSet { get; set; }
76
        public string TimeIn
77
        {
78
            get => _timeIn;
79
            set
80
            {
81
                _timeIn = value;
82
                OnPropertyChanged();
83
            }
84
        }
85
        public SerieAnimal AnimalSet;
86
        private bool _isSubscribed = false;
87

  
65 88
        #endregion
66 89

  
67 90
        #region Commandes
......
77 100
        #endregion
78 101

  
79 102
        #region Constructeurs
80
        #endregion
81 103

  
82
        #region Méthodes
83
        public void UpdateProperties(int chamberId)
104
        public ChamberButtonViewModel(int chamberId, TimerPublisher timerPublisher)
84 105
        {
85
            OnClickChamberCommand = new Command(async () => await GoToEnterAnimal());
106
            ChamberId = chamberId;
107
            _timer = timerPublisher;
86 108

  
109
            OnClickChamberCommand = new Command(async () => await GoToChamber());
110
            ButtonBackgroundColor = Colors.White;
111
            ButtonIsEnabled = true;
112
            ButtonLabel = "0";
113
            TimeIn = "";
87 114
            CurrentSet = JourneeViewModel.Instance.GetCurrentSet();
88 115

  
89
            ButtonText = chamberId.ToString();
116
            UpdateChamberId(chamberId);
117
        }
118

  
119
        #endregion
120

  
121
        #region Méthodes
122
        public void UpdateChamberId(int chamberId)
123
        {
90 124
            ChamberId = chamberId;
125
            UpdateProperties();
126
        }
127
        public void UpdateProperties()
128
        {
129
            AnimalSet = CurrentSet.GetSerieAnimalByNumBoite(ChamberId);
130
            ButtonText = ChamberId.ToString();
131

  
132
            int measureCount = AnimalSet?.GetMeasureCount() ?? 0;
91 133

  
92
            ButtonIsEnabled = JourneeViewModel.Instance.GetCurrentSet().GetIsInByNumeroBoite(chamberId);
93
            bool hasBehaviour = CurrentSet.GetHasBehaviourByNumeroBoite(chamberId);
94
            int count = CurrentSet.GetMeasureNumberByNumeroBoite(chamberId);
95
            if (hasBehaviour)
96
                ButtonBackgroundColor = Colors.Yellow;
97
            else
98
                ButtonBackgroundColor = count > 0 ? Colors.LightGreen : Colors.White;
99
            ButtonLabel = count.ToString();
134
            if (measureCount == 0)
135
                return;
136

  
137
            if (!_isSubscribed && !AnimalSet.IsOut)
138
            {
139
                _timer.Register(OnTimerTick);
140
                _isSubscribed = true;
141
            }
142

  
143
            if (_isSubscribed && AnimalSet.IsOut)
144
            {
145
                _timer.Unregister(OnTimerTick);
146
                _isSubscribed = false;
147
            }
148

  
149
            ButtonIsEnabled = !AnimalSet.IsOut;
150
            ButtonBackgroundColor = AnimalSet.HasBehaviour() ? Colors.Yellow : Colors.LightGreen;
151
            ButtonLabel = measureCount.ToString();
152
            TimeIn = AnimalSet.GetTimeInChamber();
100 153
        }
101
        private async Task GoToEnterAnimal()
154

  
155
        private async Task GoToChamber()
102 156
        {
103 157
            if (IsBusy) return;
104 158
            IsBusy = true;
105 159

  
106
            var targetView = (CurrentSet.GetMeasureNumberByNumeroBoite(ChamberId) == 0) ? nameof(EnterAnimalView) : nameof(CreateMeasureView);
160
            var targetView = (CurrentSet.GetSerieAnimalByNumBoite(ChamberId) == null) ? nameof(EnterAnimalView) : nameof(CreateMeasureView);
107 161

  
108 162
            await Shell.Current.GoToAsync($"{targetView}?chamberId={ChamberId}");
109 163

  
110 164
            IsBusy = false;
111 165
        }
166
        public void OnTimerTick(object? sender, EventArgs e)
167
        {
168
            TimeIn = AnimalSet?.GetTimeInChamber() ?? "";
169
        }
170

  
112 171
        #endregion
113 172
    }
114 173
}
GES_PAC/ViewModel/MainViewModel.cs
56 56
        public MainViewModel(ConnexionService connService)
57 57
        {
58 58
            //ONLY FOR TESTS
59
            //var date = DateTime.Now;
60
            //var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], "");
61
            //newDay.AddSet(new Serie(date, date, 25, 25, 25));
62
            //newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.Debut);
63
            //newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.Debut);
64
            //newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.Debut);
65
            //newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, ""));
66
            //newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false);
67
            //JourneeViewModel.Instance.Journees.Add(newDay);
59
            var date = DateTime.Now;
60
            var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], "");
61
            newDay.AddSet(new Serie(date, date, 25, 25, 25));
62
            newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.Debut);
63
            newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.Debut);
64
            newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.Debut);
65
            newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, ""));
66
            newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false);
67
            JourneeViewModel.Instance.Journees.Add(newDay);
68 68
            //ONLY FOR TESTS
69 69

  
70 70
            GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage());
GES_PAC/ViewModel/TimerPublisher.cs
1
namespace GES_PAC.ViewModel
2
{
3
    public class TimerPublisher
4
    {
5
        private readonly IDispatcherTimer _timer;
6
        public event EventHandler? Tick;
7

  
8
        public TimerPublisher()
9
        {
10
            _timer = Dispatcher.GetForCurrentThread().CreateTimer();
11
            _timer.Interval = TimeSpan.FromSeconds(15);
12
            _timer.Tick += (s, e) => Tick?.Invoke(this, EventArgs.Empty);
13
        }
14

  
15
        public void Start() => _timer.Start();
16
        public void Stop() => _timer.Stop();
17

  
18
        public void Register(EventHandler handler) => Tick += handler;
19
        public void Unregister(EventHandler handler) => Tick -= handler;
20
    }
21

  
22
}

Formats disponibles : Unified diff