Skip to content

Commit

Permalink
Subsequent uses of the pause feature fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
enviGit committed Feb 28, 2023
1 parent a7838e1 commit f726944
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions PomodoroTimer/Models/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void Start()
return;

IsRunning = true;
IsPaused = false;

if (_timer != null)
{
Expand All @@ -67,34 +69,20 @@ 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()
{
if (!IsRunning || IsPaused)
return;

IsPaused = true;
_remainingTimeOnPause = TimeRemaining;

if (_timer != null)
_timer.Stop();

IsRunning = false;
IsPaused = true;

_remainingTimeOnPause = TimeRemaining;
}
public void Reset()
{
Expand All @@ -117,6 +105,9 @@ private void OnTimerElapsed(object sender, ElapsedEventArgs e)
IsPaused = false;
}

if (IsPaused)
_remainingTimeOnPause = TimeRemaining;

OnTick();
}
private void OnTick()
Expand Down

0 comments on commit f726944

Please sign in to comment.