From 2f2b90aceed81944e6a2737d5b4409d6798dc9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Bispo?= Date: Mon, 18 Jul 2022 22:13:44 +0100 Subject: [PATCH] [SSG-416] PR fixes --- .../AuthenticatorViewCell.xaml | 10 +++---- src/App/Controls/CircularProgressbarView.cs | 2 +- src/App/Pages/Vault/AddEditPageViewModel.cs | 2 +- .../Vault/GroupingsPage/GroupingsPage.xaml.cs | 9 +++++- .../GroupingsPageTOTPListItem.cs | 10 +++++-- .../GroupingsPage/GroupingsPageViewModel.cs | 17 +++++------ src/App/Pages/Vault/ScanPage.xaml.cs | 1 - src/App/Pages/Vault/ViewPage.xaml | 2 +- src/App/Pages/Vault/ViewPage.xaml.cs | 4 +-- src/App/Pages/Vault/ViewPageViewModel.cs | 15 +++++++--- src/App/Utilities/TimerTask.cs | 20 ++++++------- src/App/Utilities/TotpHelper.cs | 30 ++++++++----------- 12 files changed, 67 insertions(+), 55 deletions(-) diff --git a/src/App/Controls/AuthenticatorViewCell/AuthenticatorViewCell.xaml b/src/App/Controls/AuthenticatorViewCell/AuthenticatorViewCell.xaml index cc28c2251..00ecc3415 100644 --- a/src/App/Controls/AuthenticatorViewCell/AuthenticatorViewCell.xaml +++ b/src/App/Controls/AuthenticatorViewCell/AuthenticatorViewCell.xaml @@ -13,7 +13,7 @@ ColumnDefinitions="40,*,40,Auto,40" RowSpacing="0" Padding="0,10,0,0" - RowDefinitions="Auto,Auto"> + RowDefinitions="*,*"> @@ -48,8 +48,8 @@ LineBreakMode="TailTruncation" Grid.Column="1" Grid.Row="0" - VerticalTextAlignment="End" - VerticalOptions="End" + VerticalTextAlignment="Center" + VerticalOptions="Fill" StyleClass="list-title, list-title-platform" Text="{Binding Cipher.Name}" /> @@ -57,8 +57,8 @@ LineBreakMode="TailTruncation" Grid.Column="1" Grid.Row="1" - VerticalTextAlignment="Start" - VerticalOptions="Start" + VerticalTextAlignment="Center" + VerticalOptions="Fill" StyleClass="list-subtitle, list-subtitle-platform" Text="{Binding Cipher.SubTitle}" /> diff --git a/src/App/Controls/CircularProgressbarView.cs b/src/App/Controls/CircularProgressbarView.cs index 6eb378490..56e8a6c43 100644 --- a/src/App/Controls/CircularProgressbarView.cs +++ b/src/App/Controls/CircularProgressbarView.cs @@ -105,7 +105,7 @@ namespace Bit.App.Controls private void DrawArc(SKCanvas canvas, Circle circle, Func progress, float strokewidth, SKColor color, SKColor progressEndColor) { - var progressValue = progress.Invoke(); + var progressValue = progress(); var angle = progressValue * 3.6f; canvas.DrawArc(circle.Rect, 270, angle, false, new SKPaint() diff --git a/src/App/Pages/Vault/AddEditPageViewModel.cs b/src/App/Pages/Vault/AddEditPageViewModel.cs index 1d121b602..64878bf50 100644 --- a/src/App/Pages/Vault/AddEditPageViewModel.cs +++ b/src/App/Pages/Vault/AddEditPageViewModel.cs @@ -93,7 +93,7 @@ namespace Bit.App.Pages UriOptionsCommand = new Command(UriOptions); FieldOptionsCommand = new Command(FieldOptions); PasswordPromptHelpCommand = new Command(PasswordPromptHelp); - CopyCommand = new AsyncCommand(CopyTotpClipboardAsync); + CopyCommand = new AsyncCommand(CopyTotpClipboardAsync, onException: ex => _logger.Exception(ex), allowsMultipleExecutions: false); Uris = new ExtendedObservableCollection(); Fields = new ExtendedObservableCollection(); Collections = new ExtendedObservableCollection(); diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs index e75916564..1ce9a89cf 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs @@ -193,7 +193,7 @@ namespace Bit.App.Pages { base.OnDisappearing(); IsBusy = false; - await _vm.StopCiphersTotpTick(); + _vm.StopCiphersTotpTick(); _broadcasterService.Unsubscribe(_pageName); _vm.DisableRefreshing(); _accountAvatar?.OnDisappearing(); @@ -206,6 +206,13 @@ namespace Bit.App.Pages { return; } + + if (e.CurrentSelection?.FirstOrDefault() is GroupingsPageTOTPListItem totpItem) + { + await _vm.SelectCipherAsync(totpItem.Cipher); + return; + } + if (!(e.CurrentSelection?.FirstOrDefault() is GroupingsPageListItem item)) { return; diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPageTOTPListItem.cs b/src/App/Pages/Vault/GroupingsPage/GroupingsPageTOTPListItem.cs index b2629e65d..79149130e 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPageTOTPListItem.cs +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPageTOTPListItem.cs @@ -6,6 +6,7 @@ using Bit.Core.Abstractions; using Bit.Core.Models.View; using Bit.Core.Utilities; using Xamarin.CommunityToolkit.ObjectModel; +using Xamarin.Essentials; using Xamarin.Forms; namespace Bit.App.Pages @@ -111,9 +112,12 @@ namespace Bit.App.Pages public async Task TotpTickAsync() { await _totpTickHelper.GenerateNewTotpValues(); - TotpSec = _totpTickHelper.TotpSec; - Progress = _totpTickHelper.Progress; - TotpCodeFormatted = _totpTickHelper.TotpCodeFormatted; + MainThread.BeginInvokeOnMainThread(() => + { + TotpSec = _totpTickHelper.TotpSec; + Progress = _totpTickHelper.Progress; + TotpCodeFormatted = _totpTickHelper.TotpCodeFormatted; + }); } } } diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs b/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs index badbe269e..430a983d5 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs @@ -39,7 +39,7 @@ namespace Bit.App.Pages private Dictionary _collectionCounts = new Dictionary(); private Dictionary _typeCounts = new Dictionary(); private int _deletedCount = 0; - private CancellationTokenSource _totpTickCancellationToken; + private CancellationTokenSource _totpTickCts; private Task _totpTickTask; private readonly ICipherService _cipherService; private readonly IFolderService _folderService; @@ -299,7 +299,7 @@ namespace Bit.App.Pages } if (Ciphers?.Any() ?? false) { - CreateCipherGroupedItems(ref groupedItems); + CreateCipherGroupedItems(groupedItems); } if (ShowNoFolderCipherGroup) { @@ -387,10 +387,10 @@ namespace Bit.App.Pages } } - private void CreateCipherGroupedItems(ref List groupedItems) + private void CreateCipherGroupedItems(List groupedItems) { var uppercaseGroupNames = _deviceActionService.DeviceType == DeviceType.iOS; - _totpTickCancellationToken?.Cancel(); + _totpTickCts?.Cancel(); if (TotpFilterEnable) { var ciphersListItems = Ciphers.Where(c => c.IsDeleted == Deleted && !string.IsNullOrEmpty(c.Login.Totp)) @@ -411,15 +411,14 @@ namespace Bit.App.Pages private void StartCiphersTotpTick(List ciphersListItems) { - _totpTickCancellationToken?.Cancel(); - _totpTickCancellationToken = new CancellationTokenSource(); - _totpTickTask = new TimerTask(() => { ciphersListItems.ForEach(i => i.TotpTickAsync()); }, _totpTickCancellationToken).Run(); + _totpTickCts?.Cancel(); + _totpTickCts = new CancellationTokenSource(); + _totpTickTask = new TimerTask(logger, () => ciphersListItems.ForEach(i => i.TotpTickAsync()), _totpTickCts).RunPeriodic(); } public async Task StopCiphersTotpTick() { - TotpFilterEnable = false; - _totpTickCancellationToken?.Cancel(); + _totpTickCts?.Cancel(); if (_totpTickTask != null) { await _totpTickTask; diff --git a/src/App/Pages/Vault/ScanPage.xaml.cs b/src/App/Pages/Vault/ScanPage.xaml.cs index 0ccf938cf..1927e2587 100644 --- a/src/App/Pages/Vault/ScanPage.xaml.cs +++ b/src/App/Pages/Vault/ScanPage.xaml.cs @@ -258,7 +258,6 @@ namespace Bit.App.Pages break; } } - _stopwatch.Stop(); } catch (Exception ex) { diff --git a/src/App/Pages/Vault/ViewPage.xaml b/src/App/Pages/Vault/ViewPage.xaml index be877a223..89e5a06ee 100644 --- a/src/App/Pages/Vault/ViewPage.xaml +++ b/src/App/Pages/Vault/ViewPage.xaml @@ -215,7 +215,7 @@ AutomationProperties.IsInAccessibleTree="True" AutomationProperties.Name="{u:I18n CopyTotp}" />