Skip to content

Commit

Permalink
Pl-lang button translated, break timer implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
enviGit committed Mar 15, 2023
1 parent df40bcb commit 4ddbd57
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
11 changes: 10 additions & 1 deletion PomodoroTimer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
</Image.OpacityMask>
</Image>

<TextBlock x:Name="BreakTimeLabel" Text="" TextAlignment="Center" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="45"
Margin="0,10,0,0" Width="330" Height="126" Visibility="Collapsed">
<TextBlock.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA66767" Offset="1"/>
<GradientStop Color="#5FFF0000"/>
</LinearGradientBrush>
</TextBlock.Background>
</TextBlock>
<TextBlock x:Name="TimeRemainingLabel" Text="" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="48" FontWeight="Bold" Margin="0,0,0,225"/>

<ProgressBar x:Name="ProgressBar" Value="0" Minimum="0" Maximum="{Binding TotalSeconds}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10"
Expand All @@ -45,7 +54,7 @@
<StackPanel x:Name="SessionHeaders" Margin="10,245,10,41" Orientation="Horizontal" Visibility="Collapsed">
<TextBlock Text="Completion time" Margin="5,-10,5,5" FontWeight="Bold"/>
<TextBlock Text="Duration" Margin="53,-10,5,5" FontWeight="Bold"/>
<TextBlock Text="Usuń" Margin="40,-10,5,5" FontWeight="Bold"/>
<TextBlock Text="Remove" Margin="40,-10,5,5" FontWeight="Bold"/>
</StackPanel>

<ListBox x:Name="SessionList" Margin="10,255,10,32" Background="{x:Null}" BorderBrush="{x:Null}" Visibility="Collapsed">
Expand Down
66 changes: 61 additions & 5 deletions PomodoroTimer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace PomodoroTimer
public partial class MainWindow : Window
{
private Timer timer;
private Timer breakTimer;
private int breakTimeCountdown = 4;
private Timer breakTimerCountdown;
private ObservableCollection<Session> _sessions = new ObservableCollection<Session>();
private Session currentSession;

Expand All @@ -27,6 +30,12 @@ public MainWindow()
TimeSpan duration = TimeSpan.FromMinutes(25);
timer = new Timer(duration);
timer.Tick += Timer_Tick;
TimeSpan breakDuration = TimeSpan.FromMinutes(5);
breakTimer = new Timer(breakDuration);
breakTimer.Tick += BreakTimer_Tick;
TimeSpan breakCountdownDuration = TimeSpan.FromSeconds(4);
breakTimerCountdown = new Timer(breakCountdownDuration);
breakTimerCountdown.Tick += breakTimerCountdown_Tick;
ProgressBar.Maximum = duration.TotalSeconds;
ClearSessionsButton.Visibility = Visibility.Visible;
SessionHeaders.Visibility = Visibility.Visible;
Expand All @@ -37,7 +46,7 @@ public MainWindow()
string json = File.ReadAllText("sessions.json");
var sessionListItems = JsonConvert.DeserializeObject<List<Session>>(json);

if (sessionListItems == null)
if (sessionListItems == null)
return;

foreach (var sessionListItem in sessionListItems)
Expand All @@ -49,7 +58,7 @@ public MainWindow()
};
Sessions.Add(session);
}

SessionList.ItemsSource = Sessions.OrderByDescending(x => x.EndTime);
}
}
Expand All @@ -64,10 +73,14 @@ private void StartButton_Click(object sender, RoutedEventArgs e)
return;

