Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
Ring Blink on LockAction in progress
Browse files Browse the repository at this point in the history
Ring is closed when locked
  • Loading branch information
BoBiene committed Jan 22, 2017
1 parent bcce3aa commit 47f4064
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Nuki UWP/Converter/LockStateConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Data;
using Nuki.Communication.API;

namespace Nuki.Converter
{
public class LockStateConverter : IValueConverter
{
public NukiLockState LockState { get; set; }
public bool Inverted { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
bool blnRet = false;
NukiLockState state;
if (Enum.TryParse<NukiLockState>(value?.ToString(), out state))
{
blnRet = state == LockState;

}
else { }

if (Inverted)
blnRet = !blnRet;
return blnRet;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions Nuki UWP/Nuki.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Converter\LockStateConverter.cs" />
<Compile Include="Converter\SubstractConverter.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Converter\MultiplyConverter.cs" />
Expand Down
31 changes: 31 additions & 0 deletions Nuki UWP/Views/NukiLockHome.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<UserControl.Resources>
<Converter:MultiplyConverter Value="0.5" x:Name="DiameterToRadius" />
<Converter:SubstractConverter Value="10" x:Name="RadiusToInnerRadius" />
<Converter:LockStateConverter LockState="Locked" x:Name="IsLocked" />
<Converter:LockStateConverter LockState="Locked" Inverted="True" x:Name="IsNotLocked" />
<Converter:SubstractConverter Value="40" x:Name="ContainerMargin" />
<Style TargetType="Button" x:Key="CommandButton">
<Setter Property="Width" Value="200"/>
Expand All @@ -31,6 +33,13 @@
<Setter Property="Margin" Value="10,10,10,0" />

</Style>
<Storyboard x:Name="lockActionInProgess" RepeatBehavior="Forever" AutoReverse="True">
<DoubleAnimation
Storyboard.TargetName="RingContainer"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:1"
/>
</Storyboard>

</UserControl.Resources>
<Grid>
Expand Down Expand Up @@ -71,6 +80,26 @@
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="RingState">
<VisualState>
<VisualState.StateTriggers>
<StateTrigger IsActive="{x:Bind ViewModel.LockState, Converter={StaticResource IsLocked}, Mode=OneWay}"></StateTrigger>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="MyRingSlice.StartAngle" Value="1"></Setter>
<Setter Target="MyRingSlice.EndAngle" Value="359"></Setter>
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<StateTrigger IsActive="{x:Bind ViewModel.LockState, Converter={StaticResource IsNotLocked}, Mode=OneWay}"></StateTrigger>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="MyRingSlice.StartAngle" Value="50"></Setter>
<Setter Target="MyRingSlice.EndAngle" Value="310"></Setter>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<FlipView SelectedIndex="{x:Bind ViewModel.SelectedFlipViewIndex, Mode=TwoWay}">
<Grid Background="{StaticResource ResourceKey=ContrastColorBrush}" >
Expand All @@ -81,6 +110,7 @@
</TextBlock>
</Grid>
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<RelativePanel x:Name="RingContainer" VerticalAlignment="Center"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Expand Down Expand Up @@ -112,6 +142,7 @@
Fill="{StaticResource ApplicationForegroundThemeBrush}"
Radius="100"
InnerRadius="90">

</controls:RingSegment>

</Grid>
Expand Down
24 changes: 24 additions & 0 deletions Nuki UWP/Views/NukiLockHome.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ public sealed partial class NukiLockHome : UserControl
public NukiLockHome()
{
this.InitializeComponent();
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
lockActionInProgess.Begin();
}

private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ViewModel.LockState))
{
switch (ViewModel.LockState)
{

case Communication.API.NukiLockState.Unlocking:

case Communication.API.NukiLockState.Locking:

case Communication.API.NukiLockState.Unlatching:
lockActionInProgess.Begin();
break;
default:
lockActionInProgess.Stop();
break;
}
}
else { }
}
}
}

0 comments on commit 47f4064

Please sign in to comment.