diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPageOTPListItem.cs b/src/App/Pages/Vault/GroupingsPage/GroupingsPageOTPListItem.cs index 20746f1ca..293215255 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPageOTPListItem.cs +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPageOTPListItem.cs @@ -1,9 +1,11 @@ using System; using System.Threading.Tasks; +using Bit.App.Resources; using Bit.App.Utilities; using Bit.Core.Abstractions; using Bit.Core.Models.View; using Bit.Core.Utilities; +using Xamarin.CommunityToolkit.ObjectModel; using Xamarin.Forms; namespace Bit.App.Pages @@ -11,6 +13,8 @@ namespace Bit.App.Pages public class GroupingsPageTOTPListItem : ExtendedViewModel, IGroupingsPageListItem { private readonly ITotpService _totpService; + private readonly IPlatformUtilsService _platformUtilsService; + private readonly IClipboardService _clipboardService; private CipherView _cipher; private bool _websiteIconsEnabled; @@ -26,13 +30,20 @@ namespace Bit.App.Pages public GroupingsPageTOTPListItem(CipherView cipherView, bool websiteIconsEnabled) { _totpService = ServiceContainer.Resolve("totpService"); + _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); + _clipboardService = ServiceContainer.Resolve("clipboardService"); Cipher = cipherView; WebsiteIconsEnabled = websiteIconsEnabled; interval = _totpService.GetTimeInterval(Cipher.Login.Totp); + CopyCommand = new AsyncCommand(CopyToClipboardAsync, + onException: ex => _logger.Value.Exception(ex), + allowsMultipleExecutions: false); } - public Command CopyCommand { get; set; } + readonly LazyResolve _logger = new LazyResolve("logger"); + + public AsyncCommand CopyCommand { get; set; } public CipherView Cipher { @@ -82,6 +93,12 @@ namespace Bit.App.Pages } + public async Task CopyToClipboardAsync() + { + await _clipboardService.CopyTextAsync(TotpCodeFormatted); + _platformUtilsService.ShowToast("info", null, string.Format(AppResources.ValueHasBeenCopied, AppResources.VerificationCodeTotp)); + } + public async Task TotpTickAsync() { var epoc = CoreHelpers.EpocUtcNow() / 1000; diff --git a/src/App/Pages/Vault/ViewPage.xaml b/src/App/Pages/Vault/ViewPage.xaml index d581cd2f8..661c0b63d 100644 --- a/src/App/Pages/Vault/ViewPage.xaml +++ b/src/App/Pages/Vault/ViewPage.xaml @@ -165,36 +165,52 @@ + - +