bitwarden-android/src/App/Pages/Vault/VaultViewCipherPage.cs

599 lines
25 KiB
C#
Raw Normal View History

2016-05-02 09:52:09 +03:00
using System;
2016-05-07 05:29:03 +03:00
using Acr.UserDialogs;
using Bit.App.Abstractions;
using Bit.App.Controls;
using Bit.App.Models.Page;
using Bit.App.Resources;
2016-05-02 09:52:09 +03:00
using Xamarin.Forms;
2016-05-07 05:29:03 +03:00
using XLabs.Ioc;
using System.Threading.Tasks;
2017-05-30 21:13:53 +03:00
using Bit.App.Utilities;
2017-07-13 17:51:45 +03:00
using System.Collections.Generic;
2017-07-13 19:08:48 +03:00
using Bit.App.Models;
2017-07-22 22:38:08 +03:00
using System.Linq;
using Bit.App.Enums;
2016-05-02 09:52:09 +03:00
2016-05-03 00:50:16 +03:00
namespace Bit.App.Pages
2016-05-02 09:52:09 +03:00
{
public class VaultViewCipherPage : ExtendedContentPage
2016-05-02 09:52:09 +03:00
{
private readonly CipherType _type;
2017-10-19 23:08:29 +03:00
private readonly string _cipherId;
private readonly ICipherService _cipherService;
2016-05-07 05:29:03 +03:00
private readonly IUserDialogs _userDialogs;
private readonly IDeviceActionService _deviceActionService;
2017-07-13 21:44:02 +03:00
private readonly ITokenService _tokenService;
private bool _pageDisappeared = true;
2016-05-02 09:52:09 +03:00
public VaultViewCipherPage(CipherType type, string cipherId)
2016-05-02 09:52:09 +03:00
{
_type = type;
2017-10-19 23:08:29 +03:00
_cipherId = cipherId;
_cipherService = Resolver.Resolve<ICipherService>();
2016-05-07 05:29:03 +03:00
_userDialogs = Resolver.Resolve<IUserDialogs>();
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
2017-07-13 21:44:02 +03:00
_tokenService = Resolver.Resolve<ITokenService>();
2016-05-07 05:29:03 +03:00
Init();
}
2017-10-19 23:08:29 +03:00
private VaultViewCipherPageModel Model { get; set; } = new VaultViewCipherPageModel();
private ExtendedTableView Table { get; set; }
2017-10-19 23:08:29 +03:00
private TableSection ItemInformationSection { get; set; }
private TableSection NotesSection { get; set; }
private TableSection AttachmentsSection { get; set; }
private TableSection FieldsSection { get; set; }
2017-04-20 23:07:34 +03:00
public LabeledValueCell NotesCell { get; set; }
2017-10-19 23:08:29 +03:00
private EditCipherToolBarItem EditItem { get; set; }
public List<LabeledValueCell> FieldsCells { get; set; }
2017-07-13 17:51:45 +03:00
public List<AttachmentViewCell> AttachmentCells { get; set; }
// Login
public LabeledValueCell LoginUsernameCell { get; set; }
public LabeledValueCell LoginPasswordCell { get; set; }
public LabeledValueCell LoginUriCell { get; set; }
public LabeledValueCell LoginTotpCodeCell { get; set; }
// Card
public LabeledValueCell CardNameCell { get; set; }
public LabeledValueCell CardNumberCell { get; set; }
public LabeledValueCell CardBrandCell { get; set; }
public LabeledValueCell CardExpCell { get; set; }
public LabeledValueCell CardCodeCell { get; set; }
// Card
public LabeledValueCell IdNameCell { get; set; }
public LabeledValueCell IdUsernameCell { get; set; }
public LabeledValueCell IdCompanyCell { get; set; }
public LabeledValueCell IdSsnCell { get; set; }
public LabeledValueCell IdPassportNumberCell { get; set; }
public LabeledValueCell IdLicenseNumberCell { get; set; }
public LabeledValueCell IdEmailCell { get; set; }
public LabeledValueCell IdPhoneCell { get; set; }
public LabeledValueCell IdAddressCell { get; set; }
private void Init()
2016-05-07 05:29:03 +03:00
{
2017-10-19 23:08:29 +03:00
EditItem = new EditCipherToolBarItem(this, _cipherId);
ToolbarItems.Add(EditItem);
if(Device.RuntimePlatform == Device.iOS)
{
ToolbarItems.Add(new DismissModalToolBarItem(this));
}
2016-05-07 05:29:03 +03:00
InitProps();
Title = AppResources.ViewItem;
Content = Table;
BindingContext = Model;
}
public void InitProps()
{
2016-06-18 01:14:24 +03:00
// Name
var nameCell = new LabeledValueCell(AppResources.Name);
2017-10-19 23:08:29 +03:00
nameCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.Name));
2017-12-08 17:03:44 +03:00
nameCell.Value.LineBreakMode = LineBreakMode.WordWrap;
// Notes
2017-04-20 23:07:34 +03:00
NotesCell = new LabeledValueCell();
2017-10-19 23:08:29 +03:00
NotesCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.Notes));
2017-04-20 23:07:34 +03:00
NotesCell.Value.LineBreakMode = LineBreakMode.WordWrap;
switch(_type)
{
case CipherType.Login:
// Username
LoginUsernameCell = new LabeledValueCell(AppResources.Username, button1Image: "clipboard.png");
LoginUsernameCell.Value.SetBinding(Label.TextProperty,
nameof(VaultViewCipherPageModel.LoginUsername));
LoginUsernameCell.Button1.Command =
new Command(() => Copy(Model.LoginUsername, AppResources.Username));
LoginUsernameCell.Value.LineBreakMode = LineBreakMode.WordWrap;
// Password
LoginPasswordCell = new LabeledValueCell(AppResources.Password, button1Image: string.Empty,
button2Image: "clipboard.png");
LoginPasswordCell.Value.SetBinding(Label.TextProperty,
nameof(VaultViewCipherPageModel.MaskedLoginPassword));
LoginPasswordCell.Button1.SetBinding(Button.ImageProperty,
nameof(VaultViewCipherPageModel.LoginShowHideImage));
if(Device.RuntimePlatform == Device.iOS)
{
LoginPasswordCell.Button1.Margin = new Thickness(10, 0);
}
LoginPasswordCell.Button1.Command =
new Command(() => Model.RevealLoginPassword = !Model.RevealLoginPassword);
LoginPasswordCell.Button2.Command =
new Command(() => Copy(Model.LoginPassword, AppResources.Password));
LoginPasswordCell.Value.FontFamily =
Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier");
LoginPasswordCell.Value.LineBreakMode = LineBreakMode.WordWrap;
// URI
LoginUriCell = new LabeledValueCell(AppResources.Website, button1Image: "launch.png");
LoginUriCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.LoginUriHost));
LoginUriCell.Button1.SetBinding(IsVisibleProperty, nameof(VaultViewCipherPageModel.ShowLoginLaunch));
LoginUriCell.Button1.Command = new Command(async () =>
{
if(Device.RuntimePlatform == Device.Android && Model.LoginUri.StartsWith("androidapp://"))
{
await _deviceActionService.LaunchAppAsync(Model.LoginUri, this);
}
else if(Model.LoginUri.StartsWith("http://") || Model.LoginUri.StartsWith("https://"))
{
Device.OpenUri(new Uri(Model.LoginUri));
}
});
// Totp
LoginTotpCodeCell = new LabeledValueCell(
AppResources.VerificationCodeTotp, button1Image: "clipboard.png", subText: "--");
LoginTotpCodeCell.Value.SetBinding(Label.TextProperty,
nameof(VaultViewCipherPageModel.LoginTotpCodeFormatted));
LoginTotpCodeCell.Value.SetBinding(Label.TextColorProperty,
nameof(VaultViewCipherPageModel.LoginTotpColor));
LoginTotpCodeCell.Button1.Command =
new Command(() => Copy(Model.LoginTotpCode, AppResources.VerificationCodeTotp));
LoginTotpCodeCell.Sub.SetBinding(Label.TextProperty,
nameof(VaultViewCipherPageModel.LoginTotpSecond));
LoginTotpCodeCell.Sub.SetBinding(Label.TextColorProperty,
nameof(VaultViewCipherPageModel.LoginTotpColor));
LoginTotpCodeCell.Value.FontFamily =
Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier");
break;
case CipherType.Card:
CardNameCell = new LabeledValueCell(AppResources.CardholderName);
CardNameCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.CardName));
CardNumberCell = new LabeledValueCell(AppResources.Number, button1Image: "clipboard.png");
CardNumberCell.Button1.Command = new Command(() => Copy(Model.CardNumber, AppResources.Number));
CardNumberCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.CardNumber));
CardNumberCell.Value.LineBreakMode = LineBreakMode.WordWrap;
CardBrandCell = new LabeledValueCell(AppResources.Brand);
CardBrandCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.CardBrand));
CardExpCell = new LabeledValueCell(AppResources.Expiration);
CardExpCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.CardExp));
CardCodeCell = new LabeledValueCell(AppResources.SecurityCode, button1Image: "clipboard.png");
CardCodeCell.Button1.Command = new Command(() => Copy(Model.CardCode, AppResources.SecurityCode));
CardCodeCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.CardCode));
break;
case CipherType.Identity:
IdNameCell = new LabeledValueCell(AppResources.Name);
IdNameCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.IdName));
IdNameCell.Value.LineBreakMode = LineBreakMode.WordWrap;
IdUsernameCell = new LabeledValueCell(AppResources.Username, button1Image: "clipboard.png");
IdUsernameCell.Button1.Command = new Command(() => Copy(Model.IdUsername, AppResources.Username));
IdUsernameCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.IdUsername));
IdUsernameCell.Value.LineBreakMode = LineBreakMode.WordWrap;
IdCompanyCell = new LabeledValueCell(AppResources.Company);
IdCompanyCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.IdCompany));
IdSsnCell = new LabeledValueCell(AppResources.SSN);
IdSsnCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.IdSsn));
IdPassportNumberCell = new LabeledValueCell(AppResources.PassportNumber,
button1Image: "clipboard.png");
IdPassportNumberCell.Button1.Command =
new Command(() => Copy(Model.IdPassportNumber, AppResources.PassportNumber));
IdPassportNumberCell.Value.SetBinding(Label.TextProperty,
nameof(VaultViewCipherPageModel.IdPassportNumber));
IdPassportNumberCell.Value.LineBreakMode = LineBreakMode.WordWrap;
IdLicenseNumberCell = new LabeledValueCell(AppResources.LicenseNumber,
button1Image: "clipboard.png");
IdLicenseNumberCell.Button1.Command =
new Command(() => Copy(Model.IdLicenseNumber, AppResources.LicenseNumber));
IdLicenseNumberCell.Value.SetBinding(Label.TextProperty,
nameof(VaultViewCipherPageModel.IdLicenseNumber));
IdLicenseNumberCell.Value.LineBreakMode = LineBreakMode.WordWrap;
IdEmailCell = new LabeledValueCell(AppResources.Email);
IdEmailCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.IdEmail));
IdPhoneCell = new LabeledValueCell(AppResources.Phone);
IdPhoneCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.IdPhone));
IdAddressCell = new LabeledValueCell(AppResources.Address, button1Image: "clipboard.png");
IdAddressCell.Button1.Command = new Command(() => Copy(Model.IdAddress, AppResources.Address));
IdAddressCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewCipherPageModel.IdAddress));
IdAddressCell.Value.LineBreakMode = LineBreakMode.WordWrap;
break;
default:
break;
}
2017-10-19 23:08:29 +03:00
ItemInformationSection = new TableSection(AppResources.ItemInformation)
{
nameCell
};
NotesSection = new TableSection(AppResources.Notes)
{
2017-04-20 23:07:34 +03:00
NotesCell
};
Table = new ExtendedTableView
2016-05-07 05:29:03 +03:00
{
Intent = TableIntent.Settings,
2016-05-24 06:48:34 +03:00
EnableScrolling = true,
HasUnevenRows = true,
2017-07-13 17:51:45 +03:00
EnableSelection = true,
Root = new TableRoot
{
2017-10-19 23:08:29 +03:00
ItemInformationSection
}
};
2017-05-30 21:13:53 +03:00
if(Device.RuntimePlatform == Device.iOS)
{
Table.RowHeight = -1;
Table.EstimatedRowHeight = 70;
}
2016-05-07 05:29:03 +03:00
}
protected async override void OnAppearing()
2016-05-07 05:29:03 +03:00
{
_pageDisappeared = false;
2017-04-20 23:07:34 +03:00
NotesCell.Tapped += NotesCell_Tapped;
EditItem.InitEvents();
2017-10-19 23:08:29 +03:00
var cipher = await _cipherService.GetByIdAsync(_cipherId);
if(cipher == null)
2016-05-07 05:29:03 +03:00
{
await Navigation.PopForDeviceAsync();
return;
2016-05-07 05:29:03 +03:00
}
Model.Update(cipher);
BuildTable(cipher);
base.OnAppearing();
}
2016-05-12 00:30:09 +03:00
protected override void OnDisappearing()
{
_pageDisappeared = true;
NotesCell.Tapped -= NotesCell_Tapped;
EditItem.Dispose();
CleanupAttachmentCells();
}
private void BuildTable(Cipher cipher)
{
2017-07-22 22:38:08 +03:00
if(Table.Root.Contains(NotesSection))
{
Table.Root.Remove(NotesSection);
}
2017-07-22 22:38:08 +03:00
if(Model.ShowNotes)
{
Table.Root.Add(NotesSection);
}
// Attachments
2017-07-22 22:38:08 +03:00
CleanupAttachmentCells();
if(Table.Root.Contains(AttachmentsSection))
2017-07-13 21:44:02 +03:00
{
2017-07-22 22:38:08 +03:00
Table.Root.Remove(AttachmentsSection);
}
2017-07-24 17:34:22 +03:00
if(Model.ShowAttachments && _tokenService.TokenPremium)
2017-07-22 22:38:08 +03:00
{
AttachmentsSection = new TableSection(AppResources.Attachments);
AttachmentCells = new List<AttachmentViewCell>();
foreach(var attachment in Model.Attachments.OrderBy(s => s.Name))
{
var attachmentCell = new AttachmentViewCell(attachment, async () =>
{
await OpenAttachmentAsync(cipher, attachment);
2017-07-22 22:38:08 +03:00
});
AttachmentCells.Add(attachmentCell);
AttachmentsSection.Add(attachmentCell);
attachmentCell.InitEvents();
}
Table.Root.Add(AttachmentsSection);
2017-07-13 21:44:02 +03:00
}
// Fields
if(Table.Root.Contains(FieldsSection))
{
Table.Root.Remove(FieldsSection);
}
if(Model.ShowFields)
{
FieldsSection = new TableSection(AppResources.CustomFields);
foreach(var field in Model.Fields)
{
2017-09-25 22:05:36 +03:00
FieldViewCell fieldCell;
switch(field.Type)
{
case FieldType.Text:
2017-09-25 22:05:36 +03:00
fieldCell = new FieldViewCell(this, field, null);
break;
case FieldType.Hidden:
2017-09-25 22:05:36 +03:00
fieldCell = new FieldViewCell(this, field, null, null);
break;
case FieldType.Boolean:
2017-09-25 22:05:36 +03:00
fieldCell = new FieldViewCell(this, field);
break;
default:
continue;
}
FieldsSection.Add(fieldCell);
}
Table.Root.Add(FieldsSection);
}
// Various types
switch(cipher.Type)
{
case CipherType.Login:
AddSectionCell(LoginUriCell, Model.ShowLoginUri);
AddSectionCell(LoginUsernameCell, Model.ShowLoginUsername);
AddSectionCell(LoginPasswordCell, Model.ShowLoginPassword);
if(ItemInformationSection.Contains(LoginTotpCodeCell))
{
ItemInformationSection.Remove(LoginTotpCodeCell);
}
if(cipher.Login?.Totp != null && (_tokenService.TokenPremium || cipher.OrganizationUseTotp))
{
var totpKey = cipher.Login?.Totp.Decrypt(cipher.OrganizationId);
if(!string.IsNullOrWhiteSpace(totpKey))
{
Model.LoginTotpCode = Crypto.Totp(totpKey);
if(!string.IsNullOrWhiteSpace(Model.LoginTotpCode))
{
TotpTick(totpKey);
Device.StartTimer(new TimeSpan(0, 0, 1), () =>
{
if(_pageDisappeared)
{
return false;
}
TotpTick(totpKey);
return true;
});
ItemInformationSection.Add(LoginTotpCodeCell);
}
}
}
break;
case CipherType.Card:
AddSectionCell(CardNameCell, Model.ShowCardName);
AddSectionCell(CardNumberCell, Model.ShowCardNumber);
AddSectionCell(CardBrandCell, Model.ShowCardBrand);
AddSectionCell(CardExpCell, Model.ShowCardExp);
AddSectionCell(CardCodeCell, Model.ShowCardCode);
break;
case CipherType.Identity:
AddSectionCell(IdNameCell, Model.ShowIdName);
AddSectionCell(IdUsernameCell, Model.ShowIdUsername);
AddSectionCell(IdCompanyCell, Model.ShowIdCompany);
AddSectionCell(IdSsnCell, Model.ShowIdSsn);
AddSectionCell(IdPassportNumberCell, Model.ShowIdPassportNumber);
AddSectionCell(IdLicenseNumberCell, Model.ShowIdLicenseNumber);
AddSectionCell(IdEmailCell, Model.ShowIdEmail);
AddSectionCell(IdPhoneCell, Model.ShowIdPhone);
AddSectionCell(IdAddressCell, Model.ShowIdAddress);
break;
default:
break;
}
2016-05-07 05:29:03 +03:00
}
private void AddSectionCell(LabeledValueCell cell, bool show)
{
if(ItemInformationSection.Contains(cell))
{
ItemInformationSection.Remove(cell);
}
if(show)
{
ItemInformationSection.Add(cell);
}
2017-07-13 17:51:45 +03:00
}
private void CleanupAttachmentCells()
{
if(AttachmentCells != null)
{
foreach(var cell in AttachmentCells)
{
cell.Dispose();
}
}
}
2017-10-19 23:08:29 +03:00
private async Task OpenAttachmentAsync(Cipher cipher, VaultViewCipherPageModel.Attachment attachment)
{
2017-10-19 23:08:29 +03:00
if(!_tokenService.TokenPremium && !cipher.OrganizationUseTotp)
{
await DisplayAlert(null, AppResources.PremiumRequired, AppResources.Ok);
return;
}
// 10 MB warning
if(attachment.Size >= 10485760 && !(await _userDialogs.ConfirmAsync(
2017-07-13 16:01:00 +03:00
string.Format(AppResources.AttachmentLargeWarning, attachment.SizeName), null,
AppResources.Yes, AppResources.No)))
{
return;
}
if(!_deviceActionService.CanOpenFile(attachment.Name))
{
await DisplayAlert(null, AppResources.UnableToOpenFile, AppResources.Ok);
2017-07-13 16:01:00 +03:00
return;
}
_userDialogs.ShowLoading(AppResources.Downloading, MaskType.Black);
2017-10-19 23:08:29 +03:00
var data = await _cipherService.DownloadAndDecryptAttachmentAsync(attachment.Url, cipher.OrganizationId);
_userDialogs.HideLoading();
if(data == null)
{
await DisplayAlert(null, AppResources.UnableToDownloadFile, AppResources.Ok);
return;
}
2017-07-13 16:01:00 +03:00
if(!_deviceActionService.OpenFile(data, attachment.Id, attachment.Name))
{
await DisplayAlert(null, AppResources.UnableToOpenFile, AppResources.Ok);
return;
}
}
2017-04-20 23:07:34 +03:00
private void NotesCell_Tapped(object sender, EventArgs e)
{
Copy(Model.Notes, AppResources.Notes);
}
private void Copy(string copyText, string alertLabel)
2016-05-07 05:29:03 +03:00
{
_deviceActionService.CopyToClipboard(copyText);
2017-12-22 23:00:11 +03:00
_deviceActionService.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
2016-05-07 05:29:03 +03:00
}
2017-07-13 21:44:02 +03:00
private void TotpTick(string totpKey)
{
var now = Helpers.EpocUtcNow() / 1000;
var mod = now % 30;
Model.LoginTotpSecond = (int)(30 - mod);
2017-07-13 21:44:02 +03:00
if(mod == 0)
{
Model.LoginTotpCode = Crypto.Totp(totpKey);
2017-07-13 21:44:02 +03:00
}
}
2017-10-19 23:08:29 +03:00
private class EditCipherToolBarItem : ExtendedToolbarItem
2016-05-07 05:29:03 +03:00
{
private readonly VaultViewCipherPage _page;
2017-10-19 23:08:29 +03:00
private readonly string _cipherId;
2016-05-07 05:29:03 +03:00
2017-10-19 23:08:29 +03:00
public EditCipherToolBarItem(VaultViewCipherPage page, string cipherId)
2016-05-07 05:29:03 +03:00
{
_page = page;
2017-10-19 23:08:29 +03:00
_cipherId = cipherId;
Text = AppResources.Edit;
Icon = Helpers.ToolbarImage("cog.png");
ClickAction = async () => await ClickedItem();
2016-05-07 05:29:03 +03:00
}
2016-05-02 09:52:09 +03:00
private async Task ClickedItem()
2016-05-07 05:29:03 +03:00
{
2017-10-19 23:08:29 +03:00
var page = new VaultEditCipherPage(_cipherId);
await _page.Navigation.PushForDeviceAsync(page);
2016-05-07 05:29:03 +03:00
}
2016-05-02 09:52:09 +03:00
}
2017-07-13 17:51:45 +03:00
public class AttachmentViewCell : LabeledRightDetailCell, IDisposable
{
private readonly Action _tapped;
2017-10-19 23:08:29 +03:00
public AttachmentViewCell(VaultViewCipherPageModel.Attachment attachment, Action tappedAction)
{
_tapped = tappedAction;
Label.Text = attachment.Name;
2017-07-13 16:01:00 +03:00
Detail.Text = attachment.SizeName;
Icon.Source = "download.png";
BackgroundColor = Color.White;
2017-07-14 01:08:16 +03:00
Detail.MinimumWidthRequest = 100;
2017-07-13 17:51:45 +03:00
}
public void InitEvents()
{
Tapped += AttachmentViewCell_Tapped;
}
2017-07-13 17:51:45 +03:00
public void Dispose()
{
Tapped -= AttachmentViewCell_Tapped;
}
private void AttachmentViewCell_Tapped(object sender, EventArgs e)
{
_tapped?.Invoke();
}
}
2017-09-25 22:05:36 +03:00
public class FieldViewCell : LabeledValueCell
{
2017-10-19 23:08:29 +03:00
public FieldViewCell(VaultViewCipherPage page, VaultViewCipherPageModel.Field field)
2017-09-25 22:05:36 +03:00
: base(field.Name, field.Value == "true" ? "✓" : "-")
{
Init(page, field, null);
}
2017-10-19 23:08:29 +03:00
public FieldViewCell(VaultViewCipherPage page, VaultViewCipherPageModel.Field field, bool? a)
: base(field.Name, field.Value, "clipboard.png")
2017-09-25 22:05:36 +03:00
{
Init(page, field, Button1);
}
2017-10-19 23:08:29 +03:00
public FieldViewCell(VaultViewCipherPage page, VaultViewCipherPageModel.Field field, bool? a, bool? b)
: base(field.Name, field.MaskedValue, string.Empty, "clipboard.png")
2017-09-25 22:05:36 +03:00
{
Value.FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular",
Android: "monospace", Windows: "Courier");
2017-09-25 22:05:36 +03:00
if(Device.RuntimePlatform == Device.iOS)
{
Button1.Margin = new Thickness(10, 0);
}
2017-09-25 22:05:36 +03:00
Button1.Image = "eye";
Button1.Command = new Command(() =>
{
field.Revealed = !field.Revealed;
if(field.Revealed)
{
Button1.Image = "eye_slash.png";
2017-09-25 22:05:36 +03:00
Value.Text = field.Value;
}
else
{
Button1.Image = "eye.png";
2017-09-25 22:05:36 +03:00
Value.Text = field.MaskedValue;
}
});
Init(page, field, Button2);
}
2017-10-19 23:08:29 +03:00
private void Init(VaultViewCipherPage page, VaultViewCipherPageModel.Field field, ExtendedButton copyButton)
2017-09-25 22:05:36 +03:00
{
Value.LineBreakMode = LineBreakMode.WordWrap;
if(copyButton != null)
{
copyButton.Command = new Command(() => page.Copy(field.Value, field.Name));
}
}
}
2016-05-02 09:52:09 +03:00
}
}