Skip to content

Commit

Permalink
Introduced Page System & Created Settings Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Agent47Penguin committed Mar 7, 2023
1 parent f5ea3e5 commit c102375
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 165 deletions.
20 changes: 20 additions & 0 deletions MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Page x:Class="MyPomodoroApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MyPomodoroApp"
mc:Ignorable="d"
Title ="MainPage" d:DesignHeight="450" d:DesignWidth="450" Loaded="MainPage_Loaded">

<!--Content-->
<Grid>
<Grid Grid.Row="1" Background="#FF588157" Grid.ColumnSpan="2"/>
<Label x:Name="TimerLabel" Content="25:00" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,100,0,0" FontFamily="Bahnschrift" FontSize="48" Foreground="#FFDAD7CD"/>
<Label x:Name="StatusLabel" Content="Status" HorizontalAlignment="Center" Margin="0,160,0,0" VerticalAlignment="Top" FontFamily="Bahnschrift" FontSize="16" Foreground="#FFDAD7CD"/>
<Button x:Name="ToggleButton" Content="Start" HorizontalAlignment="Center" Margin="0,225,0,0" VerticalAlignment="Top" FontFamily="Bahnschrift" FontSize="36" Click="ToggleButton_Click" BorderBrush="#00707070" Background="#00DDDDDD" Foreground="#FFDAD7CD"/>
<Button x:Name="ResetButton" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Bottom" FontFamily="Bahnschrift" FontSize="18" Click="ResetButton_Click" Margin="10,0,0,10" BorderBrush="#00DAD7CD" Background="#00DDDDDD" Foreground="#7FDAD7CD"/>
<Button x:Name="SkipButton" Content="Skip" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontFamily="Bahnschrift" FontSize="18" Margin="0,0,10,10" Click="SkipButton_Click" Foreground="#FFDAD7CD" Background="#00DDDDDD" BorderBrush="#00707070"/>
<Label x:Name="SessionLabel" Content="1/4" HorizontalAlignment="Left" Margin="20,340,0,0" VerticalAlignment="Top" FontFamily="Bahnschrift" FontSize="16" Foreground="#FFDAD7CD"/>
</Grid>
</Page>
191 changes: 191 additions & 0 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace MyPomodoroApp
{
/// <summary>
/// Interaction logic for MainPage.xaml
/// </summary>
public partial class MainPage : Page
{
// Create the Timer
private static DispatcherTimer timer = new DispatcherTimer();

// Store the time remaining for the current session
private int minutes = 25;
private int seconds = 0;

// Store the statuses for the sessions
public static string workStatus = "Work";
private string longBreakStatus = "Long Break";
private string shortBreakStatus = "Short Break";

// Store the duration of each session
private int pomodoroTime = 25;
private int longBreakTime = 15;
private int shortBreakTime = 5;

// Store the current session number and maximum number of sessions
private int curSession = 1;
private int maxSessions = 4;

public MainPage()
{
InitializeComponent();
}

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// Set the initial values for the timer label and status label
UpdateTimerLabel();
StatusLabel.Content = workStatus;

// Set the interval of the timer to 1 second
timer.Interval = TimeSpan.FromSeconds(1);

// Attach the Tick event handler to the timer
timer.Tick += Timer_Tick;
}

private void Timer_Tick(object sender, EventArgs e)
{
// Decrement a second per tick
seconds--;

// If the number of seconds is less than 0, decrement the minutes and reset the number of seconds
if (seconds < 0)
{
minutes--;
seconds = 59;
}

// If the number of minutes and seconds is 0, move to the next stage.
if (minutes == 0 && seconds == 0)
{
NextStage();
timer.Start();
}
else
{
// Update Timer Label
UpdateTimerLabel();
}
}

private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
// If the timer is currently running stop it
if (timer.IsEnabled)
{
timer.Stop();
ToggleButton.Content = "Start";
}
else
{
// If the timer is not currently running, start it
timer.Start();
ToggleButton.Content = "Stop";
}
}

private void ResetButton_Click(object sender, RoutedEventArgs e)
{
Reset();
}

