Skip to content

Commit 9d5ea90

Browse files
committed
Added size information to VaultItemInfoDialog
1 parent 526b6f0 commit 9d5ea90

3 files changed

Lines changed: 75 additions & 9 deletions

File tree

src/Platforms/SecureFolderFS.Uno/Dialogs/VaultItemInfoDialog.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<StackPanel Grid.Column="0" Spacing="4">
3131
<TextBlock Text="{l:ResourceString Rid=Name}" />
3232
<TextBlock Text="{l:ResourceString Rid=Path}" />
33+
<TextBlock Text="{l:ResourceString Rid=Size}" Visibility="{x:Bind ViewModel.PlaintextSize, Mode=OneWay, Converter={StaticResource NullToVisibilityConverter}}" />
3334
</StackPanel>
3435
<StackPanel Grid.Column="1" Spacing="4">
3536
<TextBlock
@@ -44,6 +45,12 @@
4445
Text="{x:Bind ViewModel.PlaintextPath, Mode=OneWay}"
4546
TextTrimming="CharacterEllipsis"
4647
ToolTipService.ToolTip="{x:Bind ViewModel.PlaintextPath, Mode=OneWay}" />
48+
<TextBlock
49+
IsTextSelectionEnabled="True"
50+
Opacity="0.6"
51+
Text="{x:Bind ViewModel.PlaintextSize, Mode=OneWay}"
52+
ToolTipService.ToolTip="{x:Bind ViewModel.PlaintextFullSize, Mode=OneWay}"
53+
Visibility="{x:Bind ViewModel.PlaintextSize, Mode=OneWay, Converter={StaticResource NullToVisibilityConverter}}" />
4754
</StackPanel>
4855
</Grid>
4956
</ucab:ActionBlockControl.ExpanderContent>
@@ -64,6 +71,7 @@
6471
<StackPanel Grid.Column="0" Spacing="4">
6572
<TextBlock Text="{l:ResourceString Rid=Name}" />
6673
<TextBlock Text="{l:ResourceString Rid=Path}" />
74+
<TextBlock Text="{l:ResourceString Rid=Size}" Visibility="{x:Bind ViewModel.CiphertextSize, Mode=OneWay, Converter={StaticResource NullToVisibilityConverter}}" />
6775
</StackPanel>
6876
<StackPanel Grid.Column="1" Spacing="4">
6977
<TextBlock
@@ -78,6 +86,12 @@
7886
Text="{x:Bind ViewModel.CiphertextPath, Mode=OneWay}"
7987
TextTrimming="CharacterEllipsis"
8088
ToolTipService.ToolTip="{x:Bind ViewModel.CiphertextPath, Mode=OneWay}" />
89+
<TextBlock
90+
IsTextSelectionEnabled="True"
91+
Opacity="0.6"
92+
Text="{x:Bind ViewModel.CiphertextSize, Mode=OneWay}"
93+
ToolTipService.ToolTip="{x:Bind ViewModel.CiphertextFullSize, Mode=OneWay}"
94+
Visibility="{x:Bind ViewModel.CiphertextSize, Mode=OneWay, Converter={StaticResource NullToVisibilityConverter}}" />
8195
</StackPanel>
8296
</Grid>
8397
</ucab:ActionBlockControl.ExpanderContent>

src/Platforms/SecureFolderFS.Uno/Views/Vault/VaultOverviewPage.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Linq;
44
using System.Threading;
5+
using System.Threading.Tasks;
56
using Windows.ApplicationModel.DataTransfer;
67
using Windows.Storage;
78
using CommunityToolkit.Mvvm.ComponentModel;
@@ -128,8 +129,17 @@ private async void VaultOptions_Drop(object sender, DragEventArgs e)
128129
if (string.IsNullOrEmpty(plaintextPath))
129130
return;
130131

