/// <summary>
 /// Stop the timer.
 /// </summary>
 private void StopTimer()
 {
     _timer.Stop();
     RemainingTime = BreakTimerHelper.GetFormattedTimeFromMinutes(BreakTimer.Frequency);
     _counter      = 0;
     IsNotRunning  = true;
     _isPaused     = false;
     CommandManager.InvalidateRequerySuggested();
 }
 /// <summary>
 /// Parameterless constructor for break timer.
 /// </summary>
 public BreakTimerViewModel()
 {
     Type = Pages.BreakTimer;
     InitializeCommands();
     InitializeTimer();
     AttachEvents();
     LoadUserConfiguration();
     RemainingTime = BreakTimerHelper.GetFormattedTimeFromMinutes(BreakTimer.Frequency);
     _soundPlayer  = new SoundPlayer(AlertSoundPath);
     IsNotRunning  = true;
 }
Exemple #3
0
        /// <summary>
        /// Called when timer tick event raises.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTimerTick(object sender, EventArgs e)
        {
            _counter++;
            int seconds = _duration * 60 - _counter;

            RemainingTime = BreakTimerHelper.GetFormattedTimeFromSeconds(seconds);
            if (seconds == 0)
            {
                StopTimerCommand.Execute(null);
            }
        }
Exemple #4
0
        public RelaxationViewModel(string message, int duration, bool allowStopBreak)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(message);
            }

            if (duration <= 0)
            {
                throw new ArgumentNullException(nameof(duration));
            }


            Message         = message;
            _duration       = duration;
            _allowStopBreak = allowStopBreak;
            RemainingTime   = BreakTimerHelper.GetFormattedTimeFromMinutes(duration);
            InitializeTimer();
            InitializeCommands();
        }
        /// <summary>
        /// Initializes commands
        /// </summary>
        protected override void InitializeCommands()
        {
            StartTimerCommand = new RelayCommand(p => StartTimer(), p => CanStartTimer());
            StopTimerCommand  = new RelayCommand(p => StopTimer(), p => CanStopTimer());
            PauseTimerCommand = new RelayCommand(p => PauseTimer(), p => CanPauseTimer());

            IncreaseFrequencyCommand = new RelayCommand(p => {
                BreakTimer.Frequency++;
                RemainingTime = BreakTimerHelper.GetFormattedTimeFromMinutes(BreakTimer.Frequency);
            }, p => IsNotRunning);

            IncreaseLengthCommand = new RelayCommand(p => {
                BreakTimer.Length++;
            }, p => IsNotRunning);

            IncreaseNextBreakAlertCommand = new RelayCommand(p => {
                BreakTimer.NextBreakAlert++;
            }, p => IsNotRunning);

            IncreaseIdleResetTimeCommand = new RelayCommand(p => {
                BreakTimer.IdleResetTime++;
            }, p => IsNotRunning);

            DecreaseFrequencyCommand = new RelayCommand(p => {
                BreakTimer.Frequency--;
                RemainingTime = BreakTimerHelper.GetFormattedTimeFromMinutes(BreakTimer.Frequency);
            }, p => BreakTimer.Frequency > 0 && IsNotRunning);

            DecreaseLengthCommand = new RelayCommand(p => {
                BreakTimer.Length--;
            }, p => BreakTimer.Length > 0 && IsNotRunning);

            DecreaseNextBreakAlertCommand = new RelayCommand(p => {
                BreakTimer.NextBreakAlert--;
            }, p => BreakTimer.NextBreakAlert > 0 && IsNotRunning);

            DecreaseIdleResetTimeCommand = new RelayCommand(p => {
                BreakTimer.IdleResetTime--;
            }, p => BreakTimer.IdleResetTime > 0 && IsNotRunning);
        }
        /// <summary>
        /// Timer tick event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTimerTick(object sender, EventArgs e)
        {
            _counter++;
            int seconds = BreakTimer.Frequency * 60 - _counter;

            RemainingTime = BreakTimerHelper.GetFormattedTimeFromSeconds(seconds);
            if (UserIdleHelper.GetLastInputTime() == BreakTimer.IdleResetTime * 60 && BreakTimer.IsIdleResetActive)
            {
                StopTimerCommand.Execute(null);
            }
            else if (seconds == BreakTimer.NextBreakAlert)
            {
                StopTimerCommand.Execute(null);
                if (BreakTimer.NextBreakAlert != 0)
                {
                    NotifyNextBreak(BreakTimer.NextBreakAlert);
                }
                else
                {
                    StartRelaxation();
                }
            }
        }