timer.Start();
BreakTimeLabel.Visibility = Visibility.Visible;
TimeRemainingLabel.Visibility = Visibility.Visible;
}
private void PauseButton_Click(object sender, RoutedEventArgs e)
{
if (timer.IsPaused)
return;

timer.Pause();
}
private void ResetButton_Click(object sender, RoutedEventArgs e)
Expand All @@ -87,6 +100,7 @@ private void ResetButton_Click(object sender, RoutedEventArgs e)
timer.Reset();
UpdateTimeRemainingLabel();
SessionHeaders.Visibility = Visibility.Visible;
BreakTimeLabel.Visibility = Visibility.Collapsed;
TimeRemainingLabel.Visibility = Visibility.Collapsed;
ProgressBar.Visibility = Visibility.Collapsed;
ProgressBar.Value = 0;
Expand All @@ -100,6 +114,7 @@ private void Timer_Tick(object sender, EventArgs e)
Dispatcher.Invoke(() =>
{
bgImg.Effect = new BlurEffect { Radius = 20 };
BreakTimeLabel.Text = "Timer";
UpdateTimeRemainingLabel();
ProgressBar.Visibility = Visibility.Visible;
ProgressBar.Value = (timer.Duration - timer.TimeRemaining).TotalSeconds;
Expand All @@ -116,19 +131,60 @@ private void Timer_Tick(object sender, EventArgs e)
string json = JsonConvert.SerializeObject(Sessions, Formatting.Indented);
File.WriteAllText("sessions.json", json);
timer.Reset();
TimeRemainingLabel.Text = "";
SessionHeaders.Visibility = Visibility.Visible;
ProgressBar.Visibility = Visibility.Collapsed;
TimeRemainingLabel.Text = "";
currentSession = null;
SessionList.ItemsSource = Sessions.OrderByDescending(x => x.EndTime);
ClearSessionsButton.Visibility = Visibility.Visible;
SessionList.Visibility = Visibility.Visible;
breakTimerCountdown.Start();
}
});
}
private void BreakTimer_Tick(object sender, EventArgs e)
{
TimeSpan remainingTime = breakTimer.TimeRemaining;

Dispatcher.Invoke(() =>
{
bgImg.Effect = new BlurEffect { Radius = 20 };
BreakTimeLabel.Text = "Break timer";
TimeRemainingLabel.Text = remainingTime.ToString("mm\\:ss");

if (breakTimer.TimeRemaining == TimeSpan.Zero)
{
breakTimer.Reset();
TimeRemainingLabel.Text = "";
BreakTimeLabel.Text = "";
BreakTimeLabel.Visibility = Visibility.Collapsed;
MessageBox.Show("Your break session has ended!", "Break session ended", MessageBoxButton.OK, MessageBoxImage.Information);
bgImg.Effect = new BlurEffect { Radius = 0 };
}
});
}
private void breakTimerCountdown_Tick(object sender, EventArgs e)
{
Dispatcher.Invoke(() =>
{
bgImg.Effect = new BlurEffect { Radius = 20 };
breakTimeCountdown--;
BreakTimeLabel.Text = "Your break starts in " + breakTimeCountdown;

if (breakTimeCountdown == 0)
{
breakTimerCountdown.Reset();
bgImg.Effect = new BlurEffect { Radius = 0 };
breakTimeCountdown = 4;
BreakTimeLabel.Text = "";
breakTimer.Start();
}
});
}
private void UpdateTimeRemainingLabel()
{
TimeSpan remainingTime = timer.TimeRemaining;

Dispatcher.Invoke(() => TimeRemainingLabel.Text = remainingTime.ToString("mm\\:ss"));
}
private void DeleteSessionButton_Click(object sender, RoutedEventArgs e)
Expand All @@ -137,7 +193,7 @@ private void DeleteSessionButton_Click(object sender, RoutedEventArgs e)

if (session != null)
{
MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this session?",
MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this session?",
"Confirm deletion", MessageBoxButton.YesNo, MessageBoxImage.Question);

if (result == MessageBoxResult.Yes)
Expand All @@ -151,7 +207,7 @@ private void DeleteSessionButton_Click(object sender, RoutedEventArgs e)
}
private void ClearSessionsButton_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show("Are you sure you want to permanently delete all your sessions? This action cannot be undone!",
MessageBoxResult result = MessageBox.Show("Are you sure you want to permanently delete all your sessions? This action cannot be undone!",
"Confirm deletion", MessageBoxButton.YesNo, MessageBoxImage.Warning);

if (result == MessageBoxResult.Yes)
Expand Down

0 comments on commit 4ddbd57

Please sign in to comment.