131-
var overlayService = DI.Service<IOverlayService>();
132-
_ = overlayService.ShowAsync(new VaultItemInfoOverlayViewModel(ciphertextItem, plaintextPath));
132+
var plaintextItem = await storageRoot.PlaintextRoot.GetItemByRelativePathAsync(plaintextPath);
133+
_ = DisplayInformation();
134+
135+
async Task DisplayInformation()
136+
{
137+
var viewModel = new VaultItemInfoOverlayViewModel(ciphertextItem, plaintextItem);
138+
await viewModel.InitAsync();
139+
140+
var overlayService = DI.Service<IOverlayService>();
141+
_ = overlayService.ShowAsync(viewModel);
142+
}
133143
}
134144
catch (Exception)
135145
{
Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,68 @@
11
using System.ComponentModel;
2-
using System.IO;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using ByteSizeLib;
35
using CommunityToolkit.Mvvm.ComponentModel;
46
using OwlCore.Storage;
7+
using SecureFolderFS.Shared.ComponentModel;
8+
using SecureFolderFS.Storage.Extensions;
59

610
namespace SecureFolderFS.Sdk.ViewModels.Views.Overlays
711
{
812
[Bindable(true)]
9-
public sealed partial class VaultItemInfoOverlayViewModel : OverlayViewModel
13+
public sealed partial class VaultItemInfoOverlayViewModel : OverlayViewModel, IAsyncInitialize
1014
{
15+
private readonly IStorable _ciphertextItem;
16+
private readonly IStorable _plaintextItem;
17+
18+
[ObservableProperty] private string? _PlaintextSize;
19+
[ObservableProperty] private string? _PlaintextFullSize;
20+
[ObservableProperty] private string? _CiphertextSize;
21+
[ObservableProperty] private string? _CiphertextFullSize;
1122
[ObservableProperty] private string? _PlaintextName;
1223
[ObservableProperty] private string? _CiphertextName;
1324
[ObservableProperty] private string? _PlaintextPath;
1425
[ObservableProperty] private string? _CiphertextPath;
1526
[ObservableProperty] private bool _IsFile;
1627

17-
public VaultItemInfoOverlayViewModel(IStorable ciphertextItem, string plaintextPath)
28+
public VaultItemInfoOverlayViewModel(IStorable ciphertextItem, IStorable plaintextItem)
1829
{
1930
IsFile = ciphertextItem is IFile;
20-
CiphertextPath = ciphertextItem.Id;
21-
CiphertextName = ciphertextItem.Name;
22-
PlaintextPath = plaintextPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
23-
PlaintextName = Path.GetFileName(plaintextPath);
31+
_ciphertextItem = ciphertextItem;
32+
_plaintextItem = plaintextItem;
33+
}
34+
35+
/// <inheritdoc/>
36+
public async Task InitAsync(CancellationToken cancellationToken = default)
37+
{
38+
CiphertextPath = _ciphertextItem.Id;
39+
CiphertextName = _ciphertextItem.Name;
40+
PlaintextPath = _plaintextItem.Id;
41+
PlaintextName = _plaintextItem.Name;
42+
43+
if (!IsFile)
44+
return;
45+
46+
var ciphertextSize = await ((IFile)_ciphertextItem).GetSizeAsync(cancellationToken);
47+
var plaintextSize = await ((IFile)_plaintextItem).GetSizeAsync(cancellationToken);
48+
49+
if (ciphertextSize.HasValue)
50+
{
51+
CiphertextSize = ByteSize.FromBytes(ciphertextSize.Value).ToString();
52+
CiphertextFullSize = $"{ciphertextSize.Value} B";
53+
}
54+
55+
if (plaintextSize.HasValue)
56+
{
57+
PlaintextSize = ByteSize.FromBytes(plaintextSize.Value).ToString();
58+
PlaintextFullSize = $"{plaintextSize.Value} B";
59+
60+
if (ciphertextSize.HasValue)
61+
{
62+
var difference = ciphertextSize.Value - plaintextSize.Value;
63+
CiphertextSize += $" (+{ByteSize.FromBytes(difference)})";
64+
}
65+
}
2466
}
2567
}
2668
}

0 commit comments

Comments
 (0)