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

Commit

Permalink
Updated the account omemo info with label support
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Mar 17, 2021
1 parent 0ca2e1e commit 8bb2ca4
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 120 deletions.
33 changes: 33 additions & 0 deletions UWPX_UI/Controls/OMEMO/OmemoDeviceControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<UserControl x:Class="UWPX_UI.Controls.OMEMO.OmemoDeviceControl"
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"
xmlns:omemo="using:UWPX_UI_Context.Classes.ValueConverter.OMEMO"
mc:Ignorable="d">

<UserControl.Resources>
<omemo:OmemoDeviceIdStringValueConverter x:Key="OmemoDeviceIdStringValueConverter"/>
</UserControl.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
MaxLines="1"
Style="{ThemeResource BaseLineTextBlockStyle}"
Text="{x:Bind VIEW_MODEL.MODEL.Label, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"/>
<TextBlock Grid.Row="1"
Foreground="{ThemeResource CaptionTextBrush}"
MaxLines="1"
Style="{ThemeResource CaptionLineTextBlockStyle}"
Text="{x:Bind Device.deviceId, Mode=OneWay, Converter={StaticResource OmemoDeviceIdStringValueConverter}}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"
Visibility="{x:Bind Device.deviceLabel, Mode=OneWay, Converter={StaticResource StringEmptyVisibilityValueConverter}}"/>
</Grid>
</UserControl>
64 changes: 64 additions & 0 deletions UWPX_UI/Controls/OMEMO/OmemoDeviceControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Storage.Classes.Models.Omemo;
using UWPX_UI_Context.Classes.DataContext.Controls.OMEMO;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace UWPX_UI.Controls.OMEMO
{
public sealed partial class OmemoDeviceControl: UserControl
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
public OmemoDeviceModel Device
{
get => (OmemoDeviceModel)GetValue(DeviceProperty);
set => SetValue(DeviceProperty, value);
}
public static readonly DependencyProperty DeviceProperty = DependencyProperty.Register(nameof(Device), typeof(OmemoDeviceModel), typeof(OmemoDeviceControl), new PropertyMetadata(null, OnDeviceChanged));

public readonly OmemoDeviceControlContext VIEW_MODEL = new OmemoDeviceControlContext();
#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--
public OmemoDeviceControl()
{
InitializeComponent();
}

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


#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--
private void UpdateView(DependencyPropertyChangedEventArgs e)
{
VIEW_MODEL.UpdateView(e);
}

#endregion

#region --Misc Methods (Private)--


#endregion

#region --Misc Methods (Protected)--


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

#endregion
}
}
25 changes: 6 additions & 19 deletions UWPX_UI/Controls/OMEMO/OmemoDeviceListControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@
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:datatemplates="using:UWPX_UI_Context.Classes.DataTemplates"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:local="using:UWPX_UI.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:omemo="using:Storage.Classes.Models.Omemo"
xmlns:omemoControls="using:UWPX_UI.Controls.OMEMO"
mc:Ignorable="d">

<UserControl.Resources>
<DataTemplate x:Key="DeviceTemplate"
x:DataType="datatemplates:UintDataTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0"
VerticalAlignment="Center"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="40"
Text="&#xE975;"/>
<TextBlock Grid.Column="1"
Margin="10,0,10,0"
VerticalAlignment="Center"
Text="{x:Bind Value}"/>
</Grid>
x:DataType="omemo:OmemoDeviceModel">
<omemoControls:OmemoDeviceControl Device="{x:Bind}"/>
</DataTemplate>
</UserControl.Resources>

Expand All @@ -52,12 +39,12 @@
extensions:ListViewExtensions.StretchItemContainerDirection="Both"
Background="{ThemeResource SystemControlBackgroundAltMediumBrush}"
ItemTemplate="{StaticResource DeviceTemplate}"
ItemsSource="{x:Bind VIEW_MODEL.MODEL.DEVICES}"
ItemsSource="{x:Bind Account.Client.dbAccount.omemoInfo.devices}"
SelectionMode="None"/>

<TextBlock Grid.Row="2"
Margin="0,10,0,0">
<Run Text="{x:Bind VIEW_MODEL.MODEL.DEVICES.Count.ToString(), Mode=OneWay, FallbackValue='0'}"/>
<Run Text="{x:Bind Account.Client.dbAccount.omemoInfo.devices.Count.ToString(), Mode=OneWay, FallbackValue='0'}"/>
<Run Text="device(s) found."/>
</TextBlock>

