Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                CurrentSession = new Session(5, TimeSpan.FromMinutes(25));
            }
            else
            {
                CurrentSession = new Session(1, Settings.WorkMinutes.Value);
                if (Settings.WasRunning.Value)
                {
                    CurrentSession = Settings.RunningSession.Value;
                }

                else
                {
                    CurrentSession = new Session(1, Settings.WorkMinutes.Value);
                }
            }
            _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(.1) };
            _timer.Tick += (s, e) =>
                               {
                                   var delta = DateTime.UtcNow - Settings.PreviousTick.Value;
                                   Settings.PreviousTick.Value += delta;
                                   CurrentSession.Minutes -= delta;
                                   Messenger.Default.Send(CurrentSession.Minutes.TotalSeconds, "ActualSeconds");
                                   if (CurrentSession.Minutes <= TimeSpan.FromSeconds(0))
                                   {
                                       _timeElapsedInBreakTime = TimeSpan.FromSeconds(Math.Abs(CurrentSession.Minutes.TotalSeconds));
                                       _timer.Stop();
                                       if (Settings.EnableSound.Value == true)
                                           _endSound.Play();
                                       if (Settings.EnableVibration.Value == true)
                                           VibrateController.Default.Start(TimeSpan.FromSeconds(1));
                                       UpdateSession();
                                   }
                               };
            PlayCommmand = new RelayCommand(StartSession);
            StopCommand = new RelayCommand(StopSession);
            OpenSettingsPageCommand = new RelayCommand(() => NavigationService.NavigateTo(ViewModelLocator.SettingsPageUri));
            OpenAboutPageCommand = new RelayCommand(() => NavigationService.NavigateTo(ViewModelLocator.AboutPageUri));
            OpenInstructionsPageCommand = new RelayCommand(() => NavigationService.NavigateTo(ViewModelLocator.InstructionsPageUri));
            UpdateSavedSessionCommand = new RelayCommand(UpdateSavedSession);

            SoundEffects.Initialize();
            _endSound = SoundEffects.EndSound.CreateInstance();
            _endSound.Volume = 1;

            Messenger.Default.Register<SessionMinutesChanged>(this, UpdateCurrentSession);

            if (Settings.WasRunning.Value)
                _timer.Start();
        }
Exemple #2
0
        private void UpdateUI(Session session)
        {
            if (!session.IsFreeTime) // If this is a new Session, the timer is stopped so we update the UI
            {
                ProgressBar.Maximum = Settings.WorkMinutes.Value.TotalSeconds;
                ProgressBar.Value = Settings.WorkMinutes.Value.TotalSeconds;
                Settings.WasRunning.Value = false;
                UpdateButton();
            }
            else
            {
                ProgressBar.Maximum = Settings.BreakMinutes.Value.TotalSeconds;
                ProgressBar.Value = Settings.BreakMinutes.Value.TotalSeconds;
            }

            UpdateSessionType(session.IsFreeTime);
        }
Exemple #3
0
        private void UpdateCurrentSession(SessionMinutesChanged obj)
        {
            if (_timer.IsEnabled)
                return;

            CurrentSession = new Session(1, Settings.WorkMinutes.Value);
        }
Exemple #4
0
 private void StopSession()
 {
     _timer.Stop();
     CurrentSession = new Session(1, Settings.WorkMinutes.Value);
     Settings.WasRunning.Value = false;
 }