private void SkipButton_Click(object sender, RoutedEventArgs e)
{
// Move to the next stage
NextStage();

// Update timer label
UpdateTimerLabel();
}

private void Reset()
{
// Stop the timer
timer.Stop();

// Reset the number of minutes and seconds
minutes = pomodoroTime;
seconds = 0;

// Update label
UpdateTimerLabel();

// Update Status Label
StatusLabel.Content = workStatus;

// Reset Current Session and session label
curSession = 1;
UpdateSessionLabel();
}

private void NextStage()
{
// Stop the timer
timer.Stop();

// Reset the number of seconds
seconds = 0;

// Update the toggle button
ToggleButton.Content = "Start";

// Check the status of the timer and swithc to the next stage accordingly
if (StatusLabel.Content.ToString() == workStatus)
{
// If max sessions have been completed, start long break
if (curSession >= maxSessions)
{
minutes = longBreakTime;
StatusLabel.Content = longBreakStatus;
}
else
{
minutes = shortBreakTime;
StatusLabel.Content = shortBreakStatus;
}
}
else if (StatusLabel.Content.ToString() == longBreakStatus)
{
Reset();
}
else
{
minutes = pomodoroTime;
StatusLabel.Content = workStatus;

// One cycle has been completed
curSession++;
}

// Update the session label
UpdateSessionLabel();
}

private void UpdateTimerLabel()
{
TimerLabel.Content = string.Format("{0:00}:{1:00}", minutes, seconds);
}

private void UpdateSessionLabel()
{
SessionLabel.Content = string.Format("{0}/{1}", curSession, maxSessions);
}
}
}
9 changes: 2 additions & 7 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=GridHeader, Path=ActualHeight}"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button x:Name="SettingsButton" Content="~" FontFamily="Bahnschrift" Background="#00DDDDDD" BorderBrush="#00707070" Foreground="#FFDAD7CD" FontSize="24"/>
<Button x:Name="SettingsButton" Content="~" FontFamily="Bahnschrift" Background="#00DDDDDD" BorderBrush="#00707070" Foreground="#FFDAD7CD" FontSize="24" Click="SettingsButton_Click"/>
</Grid>
<Label x:Name="AppNameLabel" Content="MyPomodoroApp" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Bahnschrift" FontSize="18" Foreground="#FFDAD7CD"/>
</Grid>
<!--Content-->
<Grid Grid.Row="1" Background="#FF588157" Grid.ColumnSpan="2">
<Label x:Name="TimerLabel" Content="25:00" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,100,0,0" FontFamily="Bahnschrift" FontSize="48" Foreground="#FFDAD7CD"/>
<Label x:Name="StatusLabel" Content="Status" HorizontalAlignment="Center" Margin="0,160,0,0" VerticalAlignment="Top" FontFamily="Bahnschrift" FontSize="16" Foreground="#FFDAD7CD"/>
<Button x:Name="ToggleButton" Content="Start" HorizontalAlignment="Center" Margin="0,225,0,0" VerticalAlignment="Top" FontFamily="Bahnschrift" FontSize="36" Click="ToggleButton_Click" BorderBrush="#00707070" Background="#00DDDDDD" Foreground="#FFDAD7CD"/>
<Button x:Name="ResetButton" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Bottom" FontFamily="Bahnschrift" FontSize="18" Click="ResetButton_Click" Margin="10,0,0,10" BorderBrush="#00DAD7CD" Background="#00DDDDDD" Foreground="#7FDAD7CD"/>
<Button x:Name="SkipButton" Content="Skip" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontFamily="Bahnschrift" FontSize="18" Margin="0,0,10,10" Click="SkipButton_Click" Foreground="#FFDAD7CD" Background="#00DDDDDD" BorderBrush="#00707070"/>
<Label x:Name="SessionLabel" Content="1/4" HorizontalAlignment="Left" Margin="20,340,0,0" VerticalAlignment="Top" FontFamily="Bahnschrift" FontSize="16" Foreground="#FFDAD7CD"/>
<Frame x:Name="MainFrame" NavigationUIVisibility="Hidden" JournalOwnership="OwnsJournal"/>
</Grid>
</Grid>
</Window>
Loading

0 comments on commit c102375

Please sign in to comment.