OpenDatabase control now handles status changes with VisualStateManager instead of Vm

Opening DB shows a progress ring instead
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-30 11:10:10 +02:00
parent 9fdc727787
commit d2814c6c67
10 changed files with 72 additions and 90 deletions

View File

@@ -129,9 +129,6 @@
<data name="CompositeKeyErrorUserPassword" xml:space="preserve"> <data name="CompositeKeyErrorUserPassword" xml:space="preserve">
<value>- password incorrect</value> <value>- password incorrect</value>
</data> </data>
<data name="CompositeKeyOpening" xml:space="preserve">
<value>Opening...</value>
</data>
<data name="CompositeKeyUpdated" xml:space="preserve"> <data name="CompositeKeyUpdated" xml:space="preserve">
<value>Database credentials updated.</value> <value>Database credentials updated.</value>
</data> </data>
@@ -264,9 +261,6 @@
<data name="HistoryDeleteTitle" xml:space="preserve"> <data name="HistoryDeleteTitle" xml:space="preserve">
<value>Delete history entry ?</value> <value>Delete history entry ?</value>
</data> </data>
<data name="CompositeKeyOpenButtonLabel" xml:space="preserve">
<value>Open</value>
</data>
<data name="FileNotFoundDescription" xml:space="preserve"> <data name="FileNotFoundDescription" xml:space="preserve">
<value>File does not exist anymore</value> <value>File does not exist anymore</value>
</data> </data>

View File

@@ -129,9 +129,6 @@
<data name="CompositeKeyErrorUserPassword" xml:space="preserve"> <data name="CompositeKeyErrorUserPassword" xml:space="preserve">
<value>- mot de passe incorrect</value> <value>- mot de passe incorrect</value>
</data> </data>
<data name="CompositeKeyOpening" xml:space="preserve">
<value>Ouverture...</value>
</data>
<data name="CompositeKeyUpdated" xml:space="preserve"> <data name="CompositeKeyUpdated" xml:space="preserve">
<value>Identifiants de la base de données mis à jour.</value> <value>Identifiants de la base de données mis à jour.</value>
</data> </data>
@@ -264,9 +261,6 @@
<data name="HistoryDeleteTitle" xml:space="preserve"> <data name="HistoryDeleteTitle" xml:space="preserve">
<value>Supprimer cet historique ?</value> <value>Supprimer cet historique ?</value>
</data> </data>
<data name="CompositeKeyOpenButtonLabel" xml:space="preserve">
<value>Open</value>
</data>
<data name="FileNotFoundDescription" xml:space="preserve"> <data name="FileNotFoundDescription" xml:space="preserve">
<value>Le fichier n'existe plus.</value> <value>Le fichier n'existe plus.</value>
</data> </data>

View File

@@ -8,7 +8,7 @@
xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
mc:Ignorable="d"> mc:Ignorable="d">
<Grid> <Grid>
<ProgressRing x:Name="LoadingRing" IsActive="True" Width="50" Height="50" Foreground="{StaticResource MainColor}" /> <ProgressRing x:Name="LoadingRing" IsActive="True" Width="50" Height="50" Foreground="{StaticResource MainColorBrush}" />
<WebView Source="https://PayPal.Me/wismna"> <WebView Source="https://PayPal.Me/wismna">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="DOMContentLoaded"> <core:EventTriggerBehavior EventName="DOMContentLoaded">

View File

