Skip to content

Commit

Permalink
Added count up sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed Apr 6, 2020
1 parent eb78bb6 commit 3047e16
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 84 deletions.
4 changes: 2 additions & 2 deletions TimerPlus/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
52 changes: 43 additions & 9 deletions TimerPlus/ScreenSessions.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<UserControl.Resources>
<local:BoolToVisibilityConverter
x:Key="BoolToVisibilityConverter" />
<local:TimeSpanToStringConverter
x:Key="TimeSpanToStringConverter" />
</UserControl.Resources>
<materialDesign:ColorZone
Mode="PrimaryDark"
Expand Down Expand Up @@ -107,21 +109,29 @@
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="Auto"
SharedSizeGroup="gp1"/>
Width="Auto"
SharedSizeGroup="gp1" />
<ColumnDefinition
Width="Auto"
SharedSizeGroup="gp2" />
<ColumnDefinition
Width="Auto"
SharedSizeGroup="gp3" />
</Grid.ColumnDefinitions>
<TextBlock
VerticalAlignment="Center"
Margin="10"
Style="{DynamicResource MaterialDesignSubtitle1TextBlock}"
Text="{Binding Name}">
</TextBlock>
<StackPanel
Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Margin="10"
Style="{DynamicResource MaterialDesignSubtitle1TextBlock}"
Text="{Binding Name}">
</TextBlock>
<materialDesign:PackIcon
VerticalAlignment="Center"
Margin="-5 0 10 0"
Visibility="{Binding CountUp, Converter={StaticResource BoolToVisibilityConverter}}"
Kind="Stopwatch" />
</StackPanel>
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Expand All @@ -140,7 +150,7 @@
VerticalAlignment="Center"
Margin="10"
Style="{DynamicResource MaterialDesignBody1TextBlock}"
Text="{Binding Time}">
Text="{Binding StatsTime, Converter={StaticResource TimeSpanToStringConverter}}">
</TextBlock>
</Grid>
</StackPanel>
Expand Down Expand Up @@ -168,6 +178,12 @@
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<TextBox
Name="txtNewSessionName"
Margin="0 0 24 0"
Expand Down Expand Up @@ -197,6 +213,24 @@
Name="timeNewSession"
WithSeconds="True"
Width="120" />
<CheckBox
Grid.Row="1"
Grid.Column="1"
Name="checkCountUp"
Checked="checkCountUp_Checked"
Unchecked="checkCountUp_Unchecked">
<StackPanel
Orientation="Horizontal">
<materialDesign:PackIcon
VerticalAlignment="Center"
Margin="0 2 5 2"
Kind="Stopwatch" />
<TextBlock
VerticalAlignment="Center">
Count up
</TextBlock>
</StackPanel>
</CheckBox>
</Grid>
<Button
Name="btnNewSession"
Expand Down
40 changes: 37 additions & 3 deletions TimerPlus/ScreenSessions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void btnNewSession_Click(object sender, RoutedEventArgs e)
Keyboard.Focus(txtNewSessionName);
return;
}
if (timeNewSession.SelectedTime == null)
if (timeNewSession.SelectedTime == null && !checkCountUp.IsChecked.GetValueOrDefault())
{
timeNewSession.Focus();
Keyboard.Focus(timeNewSession);
Expand All @@ -99,16 +99,38 @@ private void btnNewSession_Click(object sender, RoutedEventArgs e)
{
id = Helper.RandomString(10);
} while (SavedState.Data.SessionTypes.Select(x => x.Id).Contains(id));
SavedState.Data.SessionTypes.Add(new SessionType(id, txtNewSessionName.Text, timeNewSession.SelectedTime.Value - DateTime.Today));
if (checkCountUp.IsChecked.GetValueOrDefault())
{
SavedState.Data.SessionTypes.Add(new SessionType(id, txtNewSessionName.Text, TimeSpan.FromSeconds(0), true));
}
else
{
SavedState.Data.SessionTypes.Add(new SessionType(id, txtNewSessionName.Text, timeNewSession.SelectedTime.Value - DateTime.Today, false));
}
SavedState.Save();
expanderNewSession.IsExpanded = false;
snackbar.MessageQueue.Enqueue("New session type created");
}
else
{
EditSession.Name = txtNewSessionName.Text;
EditSession.Time = timeNewSession.SelectedTime.Value - DateTime.Today;
EditSession.CountUp = checkCountUp.IsChecked.GetValueOrDefault();
if (EditSession.CountUp)
{
EditSession.Time = TimeSpan.FromSeconds(0);
}
else
{
EditSession.Time = timeNewSession.SelectedTime.Value - DateTime.Today;
}
SavedState.Save();
foreach (DaySummary daySummary in SavedState.Data.DaySummaries)
{
if (daySummary.Records.Select(x => x.TypeId).Contains(EditSession.Id))
{
daySummary.NotifyStatsChanged();
}
}
expanderNewSession.IsExpanded = false;
expanderNewSession.Header = "New Session Type";
snackbar.MessageQueue.Enqueue("Session type saved");
Expand Down Expand Up @@ -150,6 +172,7 @@ private void btnEdit_Click(object sender, RoutedEventArgs e)
expanderNewSession.IsExpanded = true;
txtNewSessionName.Text = type.Name;
timeNewSession.SelectedTime = DateTime.Today + type.Time;
checkCountUp.IsChecked = type.CountUp;
NewSessionNameValidationRule.CheckDuplicate = false;
}

Expand All @@ -166,6 +189,17 @@ private void btnDelete_Click(object sender, RoutedEventArgs e)
SavedState.Save();
snackbar.MessageQueue.Enqueue("Session type deleted");
}

private void checkCountUp_Checked(object sender, RoutedEventArgs e)
{
timeNewSession.IsEnabled = false;
timeNewSession.SelectedTime = null;
}

private void checkCountUp_Unchecked(object sender, RoutedEventArgs e)
{
timeNewSession.IsEnabled = true;
}
}

public class NewSessionNameValidationRule : ValidationRule
Expand Down
Loading

0 comments on commit 3047e16

Please sign in to comment.