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

Commit

Permalink
Second part of the previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Feb 12, 2019
1 parent ea83137 commit 3b221d1
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 50 deletions.
27 changes: 26 additions & 1 deletion UWPX_UI/Controls/OMEMO/OmemoFingerprintControl.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
<UserControl x:Class="UWPX_UI.Controls.OMEMO.OmemoFingerprintControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:UWPX_UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid/>
<Grid Visibility="{x:Bind VIEW_MODEL.MODEL.Fingerprint, Mode=OneWay, Converter={StaticResource StringEmptyVisabilityValueConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Margin="0,10,10,0"
IsTextSelectionEnabled="True"
Text="{x:Bind VIEW_MODEL.MODEL.Fingerprint, Mode=OneWay}"
TextWrapping="WrapWholeWords"/>
<Button x:Name="cpyFingerprint_btn"
Grid.Column="1"
VerticalAlignment="Center"
Click="CpyFingerprint_btn_Click"
Content="&#xE8C8;"
FontFamily="Segoe MDL2 Assets"/>
</Grid>
<controls:QrCodeControl Grid.Row="1"
Margin="0,10,0,0"
QrCodeText="{x:Bind VIEW_MODEL.MODEL.Fingerprint, Mode=OneWay}"/>
</Grid>
</UserControl>
12 changes: 10 additions & 2 deletions UWPX_UI/Controls/OMEMO/OmemoFingerprintControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UWPX_UI_Context.Classes.DataTemplates;
using UWPX_UI_Context.Classes.DataContext.Controls;
using UWPX_UI_Context.Classes.DataTemplates;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

Expand All @@ -15,6 +16,8 @@ public AccountDataTemplate Account
}
public static readonly DependencyProperty AccountProperty = DependencyProperty.Register(nameof(Account), typeof(AccountDataTemplate), typeof(OmemoFingerprintControl), new PropertyMetadata(null, OnAccountChanged));

public readonly OmemoFingerprintControlContext VIEW_MODEL = new OmemoFingerprintControlContext();

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--
Expand Down Expand Up @@ -53,10 +56,15 @@ private static void OnAccountChanged(DependencyObject d, DependencyPropertyChang
{
if (d is OmemoFingerprintControl omemoFingerprintControl)
{
omemoDeviceListControl.UpdateView(e);
omemoFingerprintControl.UpdateView(e);
}
}

private void CpyFingerprint_btn_Click(object sender, RoutedEventArgs e)
{
VIEW_MODEL.CopyFingerprintToClipboard();
}

#endregion
}
}
23 changes: 23 additions & 0 deletions UWPX_UI/Controls/QrCodeControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<UserControl x:Class="UWPX_UI.Controls.QrCodeControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0"
Margin="0,0,0,10"
Content="Default QR-Code"
IsChecked="{x:Bind VIEW_MODEL.MODEL.DefaultQrCode, Mode=TwoWay}"/>
<Image Grid.Row="1"
Source="{x:Bind VIEW_MODEL.MODEL.QrCodeImage, Mode=OneWay}"/>
<ProgressRing Grid.Row="1"
IsActive="True"
Visibility="{x:Bind VIEW_MODEL.MODEL.IsLoading, Mode=OneWay, Converter={StaticResource BoolVisabilityValueConverter}}"/>
</Grid>
</UserControl>
64 changes: 64 additions & 0 deletions UWPX_UI/Controls/QrCodeControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using UWPX_UI_Context.Classes.DataContext.Controls;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace UWPX_UI.Controls
{
public sealed partial class QrCodeControl : UserControl
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
public string QrCodeText
{
get { return (string)GetValue(QrCodeTextProperty); }
set { SetValue(QrCodeTextProperty, value); }
}
public static readonly DependencyProperty QrCodeTextProperty = DependencyProperty.Register(nameof(QrCodeText), typeof(string), typeof(QrCodeControl), new PropertyMetadata("", OnQrCodeTextChanged));

public readonly QrCodeControlContext VIEW_MODEL = new QrCodeControlContext();

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--
public QrCodeControl()
{
this.InitializeComponent();
}

#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
#region --Set-, Get- Methods--


#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--


#endregion

#region --Misc Methods (Private)--
private void UpdateView(DependencyPropertyChangedEventArgs e)
{
VIEW_MODEL.UpdateView(e);
}

#endregion

#region --Misc Methods (Protected)--


#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--
private static void OnQrCodeTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is QrCodeControl qrCodeControl)
{
qrCodeControl.UpdateView(e);
}
}

#endregion
}
}
53 changes: 24 additions & 29 deletions UWPX_UI/Controls/Settings/AccountOmemoInfoControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,31 @@
<omemo:OmemoDeviceIdStringValueConverter x:Key="OmemoDeviceIdStringValueConverter"/>
</UserControl.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollMode="Disabled">
<StackPanel>
<TextBlock>
<Run FontWeight="Bold"
Text="Status:"/>
<Run Foreground="{x:Bind VIEW_MODEL.MODEL.OmemoState, Mode=OneWay, Converter={StaticResource OmemoHelperStateBrushValueConverter}}"
Text="{x:Bind VIEW_MODEL.MODEL.OmemoState, Mode=OneWay, Converter={StaticResource OmemoHelperStateStringValueConverter}}"/>
</TextBlock>

