Skip to content

Commit

Permalink
Yeah, I don't know, the terminal frustrates me...
Browse files Browse the repository at this point in the history
This is for issue #100.
  • Loading branch information
haefele committed Nov 3, 2016
1 parent ac8b419 commit d667702
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/CTime2/Views/Terminal/TerminalView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converter1="using:CTime2.Converter"
mc:Ignorable="d"
>
<Page.Resources>
<converter:FormatStringConverter x:Key="TimeToStringConverter"
FormatString="hh\:mm\:ss" />
<Style x:Key="RoundToggleButtonStyle" TargetType="ToggleButton">
<converter1:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
<Style x:Key="RoundToggleButtonStyle" TargetType="RadioButton">
<Setter Property="Background" Value="{ThemeResource ToggleButtonBackground}"/>
<Setter Property="Foreground" Value="{ThemeResource ToggleButtonForeground}"/>
<Setter Property="BorderBrush" Value="{ThemeResource ToggleButtonBorderBrush}"/>
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderThickness" Value="4"/>
<Setter Property="Padding" Value="8,4,8,4"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
Expand All @@ -30,7 +34,7 @@
<Setter Property="FocusVisualMargin" Value="-3"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<ControlTemplate TargetType="RadioButton">
<Grid x:Name="RootGrid" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
Expand Down Expand Up @@ -242,31 +246,56 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<ToggleButton Grid.Column="0"
<RadioButton Grid.Column="0"
Content="Normal Stempeln"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="20"
Style="{StaticResource RoundToggleButtonStyle}" />
Style="{StaticResource RoundToggleButtonStyle}">
<ToggleButton.IsChecked>
<Binding Path="StampMode" Converter="{StaticResource EnumToBooleanConverter}" Mode="TwoWay">
<Binding.ConverterParameter>
<local:TerminalStampMode>Normal</local:TerminalStampMode>
</Binding.ConverterParameter>
</Binding>
</ToggleButton.IsChecked>
</RadioButton>

<ToggleButton Grid.Column="1"
<RadioButton Grid.Column="1"
Content="Trip"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="20"
Style="{StaticResource RoundToggleButtonStyle}" />
Style="{StaticResource RoundToggleButtonStyle}">
<ToggleButton.IsChecked>
<Binding Path="StampMode" Converter="{StaticResource EnumToBooleanConverter}" Mode="TwoWay">
<Binding.ConverterParameter>
<local:TerminalStampMode>Trip</local:TerminalStampMode>
</Binding.ConverterParameter>
</Binding>
</ToggleButton.IsChecked>
</RadioButton>

<ToggleButton Grid.Column="2"
<RadioButton Grid.Column="2"
Content="Homeoffice"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="20"
Style="{StaticResource RoundToggleButtonStyle}" />
Style="{StaticResource RoundToggleButtonStyle}">
<ToggleButton.IsChecked>
<Binding Path="StampMode" Converter="{StaticResource EnumToBooleanConverter}" Mode="TwoWay">
<Binding.ConverterParameter>
<local:TerminalStampMode>HomeOffice</local:TerminalStampMode>
</Binding.ConverterParameter>
</Binding>
</ToggleButton.IsChecked>
</RadioButton>
</Grid>

<TextBox x:Name="RfidReaderTextBox"
Text="{Binding RfidKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Opacity="0"
PreventKeyboardDisplayOnProgrammaticFocus="True"
IsHitTestVisible="False"
Grid.Row="0">
<interactivity:Interaction.Behaviors>
Expand Down
49 changes: 49 additions & 0 deletions src/CTime2/Views/Terminal/TerminalViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Caliburn.Micro;
Expand All @@ -11,19 +12,30 @@
using ReactiveUI;
using UwCore;
using UwCore.Common;
using UwCore.Logging;
using UwCore.Services.ApplicationState;

namespace CTime2.Views.Terminal
{
public enum TerminalStampMode
{
Normal,
HomeOffice,
Trip,
Pause,
}

public class TerminalViewModel : ReactiveScreen
{
private readonly ICTimeService _cTimeService;
private readonly IApplicationStateService _applicationStateService;

private readonly Timer _timer;
private readonly Timer _resetModeTimer;

private TimeSpan _currentTime;
private string _rfidKey;
private TerminalStampMode _stampMode;

public TimeSpan CurrentTime
{
Expand All @@ -37,6 +49,12 @@ public string RfidKey
set { this.RaiseAndSetIfChanged(ref this._rfidKey, value); }
}

public TerminalStampMode StampMode
{
get { return this._stampMode; }
set { this.RaiseAndSetIfChanged(ref this._stampMode, value); }
}

public UwCoreCommand<Unit> Stamp { get; }

public TerminalViewModel(ICTimeService cTimeService, IApplicationStateService applicationStateService)
Expand All @@ -52,7 +70,24 @@ public TerminalViewModel(ICTimeService cTimeService, IApplicationStateService ap
.HandleExceptions()
.ShowLoadingOverlay("Stempeln...");

this.StampMode = TerminalStampMode.Normal;
this.WhenAnyValue(f => f.StampMode)
.Subscribe(stampMode =>
{
if (stampMode == TerminalStampMode.Normal)
{
//Stop the timer
this._resetModeTimer?.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromSeconds(10));
}
else
{
//Start the timer
this._resetModeTimer?.Change(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));
}
});

this._timer = new Timer(this.Tick, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(100));
this._resetModeTimer = new Timer(this.ResetModeTick, null, TimeSpan.FromMilliseconds(-1), TimeSpan.FromSeconds(10));

this.DisplayName = "Terminal";
}
Expand All @@ -65,6 +100,20 @@ private void Tick(object state)
});
}

private void ResetModeTick(object state)
{
Execute.OnUIThread(() =>
{
if (this.StampMode != TerminalStampMode.Normal)
{
this.StampMode = TerminalStampMode.Normal;
}

//Stop the timer
this._resetModeTimer?.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromSeconds(10));
});
}

private async Task StampImpl()
{
await this._cTimeService.SaveTimer(
Expand Down

0 comments on commit d667702

Please sign in to comment.