@@ -9,10 +9,14 @@
xmlns:converters="using:ModernKeePass.Converters" xmlns:converters="using:ModernKeePass.Converters"
mc:Ignorable="d" > mc:Ignorable="d" >
<UserControl.Resources> <UserControl.Resources>
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/> <converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
</UserControl.Resources> </UserControl.Resources>
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=OpenDatabaseControl}"> <Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=OpenDatabaseControl}">
<Grid.Resources>
<SolidColorBrush x:Key="ErrorBrush" Color="Red" />
</Grid.Resources>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="50" /> <ColumnDefinition Width="50" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
@@ -24,7 +28,7 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0" IsChecked="{Binding HasPassword, Mode=TwoWay}" /> <CheckBox Grid.Row="0" Grid.Column="0" IsChecked="{Binding HasPassword, Mode=TwoWay}" />
<PasswordBox Grid.Row="0" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding Password, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" KeyDown="PasswordBox_KeyDown" BorderBrush="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" > <PasswordBox x:Name="PasswordBox" Grid.Row="0" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding Password, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" KeyDown="PasswordBox_KeyDown" >
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="GotFocus"> <core:EventTriggerBehavior EventName="GotFocus">
<core:ChangePropertyAction TargetObject="{Binding}" PropertyName="HasPassword" Value="True" /> <core:ChangePropertyAction TargetObject="{Binding}" PropertyName="HasPassword" Value="True" />
@@ -33,16 +37,52 @@
</PasswordBox> </PasswordBox>
<CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" /> <CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" />
<HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0" <HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0"
x:Name="HyperlinkButton"
Content="{Binding KeyFileText}" Content="{Binding KeyFileText}"
IsEnabled="{Binding HasKeyFile}" IsEnabled="{Binding HasKeyFile}"
Click="KeyFileButton_Click" /> Click="KeyFileButton_Click" />
<Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" <Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2"
Content="{Binding OpenButtonLabel}" x:Uid="OpenDatabaseControlButton"
Visibility="{Binding IsOpening, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
Command="{Binding OpenDatabaseCommand}" Command="{Binding OpenDatabaseCommand}"
CommandParameter="{Binding DatabaseFilePath, ElementName=UserControl}" /> CommandParameter="{Binding DatabaseFilePath, ElementName=UserControl}" />
<ProgressRing Grid.Column="0" Grid.Row="2" IsActive="{Binding IsOpening}" Visibility="{Binding IsOpening, Converter={StaticResource BooleanToVisibilityConverter}}" Foreground="{StaticResource MainColorBrush}" />
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Height="Auto" FontSize="14" FontWeight="Light" <TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Height="Auto" FontSize="14" FontWeight="Light"
Text="{Binding Status}" Text="{Binding Status}"
Foreground="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" Foreground="Red"
Visibility="{Binding Status, Converter={StaticResource EmptyStringToVisibilityConverter}}" /> Visibility="{Binding Status, Converter={StaticResource EmptyStringToVisibilityConverter}}" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CredentialStatus">
<VisualState x:Name="Error">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ErrorBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HyperlinkButton" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ErrorBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Initial">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxBorderThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HyperlinkButton" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource HyperlinkForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding IsError}" Value="True">
<core:GoToStateAction StateName="Error"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding IsError}" Value="False">
<core:GoToStateAction StateName="Initial"/>
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -54,7 +54,7 @@ namespace ModernKeePass.Views.UserControls
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name); var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFilePath = token; Model.KeyFilePath = token;
Model.KeyFileText = file.DisplayName; Model.KeyFileText = file.Name;
} }
} }
} }

View File

@@ -11,7 +11,6 @@
<UserControl.Resources> <UserControl.Resources>
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/> <converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/> <converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/> <converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
</UserControl.Resources> </UserControl.Resources>
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=SetCredentials}"> <Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=SetCredentials}">

View File

