From f726944dd4600b9f1c2379381659cfb7e0be7181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Troja=C5=84ski?= <80624809+enviGit@users.noreply.github.com> Date: Tue, 28 Feb 2023 20:58:13 +0100 Subject: [PATCH] Subsequent uses of the pause feature fixed --- PomodoroTimer/Models/Timer.cs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/PomodoroTimer/Models/Timer.cs b/PomodoroTimer/Models/Timer.cs index fcdc276..23cea54 100644 --- a/PomodoroTimer/Models/Timer.cs +++ b/PomodoroTimer/Models/Timer.cs @@ -12,6 +12,7 @@ public class Timer : INotifyPropertyChanged private bool _isRunning; private bool _isPaused; private TimeSpan _remainingTimeOnPause; + private TimeSpan _remainingTimeOnResume; public event PropertyChangedEventHandler PropertyChanged; private System.Timers.Timer _timer; public event EventHandler Tick; @@ -57,6 +58,7 @@ public void Start() return; IsRunning = true; + IsPaused = false; if (_timer != null) { @@ -67,20 +69,6 @@ public void Start() _timer = new System.Timers.Timer(1000); _timer.Elapsed += OnTimerElapsed; - if (!IsPaused) - { - TimeRemaining = Duration; - } - else if (IsPaused) - { - if (_remainingTimeOnPause.TotalMilliseconds > 0) - TimeRemaining = _remainingTimeOnPause; - else - TimeRemaining = Duration; - - _remainingTimeOnPause = TimeSpan.Zero; - } - _timer.Start(); } public void Pause() @@ -88,13 +76,13 @@ public void Pause() if (!IsRunning || IsPaused) return; - IsPaused = true; - _remainingTimeOnPause = TimeRemaining; - if (_timer != null) _timer.Stop(); IsRunning = false; + IsPaused = true; + + _remainingTimeOnPause = TimeRemaining; } public void Reset() { @@ -117,6 +105,9 @@ private void OnTimerElapsed(object sender, ElapsedEventArgs e) IsPaused = false; } + if (IsPaused) + _remainingTimeOnPause = TimeRemaining; + OnTick(); } private void OnTick()