2 using System.Windows.Input;
4 using Fitness.Services;
5 using Tizen.Multimedia.Vision;
6 using Tizen.NUI.Binding;
8 namespace Fitness.ViewModels
11 /// Class handling the exercising view.
13 public class ExercisingViewModel : ChangeWorkoutViewModel
15 private WorkoutState state;
16 private IExerciseService squatService;
19 private int repetitions;
20 private Landmark[,] poseLandmarks;
23 /// Initializes a new instance of the <see cref="ExercisingViewModel"/> class.
25 /// <param name="workoutViewModel">Workout view model information.</param>
26 public ExercisingViewModel(WorkoutViewModel workoutViewModel)
28 PauseResumeWorkout = new Command(TriggerPauseResumeWorkout);
29 TryAgain = new Command(ExecuteTryAgain);
30 EndWorkout = new Command(ExecuteEndWorkout);
31 State = WorkoutState.Playing;
32 CurrentWorkout = workoutViewModel;
33 squatService = new SquatService()
35 HoldTimeThreshold = 1200,
37 squatService.ExerciseStateUpdated += SquatService_ExerciseStateUpdated;
41 /// Gets the pose landmark property.
43 public Landmark[,] PoseLandmarks
48 if (value != poseLandmarks)
50 poseLandmarks = value;
51 RaisePropertyChanged();
57 /// Gets the property specifying the correctness of the exercise - values ranging from 0 to 100.
67 RaisePropertyChanged();
73 /// Gets the property specifying the number of repetitions of the exercise.
75 public int Repetitions
80 if (value != repetitions)
83 RaisePropertyChanged();
89 /// Gets the property specifying the time of the exercise performed - values ranging from 0 to 5.
99 RaisePropertyChanged();
105 /// Gets the TimeLeft in workout.
107 public TimeSpan TimeLeft { get; private set; } = TimeSpan.FromSeconds(27);
110 /// Gets the current workout state.
112 public WorkoutState State
120 RaisePropertyChanged();
126 /// Gets the pause workout command.
128 public ICommand Pause { get; private set; }
131 /// Gets the URL to video with workout.
133 public string WorkoutVideoUrl { get; private set; }
136 /// Gets the URL to preview from device camera.
138 public string PreviewVideoUrl { get; private set; }
141 /// Gets Prev Command.
143 public ICommand Prev { get; private set; }
146 /// Gets Next Command.
148 public ICommand Next { get; private set; }
151 /// Gets PauseWorkout Command.
153 public ICommand PauseResumeWorkout { get; private set; }
156 /// Gets TryAgain Command.
158 public ICommand TryAgain { get; private set; }
161 /// Gets EndWorkout Command.
163 public ICommand EndWorkout { get; private set; }
166 /// Gets the pause/resume label.
168 public string PauseResumeLabel { get; private set; } = "Pause";
171 /// Gets the <see cref="SquatService"/> property.
173 public IExerciseService SquatService { get; private set; }
176 protected override void GoPrevious()
178 if (State == WorkoutState.Playing)
180 State = WorkoutState.Paused;
183 Services.NavigationService.Instance.NavigateToSummaryView(SummaryType.ChangeToPreviousWorkout, CurrentWorkout);
187 protected override void GoNext()
189 if (State == WorkoutState.Playing)
191 State = WorkoutState.Paused;
194 Services.NavigationService.Instance.NavigateToSummaryView(SummaryType.ChangeToNextWorkout, CurrentWorkout);
197 private void SquatService_ExerciseStateUpdated(object sender, ExerciseEventArgs e)
199 PoseLandmarks = e.PoseLandmarks;
201 Repetitions = e.Count;
205 private void TriggerPauseResumeWorkout()
207 if (State == WorkoutState.Paused)
209 State = WorkoutState.Playing;
211 else if (State == WorkoutState.Playing)
213 State = WorkoutState.Paused;
217 private void ExecuteTryAgain()
219 Services.NavigationService.Instance.NavigateToSummaryView(SummaryType.TryAgain, CurrentWorkout);
222 private void ExecuteEndWorkout()
224 Services.NavigationService.Instance.NavigateToSummaryView(SummaryType.EndWorkout, CurrentWorkout);