private void UpdateForStateChange(GymTimerConfig config) { TimerElapsed = TimeSpan.Zero; if (TimerState == TimerStateEnum.GET_READY || TimerState == TimerStateEnum.BREAK) { if (TimerState == TimerStateEnum.BREAK) { Iteration++; } TimerState = TimerStateEnum.WORKOUT; TimerColor = config.WorkoutTimeColor; TimerTimeSpan = config.WorkoutTime; } else if (TimerState == TimerStateEnum.WORKOUT) { if (Iteration < config.Iterations) { TimerState = TimerStateEnum.BREAK; TimerTimeSpan = config.BreakTime; TimerColor = config.BreakTimeColor; } else { TimerState = TimerStateEnum.END; TimerTimeSpan = TimeSpan.Zero; TimerColor = config.WorkoutOverTimeColor; this.Stop(); } } }
public void Reset(GymTimerConfig config) { Running = false; TimerState = TimerStateEnum.GET_READY; Iteration = 1; TimerColor = config.InitialBufferTimeColor; TimerTimeSpan = config.InitialBufferTime; TimerElapsed = TimeSpan.Zero; }
private void InitTimer() { _config = new GymTimerConfig(); _state = new GymTimerState(); _state.Reset(_config); _dispatchTimer = new DispatcherTimer(); _dispatchTimer.Interval = _state.TimerTickSpan; _dispatchTimer.Tick += DispatcherTimer_Tick; _state.Start(); _dispatchTimer.Start(); }
public void State_Tick(GymTimerConfig config) { if (!Running) { return; } TimerElapsed += TimerTickSpan; if (TimerState == TimerStateEnum.WORKOUT && (TimerTimeSpan - TimerElapsed) <= TimeSpan.FromSeconds(10)) { TimerColor = config.WorkoutCloseToOverTimeColor; } if (TimerElapsed >= TimerTimeSpan) { UpdateForStateChange(config); } }