<TextBlock Grid.Row="0">
<Run FontWeight="Bold"
Text="OMEMO session:"/>
<Run Foreground="{x:Bind VIEW_MODEL.MODEL.OmemoState, Mode=OneWay, Converter={StaticResource OmemoHelperStateBrushValueConverter}}"
Text="{x:Bind VIEW_MODEL.MODEL.OmemoState, Mode=OneWay, Converter={StaticResource OmemoHelperStateStringValueConverter}}"/>
</TextBlock>
<controls:IconTextBlockControl Text="{x:Bind VIEW_MODEL.MODEL.ErrorText, Mode=OneWay}"
Visibility="{x:Bind VIEW_MODEL.MODEL.ErrorText, Converter={StaticResource StringEmptyVisabilityValueConverter}}"/>
<controls:SeperatorControl Margin="-10,0,0,0"
Text="Fingerprint:"/>
<controlsOmemo:OmemoFingerprintControl Account="{x:Bind Account, Mode=OneWay}"/>

<controls:IconTextBlockControl Grid.Row="1"
Text="{x:Bind VIEW_MODEL.MODEL.ErrorText, Mode=OneWay}"
Visibility="{x:Bind VIEW_MODEL.MODEL.ErrorText, Converter={StaticResource StringEmptyVisabilityValueConverter}}"/>
<controls:SeperatorControl Margin="-10,0,0,0"
Text="Devices:"/>
<TextBlock Margin="0,10,0,0">
<Run FontWeight="Bold"
Text="Your OMEMO device ID:"/>
<Run Text="{x:Bind VIEW_MODEL.MODEL.DeviceId, Mode=OneWay, Converter={StaticResource OmemoDeviceIdStringValueConverter}}"/>
</TextBlock>

<controlsOmemo:OmemoFingerprintControl Grid.Row="2"/>

<TextBlock Grid.Row="3"
Margin="0,10,0,0">
<Run FontWeight="Bold"
Text="Your OMEMO device ID:"/>
<Run Text="{x:Bind VIEW_MODEL.MODEL.DeviceId, Mode=OneWay, Converter={StaticResource OmemoDeviceIdStringValueConverter}}"/>
</TextBlock>

<controlsOmemo:OmemoDeviceListControl Grid.Row="4"
Account="{x:Bind Account, Mode=OneWay}"/>
</Grid>
<controlsOmemo:OmemoDeviceListControl Margin="0,10,0,0"
Account="{x:Bind Account, Mode=OneWay}"/>
</StackPanel>
</ScrollViewer>
</UserControl>
7 changes: 7 additions & 0 deletions UWPX_UI/UWPX_UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
<Compile Include="Controls\OMEMO\OmemoFingerprintControl.xaml.cs">
<DependentUpon>OmemoFingerprintControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\QrCodeControl.xaml.cs">
<DependentUpon>QrCodeControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\SeperatorControl.xaml.cs">
<DependentUpon>SeperatorControl.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -428,6 +431,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\QrCodeControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\SeperatorControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UWPX_UI_Context.Classes.DataTemplates;
using UWPX_UI_Context.Classes.DataTemplates.Controls;
using Windows.UI.Xaml;

namespace UWPX_UI_Context.Classes.DataContext.Controls
{
class OmemoFingerprintControlContext
public sealed class OmemoFingerprintControlContext
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--

public readonly OmemoFingerprintControlDataTemplate MODEL = new OmemoFingerprintControlDataTemplate();

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
Expand All @@ -25,7 +23,22 @@ class OmemoFingerprintControlContext
#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--

public void UpdateView(DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is AccountDataTemplate account)
{
MODEL.UpdateView(account);
}
else
{
MODEL.UpdateView(null);
}
}

public void CopyFingerprintToClipboard()
{
UiUtils.SetClipboardText(MODEL.Fingerprint);
}

#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using UWPX_UI_Context.Classes.DataTemplates.Controls;
using Windows.UI.Xaml;

namespace UWPX_UI_Context.Classes.DataContext.Controls
{
public sealed class QrCodeControlContext
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
public readonly QrCodeControlDataTemplate MODEL = new QrCodeControlDataTemplate();

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--


#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
#region --Set-, Get- Methods--


#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--
public void UpdateView(DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is string s)
{
MODEL.UpdateView(s);
}
else
{
MODEL.UpdateView(null);
}
}

#endregion

#region --Misc Methods (Private)--


#endregion

#region --Misc Methods (Protected)--


#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--


#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using libsignal;
using Shared.Classes;
using XMPP_API.Classes.Crypto;

namespace UWPX_UI_Context.Classes.DataTemplates.Controls
{
class OmemoFingerprintControlDataTemplate
public sealed class OmemoFingerprintControlDataTemplate : AbstractDataTemplate
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--

private string _Fingerprint;
public string Fingerprint
{
get { return _Fingerprint; }
set { SetProperty(ref _Fingerprint, value); }
}

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
Expand All @@ -25,7 +28,23 @@ class OmemoFingerprintControlDataTemplate
#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--

public void UpdateView(AccountDataTemplate account)
{
if (!(account is null))
{
IdentityKey key = account.Account.omemoIdentityKeyPair?.getPublicKey();
if (!(key is null))
{
Fingerprint = CryptoUtils.genOmemoFingerprint(key);
return;
}
else
{
Fingerprint = "Failed to load fingerprint!";
}
}
Fingerprint = "";
}

#endregion

Expand Down
Loading

0 comments on commit 3b221d1

Please sign in to comment.