Skip to content

Commit

Permalink
Start function for resuming timer fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
enviGit committed Feb 28, 2023
1 parent 51e9f7e commit 55afa8c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion PomodoroTimer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Grid>
<Image gif:ImageBehavior.AnimatedSource="Resources/bg.gif"/>

<TextBlock x:Name="TimeRemainingLabel" Text="" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="48" Margin="0,0,0,125"/>
<TextBlock x:Name="TimeRemainingLabel" Text="" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="48" Margin="0,0,0,125" Background="#3F000000"/>

<ProgressBar x:Name="ProgressBar" Value="0" Minimum="0" Maximum="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10" Visibility="Collapsed"/>

Expand Down
2 changes: 2 additions & 0 deletions PomodoroTimer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System;
using System.Windows;

#nullable disable

namespace PomodoroTimer
{
public partial class MainWindow : Window
Expand Down
30 changes: 21 additions & 9 deletions PomodoroTimer/Models/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,28 @@ public void Start()
return;

IsRunning = true;
IsPaused = false;

if (_timer == null)
if (_timer != null)
{
_timer = new System.Timers.Timer(1000);
_timer.Elapsed += OnTimerElapsed;
_timer.Stop();
_timer.Dispose();
}

if (IsPaused)
_timer = new System.Timers.Timer(1000);
_timer.Elapsed += OnTimerElapsed;

if (!IsPaused)
{
TimeRemaining = Duration;
}
else if (IsPaused)
{
_timeRemaining = _remainingTimeOnPause;
if (_remainingTimeOnPause.TotalMilliseconds > 0)
TimeRemaining = _remainingTimeOnPause;
else
TimeRemaining = Duration;

_remainingTimeOnPause = TimeSpan.Zero;
}

_timer.Start();
Expand All @@ -78,11 +89,12 @@ public void Pause()
return;

IsPaused = true;
_remainingTimeOnPause = TimeRemaining;

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

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

Tick?.Invoke(this, EventArgs.Empty);
OnTick();
}
private void OnTick()
{
if (Tick != null)
Tick(this, EventArgs.Empty);
}
}
}
}
7 changes: 3 additions & 4 deletions PomodoroTimer/PomodoroTimer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\appIcon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,13 +18,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="WpfAnimatedGif" Version="2.0.2" />
<Content Include="Resources\appIcon.ico" />
</ItemGroup>

<ItemGroup>
<Reference Include="Lighty.Controls">
<HintPath>C:\Users\Envi\.nuget\packages\lighty.controls\1.0.3\lib\net45\Lighty.Controls.dll</HintPath>
</Reference>
<PackageReference Include="WpfAnimatedGif" Version="2.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file added PomodoroTimer/Resources/appIcon.ico
Binary file not shown.

0 comments on commit 55afa8c

Please sign in to comment.