-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced Page System & Created Settings Page
- Loading branch information
1 parent
f5ea3e5
commit c102375
Showing
6 changed files
with
262 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.