Expand Down
18 changes: 3 additions & 15 deletions UWPX_UI/Controls/OMEMO/OmemoDeviceListControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public AccountDataTemplate Account
get => (AccountDataTemplate)GetValue(AccountProperty);
set => SetValue(AccountProperty, value);
}
public static readonly DependencyProperty AccountProperty = DependencyProperty.Register(nameof(Account), typeof(AccountDataTemplate), typeof(OmemoDeviceListControl), new PropertyMetadata(null, OnAccountChanged));
public static readonly DependencyProperty AccountProperty = DependencyProperty.Register(nameof(Account), typeof(AccountDataTemplate), typeof(OmemoDeviceListControl), new PropertyMetadata(null));

public readonly OmemoDeviceListControlContext VIEW_MODEL = new OmemoDeviceListControlContext();

Expand All @@ -39,10 +39,6 @@ public OmemoDeviceListControl()
#endregion

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

#endregion

Expand All @@ -52,24 +48,16 @@ private void UpdateView(DependencyPropertyChangedEventArgs e)
#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--
private async void Reset_ibtn_Click(object sender, RoutedEventArgs args)
private async void Reset_ibtn_Click(IconProgressButtonControl sender, RoutedEventArgs args)
{
await VIEW_MODEL.ResetOmemoDevicesAsync(Account.Client);
}

private async void Refresh_ibtn_Click(object sender, RoutedEventArgs args)
private async void Refresh_ibtn_Click(IconProgressButtonControl sender, RoutedEventArgs args)
{
await VIEW_MODEL.RefreshOmemoDevicesAsync(Account.Client);
}

private static void OnAccountChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is OmemoDeviceListControl omemoDeviceListControl)
{
omemoDeviceListControl.UpdateView(e);
}
}

#endregion
}
}
96 changes: 83 additions & 13 deletions UWPX_UI/Controls/Settings/AccountOmemoInfoControl.xaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<UserControl x:Class="UWPX_UI.Controls.Settings.AccountOmemoInfoControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chat="using:UWPX_UI.Controls.Chat"
xmlns:controls="using:UWPX_UI.Controls"
xmlns:controlsOmemo="using:UWPX_UI.Controls.OMEMO"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:omemo="using:UWPX_UI_Context.Classes.ValueConverter.OMEMO"
Loaded="UserControl_Loaded"
mc:Ignorable="d">

<UserControl.Resources>
<omemo:OmemoHelperStateStringValueConverter x:Key="OmemoHelperStateStringValueConverter"/>
<omemo:OmemoHelperStateBrushValueConverter x:Key="OmemoHelperStateBrushValueConverter"/>
<omemo:OmemoDeviceIdStringValueConverter x:Key="OmemoDeviceIdStringValueConverter"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Resources/Styles/Button/TransparentThemeButtonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<omemo:OmemoHelperStateStringValueConverter x:Key="OmemoHelperStateStringValueConverter"/>
<omemo:OmemoHelperStateBrushValueConverter x:Key="OmemoHelperStateBrushValueConverter"/>
<omemo:OmemoDeviceIdStringValueConverter x:Key="OmemoDeviceIdStringValueConverter"/>
</ResourceDictionary>
</UserControl.Resources>

<ScrollViewer Margin="0,0,-10,0"
Expand All @@ -25,26 +32,89 @@
Text="{x:Bind VIEW_MODEL.MODEL.OmemoState, Mode=OneWay, Converter={StaticResource OmemoHelperStateStringValueConverter}}"/>
</TextBlock>

<controls:IconTextBlockControl HorizontalAlignment="Left"
Glyph="&#xE783;"
GlyphForeground="Red"
Text="{x:Bind VIEW_MODEL.MODEL.ErrorText, Mode=OneWay}"
Visibility="{x:Bind VIEW_MODEL.MODEL.ErrorText, Converter={StaticResource StringEmptyVisibilityValueConverter}}"/>
<controls:SeperatorControl Margin="-10,0,0,0"
Text="Fingerprint:"/>
<controlsOmemo:OmemoOwnFingerprintControl Margin="0,10,0,0"
Client="{x:Bind Account.Client, Mode=OneWay}"/>

<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>

