1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-15 15:53:44 +00:00

PS-70 add copy to clipboard.

This commit is contained in:
André Bispo
2022-06-20 12:27:11 +01:00
parent 3b763e454c
commit e8d31b8a22
3 changed files with 58 additions and 11 deletions

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.App.Resources;
using Bit.App.Utilities; using Bit.App.Utilities;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Models.View; using Bit.Core.Models.View;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Xamarin.CommunityToolkit.ObjectModel;
using Xamarin.Forms; using Xamarin.Forms;
namespace Bit.App.Pages namespace Bit.App.Pages
@@ -11,6 +13,8 @@ namespace Bit.App.Pages
public class GroupingsPageTOTPListItem : ExtendedViewModel, IGroupingsPageListItem public class GroupingsPageTOTPListItem : ExtendedViewModel, IGroupingsPageListItem
{ {
private readonly ITotpService _totpService; private readonly ITotpService _totpService;
private readonly IPlatformUtilsService _platformUtilsService;
private readonly IClipboardService _clipboardService;
private CipherView _cipher; private CipherView _cipher;
private bool _websiteIconsEnabled; private bool _websiteIconsEnabled;
@@ -26,13 +30,20 @@ namespace Bit.App.Pages
public GroupingsPageTOTPListItem(CipherView cipherView, bool websiteIconsEnabled) public GroupingsPageTOTPListItem(CipherView cipherView, bool websiteIconsEnabled)
{ {
_totpService = ServiceContainer.Resolve<ITotpService>("totpService"); _totpService = ServiceContainer.Resolve<ITotpService>("totpService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_clipboardService = ServiceContainer.Resolve<IClipboardService>("clipboardService");
Cipher = cipherView; Cipher = cipherView;
WebsiteIconsEnabled = websiteIconsEnabled; WebsiteIconsEnabled = websiteIconsEnabled;
interval = _totpService.GetTimeInterval(Cipher.Login.Totp); 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<ILogger> _logger = new LazyResolve<ILogger>("logger");
public AsyncCommand CopyCommand { get; set; }
public CipherView Cipher 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() public async Task TotpTickAsync()
{ {
var epoc = CoreHelpers.EpocUtcNow() / 1000; var epoc = CoreHelpers.EpocUtcNow() / 1000;

View File

@@ -165,36 +165,52 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="40" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label <Label
Text="{u:I18n VerificationCodeTotp}" Text="{u:I18n VerificationCodeTotp}"
StyleClass="box-label" StyleClass="box-label"
Grid.Row="0" Grid.Row="0"
Grid.Column="0" /> Grid.Column="0"/>
<controls:MonoLabel <controls:MonoLabel
Text="{Binding TotpCodeFormatted, Mode=OneWay}" Text="{Binding TotpCodeFormatted, Mode=OneWay}"
StyleClass="box-value" StyleClass="box-value"
Grid.Row="1" Grid.Row="1"
Grid.Column="0" /> Grid.Column="0"
<Label VerticalTextAlignment="Start"
Text="{Binding TotpSec, Mode=OneWay}" VerticalOptions="Start"/>
Style="{DynamicResource textTotp}" <controls:CircularProgressbarView
Margin="0, 0, 10, 0" Progress="{Binding TotpProgress}"
ProgressColor="{StaticResource PrimaryColor}"
EndingProgressColor="{StaticResource DangerColor}"
BackgroundProgressColor="{StaticResource BackgroundColor}"
StrokeWidth="3"
Radius="15"
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
Grid.RowSpan="2" Grid.RowSpan="2"
HorizontalOptions="End" HorizontalOptions="FillAndExpand"
HorizontalTextAlignment="End" VerticalOptions="FillAndExpand" />
VerticalOptions="CenterAndExpand" /> <Label
Text="{Binding TotpSec, Mode=OneWay}"
Style="{DynamicResource textTotp}"
Grid.Row="0"
Grid.Column="1"
Grid.RowSpan="2"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
<controls:IconButton <controls:IconButton
StyleClass="box-row-button, box-row-button-platform" StyleClass="box-row-button, box-row-button-platform"
Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}" Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
Command="{Binding CopyCommand}" Command="{Binding CopyCommand}"
IsVisible="{Binding CanAccessPremium}"
CommandParameter="LoginTotp" CommandParameter="LoginTotp"
Grid.Row="0" Grid.Row="0"
Grid.Column="2" Grid.Column="2"
@@ -202,6 +218,15 @@
AutomationProperties.IsInAccessibleTree="True" AutomationProperties.IsInAccessibleTree="True"
AutomationProperties.Name="{u:I18n CopyTotp}" /> AutomationProperties.Name="{u:I18n CopyTotp}" />
</Grid> </Grid>
<Label FormattedText="{Binding UpgradeToPremiumTotpText}"
StyleClass="box-footer-label"
IsVisible="{Binding CanAccessPremium , Converter={StaticResource inverseBool}}"
Margin="0,5"
HorizontalOptions="StartAndExpand">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="UpgradeToPremiumTotp_Tapped" />
</Label.GestureRecognizers>
</Label>
<BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowTotp}" /> <BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowTotp}" />
</StackLayout> </StackLayout>
<StackLayout IsVisible="{Binding IsCard}" Spacing="0" Padding="0"> <StackLayout IsVisible="{Binding IsCard}" Spacing="0" Padding="0">

View File

@@ -323,5 +323,10 @@ namespace Bit.App.Pages
ToolbarItems.Insert(1, _editItem); ToolbarItems.Insert(1, _editItem);
} }
} }
private void UpgradeToPremiumTotp_Tapped(object sender, System.EventArgs e)
{
_vm.LaunchGetPremiumMembershipURI();
}
} }
} }