@@ -1,16 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Windows.UI; using Windows.UI;
using GalaSoft.MvvmLight;
using ModernKeePass.Domain.Entities; using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums; using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces; using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems namespace ModernKeePass.ViewModels.ListItems
{ {
public class EntryItemVm : NotifyPropertyChangedBase public class EntryItemVm : ObservableObject
{ {
private readonly ISecurityService _securityService;
public EntryEntity EntryEntity { get; } public EntryEntity EntryEntity { get; }
public GroupItemVm Parent { get; } public GroupItemVm Parent { get; }

View File

@@ -1,27 +0,0 @@
using System;
using Windows.UI;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
namespace ModernKeePass.Converters
{
public class DiscreteIntToSolidColorBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var status = System.Convert.ToInt32(value);
switch (status)
{
case 1: return new SolidColorBrush(Colors.Red);
case 3: return new SolidColorBrush(Colors.Yellow);
case 5: return new SolidColorBrush(Colors.Green);
default: return new SolidColorBrush(Colors.Black);
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -14,14 +14,6 @@ namespace ModernKeePass.ViewModels
{ {
public class OpenDatabaseControlVm : ViewModelBase public class OpenDatabaseControlVm : ViewModelBase
{ {
public enum StatusTypes
{
Normal = 0,
Error = 1,
Warning = 3,
Success = 5
}
public bool HasPassword public bool HasPassword
{ {
get { return _hasPassword; } get { return _hasPassword; }
@@ -44,27 +36,19 @@ namespace ModernKeePass.ViewModels
} }
} }
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath));
public string Status public string Status
{ {
get { return _status; } get { return _status; }
set { Set(() => Status, ref _status, value); } set { Set(() => Status, ref _status, value); }
} }
public int StatusType
{
get { return _statusType; }
set { Set(() => StatusType, ref _statusType, value); }
}
public string Password public string Password
{ {
get { return _password; } get { return _password; }
set set
{ {
_password = value; _password = value;
StatusType = (int)StatusTypes.Normal; IsError = false;
Status = string.Empty; Status = string.Empty;
} }
} }
@@ -75,6 +59,7 @@ namespace ModernKeePass.ViewModels
set set
{ {
_keyFilePath = value; _keyFilePath = value;
IsError = false;
RaisePropertyChanged(nameof(IsValid)); RaisePropertyChanged(nameof(IsValid));
OpenDatabaseCommand.RaiseCanExecuteChanged(); OpenDatabaseCommand.RaiseCanExecuteChanged();
} }
@@ -86,14 +71,22 @@ namespace ModernKeePass.ViewModels
set { Set(() => KeyFileText, ref _keyFileText, value); } set { Set(() => KeyFileText, ref _keyFileText, value); }
} }
public string OpenButtonLabel public bool IsOpening
{ {
get { return _openButtonLabel; } get { return _isOpening; }
set { Set(() => OpenButtonLabel, ref _openButtonLabel, value); } set { Set(() => IsOpening, ref _isOpening, value); }
} }
public bool IsError
{
get { return _isError; }
set { Set(() => IsError, ref _isError, value); }
}
public bool IsValid => !IsOpening && (HasPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath));
public RelayCommand<string> OpenDatabaseCommand { get; } public RelayCommand<string> OpenDatabaseCommand { get; }
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly IResourceProxy _resource; private readonly IResourceProxy _resource;
private readonly INotificationService _notification; private readonly INotificationService _notification;
@@ -102,11 +95,10 @@ namespace ModernKeePass.ViewModels
private bool _isOpening; private bool _isOpening;
private string _password = string.Empty; private string _password = string.Empty;
private string _status; private string _status;
private int _statusType;
private string _keyFilePath; private string _keyFilePath;
private string _keyFileText; private string _keyFileText;
private string _openButtonLabel; private bool _isError;
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, INotificationService notification) public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, INotificationService notification)
{ {
_mediator = mediator; _mediator = mediator;
@@ -114,7 +106,6 @@ namespace ModernKeePass.ViewModels
_notification = notification; _notification = notification;
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid); OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile"); _keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
_openButtonLabel = _resource.GetResourceValue("CompositeKeyOpenButtonLabel");
} }
public async Task TryOpenDatabase(string databaseFilePath) public async Task TryOpenDatabase(string databaseFilePath)
@@ -132,9 +123,7 @@ namespace ModernKeePass.ViewModels
public async Task OpenDatabase(string databaseFilePath) public async Task OpenDatabase(string databaseFilePath)
{ {
var oldLabel = _openButtonLabel; IsOpening = true;
OpenButtonLabel = _resource.GetResourceValue("CompositeKeyOpening");
_isOpening = true;
try try
{ {
await _mediator.Send(new OpenDatabaseQuery await _mediator.Send(new OpenDatabaseQuery
@@ -152,7 +141,8 @@ namespace ModernKeePass.ViewModels
var errorMessage = new StringBuilder($"{_resource.GetResourceValue("CompositeKeyErrorOpen")}\n"); var errorMessage = new StringBuilder($"{_resource.GetResourceValue("CompositeKeyErrorOpen")}\n");
if (HasPassword) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserPassword")); if (HasPassword) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserPassword"));
if (HasKeyFile) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserKeyFile")); if (HasKeyFile) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserKeyFile"));
UpdateStatus(errorMessage.ToString(), StatusTypes.Error); Status = errorMessage.ToString();
IsError = true;
} }
catch (FileNotFoundException) catch (FileNotFoundException)
{ {
@@ -160,23 +150,17 @@ namespace ModernKeePass.ViewModels
$"{_resource.GetResourceValue("FileNotFoundTitle")}", $"{_resource.GetResourceValue("FileNotFoundTitle")}",
$"{_resource.GetResourceValue("FileNotFoundDescription")}"); $"{_resource.GetResourceValue("FileNotFoundDescription")}");
MessengerInstance.Send(new FileNotFoundMessage()); MessengerInstance.Send(new FileNotFoundMessage());
IsError = true;
} }
catch (Exception e) catch (Exception e)
{ {
var error = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}"; Status = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}";
UpdateStatus(error, StatusTypes.Error); IsError = true;
} }
finally finally
{ {
_isOpening = false; IsOpening = false;
OpenButtonLabel = oldLabel;
} }
} }
private void UpdateStatus(string text, StatusTypes type)
{
Status = text;
StatusType = (int)type;
}
} }
} }

View File

@@ -21,7 +21,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\TextBoxWithButton.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Controls\TextBoxWithButton.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\BooleanToVisibilityConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Converters\BooleanToVisibilityConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ColorToBrushConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Converters\ColorToBrushConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\DiscreteIntToSolidColorBrushConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\DoubleToSolidColorBrushConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Converters\DoubleToSolidColorBrushConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\EmptyStringToVisibilityConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Converters\EmptyStringToVisibilityConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\IconToSymbolConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Converters\IconToSymbolConverter.cs" />