<TextBlock Margin="0,10,0,0"
FontWeight="Bold"
Text="This device:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="name_tbx"
Grid.Column="0"
VerticalAlignment="Center"
IsTextSelectionEnabled="True"
MaxLines="1"
Style="{StaticResource SubtitleTextBlockStyle}"
Text="{x:Bind VIEW_MODEL.MODEL.DeviceLabel, Mode=OneWay}"
TextTrimming="CharacterEllipsis"/>
<chat:EnterTextBox x:Name="editLabel_tbx"
Grid.Column="0"
BeforeTextChanging="EditLabel_tbx_BeforeTextChanging"
EnterKeyDown="EditLabel_tbx_EnterKeyDown"
PlaceholderText="{x:Bind Account.Client.dbAccount.omemoInfo.deviceId, Mode=OneWay, Converter={StaticResource OmemoDeviceIdStringValueConverter}}"
Text="{x:Bind VIEW_MODEL.MODEL.DeviceLabel, Mode=TwoWay}"
Visibility="Collapsed"/>
<Button x:Name="editLabel_btn"
Grid.Column="1"
Margin="5,0,0,0"
Padding="0"
VerticalAlignment="Center"
Click="EditLabel_btn_Click"
Content="&#xE70F;"
FontWeight="Normal"
Style="{ThemeResource TransparentThemeButtonStyle}"/>
</Grid>
<TextBlock Grid.Row="1"
Margin="0,10,0,0"
Foreground="{ThemeResource CaptionTextBrush}"
MaxLines="1"
Style="{ThemeResource CaptionLineTextBlockStyle}"
Text="{x:Bind Account.Client.dbAccount.omemoInfo.deviceId, Mode=OneWay, Converter={StaticResource OmemoDeviceIdStringValueConverter}}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"
Visibility="{x:Bind Account.Client.dbAccount.omemoInfo.deviceLabel, Mode=OneWay, Converter={StaticResource StringEmptyVisibilityValueConverter}}"/>

<Grid Margin="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

</Grid>

<controlsOmemo:OmemoDeviceListControl Margin="0,10,0,0"
Account="{x:Bind Account, Mode=OneWay}"/>
</StackPanel>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="EditLabelGroup">
<VisualState x:Name="DisplayLabelState">
<VisualState.Setters>
<Setter Target="editLabel_btn.Content" Value="&#xE70F;"/>
<Setter Target="name_tbx.Visibility" Value="Visible"/>
<Setter Target="editLabel_tbx.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="EditLabelState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="editLabel_btn.Content" Value="&#xE74E;"/>
<Setter Target="name_tbx.Visibility" Value="Collapsed"/>
<Setter Target="editLabel_tbx.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</ScrollViewer>
</UserControl>
48 changes: 48 additions & 0 deletions UWPX_UI/Controls/Settings/AccountOmemoInfoControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UWPX_UI_Context.Classes.DataTemplates;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace UWPX_UI.Controls.Settings
{
Expand All @@ -17,6 +18,7 @@ public AccountDataTemplate Account
public static readonly DependencyProperty AccountProperty = DependencyProperty.Register(nameof(Account), typeof(AccountDataTemplate), typeof(AccountOmemoInfoControl), new PropertyMetadata(null, OnAccountChanged));

public readonly AccountOmemoInfoControlContext VIEW_MODEL = new AccountOmemoInfoControlContext();
private bool editingLabel = false;

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
Expand Down Expand Up @@ -44,6 +46,27 @@ private void UpdateView(DependencyPropertyChangedEventArgs e)
VIEW_MODEL.UpdateView(e);
}

private void UpdateViewState(string state)
{
VisualStateManager.GoToState(this, state, true);
}

private void UpdateEditLabelViewState()
{
if (editingLabel)
{
editLabel_tbx.Text = VIEW_MODEL.MODEL.DeviceLabel;
UpdateViewState(EditLabelState.Name);
ToolTipService.SetToolTip(editLabel_btn, new ToolTip { Content = "Save" });
}
else
{
UpdateViewState(DisplayLabelState.Name);
VIEW_MODEL.SaveDeviceLabel(editLabel_tbx.Text, Account.Client.dbAccount.omemoInfo);
ToolTipService.SetToolTip(editLabel_btn, new ToolTip { Content = "Change device label" });
}
}

#endregion

#region --Misc Methods (Protected)--
Expand All @@ -60,6 +83,31 @@ private static void OnAccountChanged(DependencyObject d, DependencyPropertyChang
}
}

private void EditLabel_tbx_BeforeTextChanging(TextBox sender, TextBoxBeforeTextChangingEventArgs args)
{
if (!string.Equals(args.NewText, args.NewText.TrimStart()))
{
args.Cancel = true;
}
}

private void EditLabel_tbx_EnterKeyDown(object sender, KeyRoutedEventArgs e)
{
editingLabel = false;
UpdateEditLabelViewState();
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
UpdateEditLabelViewState();
}

private void EditLabel_btn_Click(object sender, RoutedEventArgs e)
{
editingLabel = !editingLabel;
UpdateEditLabelViewState();
}

#endregion
}
}
Loading

0 comments on commit 8bb2ca4

Please sign in to comment.