Skip to content
Permalink
Browse files

Added a start over again IoT register button

  • Loading branch information...
COM8 committed Sep 10, 2019
1 parent 965f4cf commit df61058b64e4845390b523f096734bd745772abb
@@ -1,10 +1,60 @@
<UserControl x:Class="UWPX_UI.Controls.IoT.BluetoothScannerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:controls1="using:UWPX_UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Unloaded="UserControl_Unloaded"
mc:Ignorable="d">

<Grid/>
<Grid>
<!-- Loading: -->
<controls:Loading x:Name="loading_grid"
IsLoading="True">
<controls1:LoadingContentControl Text="Scanning for device..."/>
</controls:Loading>

<!-- Error: -->
<Grid x:Name="error_grid"
Grid.Row="0"
Margin="0,10,0,0"
Padding="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="{ThemeResource AppBackgroundAcrylicElementBrush}"
CornerRadius="5"
Visibility="Visible">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
HorizontalAlignment="Center"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="50"
Foreground="Red"
Text="&#xE783;"/>
<TextBlock Grid.Row="1"
HorizontalAlignment="Center"
Text="{x:Bind VIEW_MODEL.MODEL.ErrorMsg, Mode=OneWay}"
TextWrapping="Wrap"/>
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="States">
<VisualState x:Name="State_Scanning">
<VisualState.Setters>
<Setter Target="step1ScanQrCode_dsp.Visibility" Value="Visible"/>
<Setter Target="step2Bluetooth_dsp.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="State_Error">
<VisualState.Setters>
<Setter Target="step1ScanQrCode_dsp.Visibility" Value="Collapsed"/>
<Setter Target="step2Bluetooth_dsp.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</UserControl>
@@ -40,6 +40,11 @@ public async Task StartAsync()
await VIEW_MODEL.StartAsync(RegisterIoTUriAction.MAC);
}

public void Stop()
{
VIEW_MODEL.Stop();
}

#endregion

#region --Misc Methods (Private)--
@@ -55,15 +60,22 @@ public async Task StartAsync()
#region --Events--
private async static void OnRegisterIoTUriActionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is BluetoothScannerControl bluetoothScannerControl && e.NewValue is RegisterIoTUriAction)
if (d is BluetoothScannerControl bluetoothScannerControl)
{
await bluetoothScannerControl.StartAsync();
if (e.NewValue is RegisterIoTUriAction)
{
await bluetoothScannerControl.StartAsync();
}
else
{
bluetoothScannerControl.Stop();
}
}
}

private void UserControl_Unloaded(object sender, RoutedEventArgs e)
{
VIEW_MODEL.Stop();
Stop();
}

#endregion
@@ -85,6 +85,7 @@ public async Task StartAsync()
return;
}
isRunning = true;
VIEW_MODEL.MODEL.QrCode = "";
StartQrCodeTask();
await camera_pvc.StartPreviewAsync();
}
@@ -149,11 +149,17 @@
</Grid.ColumnDefinitions>
<controls:IconButtonControl x:Name="cancel2_ibtn"
Grid.Column="0"
Margin="0,0,0,1"
Margin="0,0,1,0"
Click="Cancel_ibtn_Click"
Glyph="&#xE711;"
GlyphForeground="Red"
Text="Cancel"/>
<controls:IconButtonControl x:Name="retry_ibtn"
Grid.Column="2"
Margin="1,0,0,0"
Click="Retry_ibtn_Click"
Glyph="&#xE777;"
Text="Retry"/>
</Grid>
</StackPanel>
</Border>
@@ -83,6 +83,13 @@ private async void QrCodeScannerControl_NewValidQrCode(QrCodeScannerControl send
}
}

private async void Retry_ibtn_Click(IconButtonControl sender, RoutedEventArgs args)
{
VIEW_MODEL.MODEL.RegisterIoTUriAction = null;
UpdateViewState(State_1.Name);
await qrCodeScanner.StartAsync();
}

#endregion
}
}
@@ -83,12 +83,15 @@ private void Scanner_StateChanged(BLEScanner scanner, BLEScannerStateChangedEven
break;

case BLEScannerState.ERROR_BLE_NOT_SUPPORTED:
MODEL.ErrorMsg = "Your device does not support Bluetooth LE!";
break;

case BLEScannerState.ERROR_BLUETOOTH_NOT_SUPPORTED:
MODEL.ErrorMsg = "No Bluetooth radio available!";
break;

case BLEScannerState.ERROR_BLUETOOTH_DISABLED:
MODEL.ErrorMsg = "Bluetooth disabled!";
break;
}
}
@@ -6,7 +6,12 @@ public class BluetoothScannerControlDataTemplate: AbstractDataTemplate
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--

private string _ErrorMsg;
public string ErrorMsg
{
get => _ErrorMsg;
set => SetProperty(ref _ErrorMsg, value);
}

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\

0 comments on commit df61058

Please sign in to comment.
You can’t perform that action at this time.