Skip to content
Snippets Groups Projects
Commit a2c4378c authored by Martin Hustoles's avatar Martin Hustoles
Browse files

Merge branch 'session' into 'develop'

added Timer functionality

See merge request !14
parents f66b88a6 dabd27c6
No related branches found
No related tags found
1 merge request!14added Timer functionality
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
Height="550" Width="900"> Height="550" Width="900">
<Grid> <Grid>
<header:HeaderTemplate VerticalAlignment="Top"/> <header:HeaderTemplate VerticalAlignment="Top"/>
<Button Content="Subscription" Style="{StaticResource TopMenuButon}" HorizontalAlignment="Right" Margin="0,4,180,0" VerticalAlignment="Top" Height="26" Width="80"/>
<Button Content="Subscription" Style="{StaticResource TopMenuButon}" HorizontalAlignment="Right" Margin="0,4,180,0" VerticalAlignment="Top" Height="26" Width="80" Click="Option1_Click"/> <Button Content="Contact" Style="{StaticResource TopMenuButon}" HorizontalAlignment="Right" Margin="0,4,100,0" VerticalAlignment="Top" Height="26" Width="80"/>
<Button Content="Contract" Style="{StaticResource TopMenuButon}" HorizontalAlignment="Right" Margin="0,4,100,0" VerticalAlignment="Top" Height="26" Width="80" Click="Option2_Click"/> <Button Content="Distractions" Style="{StaticResource TopMenuButon}" HorizontalAlignment="Right" Margin="0,4,20,0" VerticalAlignment="Top" Height="26" Width="80"/>
<Button Content="Distractions" Style="{StaticResource TopMenuButon}" HorizontalAlignment="Right" Margin="0,4,20,0" VerticalAlignment="Top" Height="26" Width="80" Click="Option3_Click"/> <TextBlock Name ="Title" Text="Focus Session 0 of 0" Style="{StaticResource Heading1}" HorizontalAlignment="Center" Height="42" TextWrapping="Wrap" VerticalAlignment="Top" Width="442" Margin="0,133,0,0"/>
<TextBlock Name="Clock" Text="00:00" Style="{StaticResource Heading1}" HorizontalAlignment="Center" Height="104" TextWrapping="Wrap" VerticalAlignment="Top" Width="326" Margin="0,180,0,0" FontSize="72" FontWeight="Bold"/>
<!-- DELETE --> <Rectangle Name="ProgressBar" Style="{StaticResource CircleSmall}" HorizontalAlignment="Center" Margin="0,289,0,0" VerticalAlignment="Top" Width="407"/>
<Label Content="Session Page" HorizontalAlignment="Center" Margin="0,234,0,0" VerticalAlignment="Top" Height="108" Width="439" FontSize="48" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> <Button Content="Start" Name="PlayPauseButton" Style="{StaticResource PlayPauseButton}" HorizontalAlignment="Center" Margin="0,346,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Click="Button_Click"/>
</Grid> </Grid>
</Window> </Window>
\ No newline at end of file
using System.Text; using System.Diagnostics;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
...@@ -8,6 +9,7 @@ using System.Windows.Media; ...@@ -8,6 +9,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Windows.Threading;
namespace InnoLabProjektDektopApp namespace InnoLabProjektDektopApp
{ {
...@@ -16,22 +18,99 @@ namespace InnoLabProjektDektopApp ...@@ -16,22 +18,99 @@ namespace InnoLabProjektDektopApp
/// </summary> /// </summary>
public partial class Session : Window public partial class Session : Window
{ {
private Timer timer;
private const int maxTime = (0 * 60) + 5;//(40 * 60) + 0;
private int seconds = maxTime; // (Minutes * [constant]) + Seconds
private int step = 0;
private const int sessions = 4;
private int currentSession = 1;
public Session() public Session()
{ {
InitializeComponent(); InitializeComponent();
GlobalSettings.setDefaults(this); GlobalSettings.setDefaults(this);
timer = new Timer(timertick, null,0,1000);
updateTexts();
} }
private void Option1_Click(object sender, RoutedEventArgs e)
private void timertick(object state)
{
Dispatcher.Invoke(() =>
{
seconds += step;
updateTexts();
ProgressBar.Fill = GradientGenerator.generateTwoColorBrush(Color.FromRgb(72, 98, 132), Color.FromRgb(222, 222, 222), 1 - (seconds / (double)maxTime));
if (seconds <= 0)
{
stopTimer();
currentSession++;
seconds = maxTime;
if (currentSession > sessions)
{ {
//this.Content = new AnotherWindow().Content; timer.Dispose();
} }
private void Option2_Click(object sender, RoutedEventArgs e) }
});
}
public void startTimer()
{
if (seconds <= 0) return;
step = -1;
PlayPauseButton.Content = "Pause";
}
public void stopTimer()
{ {
//this.Content = new AnotherWindow().Content; step = 0;
PlayPauseButton.Content = "Start";
} }
private void Option3_Click(object sender, RoutedEventArgs e)
public void setTime(int minutes, int seconds)
{ {
//this.Content = new AnotherWindow().Content; if (minutes < 0 || minutes > maxTime / 60 || seconds < 0 || seconds > maxTime % 60) return;
seconds = minutes * 60 + seconds;
updateTexts();
} }
private void updateTexts()
{
Clock.Text = seconds / 60 + ":" + (seconds % 60 < 10 ? "0" : "") + seconds % 60;
Title.Text = "Focus Session " + currentSession + " of " + sessions;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (step < 0) {
stopTimer();
} else {
startTimer();
}
}
}
}
public static class GradientGenerator
{
public static Brush generateTwoColorBrush(Color color1, Color color2, double ratio)
{
GradientStopCollection collection = new GradientStopCollection();
collection.Add(new GradientStop(color1, 0));
collection.Add(new GradientStop(color1, ratio));
collection.Add(new GradientStop(color2, ratio));
collection.Add(new GradientStop(color2, 1.0));
LinearGradientBrush brush = new LinearGradientBrush(collection);
brush.StartPoint = new Point(0, 0);
brush.EndPoint = new Point(1, 0);
return brush;
} }
} }
\ No newline at end of file
...@@ -59,4 +59,50 @@ ...@@ -59,4 +59,50 @@
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0"/>
</Style> </Style>
<Style TargetType="Rectangle" x:Key="MainColor">
<Setter Property="Stroke" Value="DarkGray"/>
<Setter Property="StrokeThickness" Value="2"/>
</Style>
<Style TargetType="Rectangle" x:Key="CircleSmall">
<Setter Property="Fill" Value="#DEDEDE"/>
<Setter Property="StrokeThickness" Value="0"/>
<Setter Property="Width" Value="30"/>
<Setter Property="Height" Value="30"/>
<Setter Property="RadiusX" Value="15"/>
<Setter Property="RadiusY" Value="15"/>
</Style>
<Style TargetType="Button" x:Key="PlayPauseButton">
<Setter Property="Background" Value="#486284"/>
<Setter Property="Foreground" Value="#ffffff"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Width" Value="80"/>
<Setter Property="Height" Value="60"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
CornerRadius="30">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#394f6b"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="TextBlock" x:Key="Heading1">
<Setter Property="Foreground" Value="#486284"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="FontSize" Value="35"/>
</Style>
</ResourceDictionary> </ResourceDictionary>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment