Exemplo n.º 1
0
        void TimerView_SizeChanged(object sender, EventArgs e)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            if (TrackBar == null || ProgressBar == null)
            {
                return;
            }

            if (Children.Count == 0)
            {
                //ensure track-bar gets full width and height as parent
                AddTrackBar();

                //ensure progress-bar gets full height, but width can be changed
                AddProgressBar();

                //if timer-label available, ensure it gets full width and height
                if (TimerLabel != null)
                {
                    AddTimerLabel();
                    TimerLabel.SetBinding(BindingContextProperty, new Binding(nameof(RemainingTime), source: this));
                }

                if (AutoStart)
                {
                    StartTimerCommand.Execute(Time);
                }
            }
            else
            {
                if (IsTimerRunning)
                {
                    //if timer runnnig already - restart animation
                    ProgressBar.CancelWidthToAnimation();
                    StartTimerCommand.Execute(null); //Use remaining time
                }
                else
                {
                    SetProgressBarWidth();
                }
            }
        }
        /// <summary>
        /// When power mode changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
        {
            switch (e.Mode)
            {
            case PowerModes.Suspend:
                if (_timer.IsEnabled)
                {
                    StopTimerCommand.Execute(null);
                    _isPowerModeChanged = true;
                }
                break;

            case PowerModes.Resume:
                if (_isPowerModeChanged)
                {
                    StartTimerCommand.Execute(null);
                    _isPowerModeChanged = false;
                    CommandManager.InvalidateRequerySuggested();
                }
                break;
            }
        }
        /// <summary>
        ///     Notify the user about the next break.
        /// </summary>
        /// <param name="seconds"></param>
        private void NotifyNextBreak(int seconds)
        {
            BreakNotifierViewModel breakNotifierViewModel = new BreakNotifierViewModel(seconds);
            BreakNotifierView      breakNotifierView      = new BreakNotifierView {
                DataContext = breakNotifierViewModel
            };

            if (breakNotifierView.ShowDialog() == true)
            {
                if (breakNotifierViewModel.IsManuallyStopped)
                {
                    return;
                }
                else if (breakNotifierViewModel.IsNextBreakSkipped)
                {
                    StartTimerCommand.Execute(null);
                }
                else
                {
                    StartRelaxation();
                }
            }
        }