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;
|
2016-05-13 07:11:32 +03:00
|
|
|
|
using Bit.App.Controls;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
using Bit.App.Models.Page;
|
2016-05-07 20:42:09 +03:00
|
|
|
|
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;
|
2017-02-17 08:16:09 +03:00
|
|
|
|
using System.Threading.Tasks;
|
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
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
public class VaultViewLoginPage : ExtendedContentPage
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private readonly string _loginId;
|
|
|
|
|
private readonly ILoginService _loginService;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
private readonly IClipboardService _clipboardService;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
public VaultViewLoginPage(string loginId)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
_loginId = loginId;
|
|
|
|
|
_loginService = Resolver.Resolve<ILoginService>();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_clipboardService = Resolver.Resolve<IClipboardService>();
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private VaultViewLoginPageModel Model { get; set; } = new VaultViewLoginPageModel();
|
2016-05-14 02:57:07 +03:00
|
|
|
|
private ExtendedTableView Table { get; set; }
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private TableSection LoginInformationSection { get; set; }
|
2016-06-14 03:03:16 +03:00
|
|
|
|
private TableSection NotesSection { get; set; }
|
|
|
|
|
public LabeledValueCell UsernameCell { get; set; }
|
|
|
|
|
public LabeledValueCell PasswordCell { get; set; }
|
|
|
|
|
public LabeledValueCell UriCell { get; set; }
|
2017-02-17 08:16:09 +03:00
|
|
|
|
private EditLoginToolBarItem EditItem { get; set; }
|
2016-05-08 06:11:47 +03:00
|
|
|
|
|
|
|
|
|
private void Init()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-02-17 08:16:09 +03:00
|
|
|
|
EditItem = new EditLoginToolBarItem(this, _loginId);
|
|
|
|
|
ToolbarItems.Add(EditItem);
|
2016-05-14 08:34:42 +03:00
|
|
|
|
if(Device.OS == TargetPlatform.iOS)
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(new DismissModalToolBarItem(this));
|
|
|
|
|
}
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-06-18 01:14:24 +03:00
|
|
|
|
// Name
|
2016-05-14 02:57:07 +03:00
|
|
|
|
var nameCell = new LabeledValueCell(AppResources.Name);
|
2017-01-03 08:17:15 +03:00
|
|
|
|
nameCell.Value.SetBinding<VaultViewLoginPageModel>(Label.TextProperty, s => s.Name);
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
|
|
|
|
// Username
|
2016-06-14 03:03:16 +03:00
|
|
|
|
UsernameCell = new LabeledValueCell(AppResources.Username, button1Text: AppResources.Copy);
|
2017-01-03 08:17:15 +03:00
|
|
|
|
UsernameCell.Value.SetBinding<VaultViewLoginPageModel>(Label.TextProperty, s => s.Username);
|
|
|
|
|
UsernameCell.Value.SetBinding<VaultViewLoginPageModel>(Label.FontSizeProperty, s => s.UsernameFontSize);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
UsernameCell.Button1.Command = new Command(() => Copy(Model.Username, AppResources.Username));
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// Password
|
2016-08-17 05:18:45 +03:00
|
|
|
|
PasswordCell = new LabeledValueCell(AppResources.Password, button1Text: string.Empty,
|
|
|
|
|
button2Text: AppResources.Copy);
|
2017-01-03 08:17:15 +03:00
|
|
|
|
PasswordCell.Value.SetBinding<VaultViewLoginPageModel>(Label.TextProperty, s => s.MaskedPassword);
|
|
|
|
|
PasswordCell.Value.SetBinding<VaultViewLoginPageModel>(Label.FontSizeProperty, s => s.PasswordFontSize);
|
|
|
|
|
PasswordCell.Button1.SetBinding<VaultViewLoginPageModel>(Button.ImageProperty, s => s.ShowHideImage);
|
2016-06-18 01:14:24 +03:00
|
|
|
|
if(Device.OS == TargetPlatform.iOS)
|
|
|
|
|
{
|
|
|
|
|
PasswordCell.Button1.Margin = new Thickness(10, 0);
|
|
|
|
|
}
|
2016-06-14 03:03:16 +03:00
|
|
|
|
PasswordCell.Button1.Command = new Command(() => Model.RevealPassword = !Model.RevealPassword);
|
|
|
|
|
PasswordCell.Button2.Command = new Command(() => Copy(Model.Password, AppResources.Password));
|
2016-11-09 05:29:24 +03:00
|
|
|
|
PasswordCell.Value.FontFamily = Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// URI
|
2016-06-14 03:03:16 +03:00
|
|
|
|
UriCell = new LabeledValueCell(AppResources.Website, button1Text: AppResources.Launch);
|
2017-01-03 08:17:15 +03:00
|
|
|
|
UriCell.Value.SetBinding<VaultViewLoginPageModel>(Label.TextProperty, s => s.UriHost);
|
|
|
|
|
UriCell.Button1.SetBinding<VaultViewLoginPageModel>(IsVisibleProperty, s => s.ShowLaunch);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
UriCell.Button1.Command = new Command(() => Device.OpenUri(new Uri(Model.Uri)));
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
|
|
|
|
// Notes
|
2016-05-14 08:34:42 +03:00
|
|
|
|
var notesCell = new LabeledValueCell();
|
2017-01-03 08:17:15 +03:00
|
|
|
|
notesCell.Value.SetBinding<VaultViewLoginPageModel>(Label.TextProperty, s => s.Notes);
|
2016-05-24 06:48:34 +03:00
|
|
|
|
notesCell.Value.LineBreakMode = LineBreakMode.WordWrap;
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection = new TableSection(AppResources.LoginInformation)
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
|
|
|
|
nameCell
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NotesSection = new TableSection(AppResources.Notes)
|
|
|
|
|
{
|
|
|
|
|
notesCell
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Table = new ExtendedTableView
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Intent = TableIntent.Settings,
|
2016-05-24 06:48:34 +03:00
|
|
|
|
EnableScrolling = true,
|
2016-05-14 02:57:07 +03:00
|
|
|
|
HasUnevenRows = true,
|
2016-05-17 06:54:24 +03:00
|
|
|
|
EnableSelection = false,
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Root = new TableRoot
|
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection,
|
2016-06-14 03:03:16 +03:00
|
|
|
|
NotesSection
|
2016-05-14 02:57:07 +03:00
|
|
|
|
}
|
2016-05-08 06:11:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-05-14 02:57:07 +03:00
|
|
|
|
if(Device.OS == TargetPlatform.iOS)
|
|
|
|
|
{
|
|
|
|
|
Table.RowHeight = -1;
|
|
|
|
|
Table.EstimatedRowHeight = 70;
|
|
|
|
|
}
|
2016-11-08 07:45:46 +03:00
|
|
|
|
else if(Device.OS == TargetPlatform.Android)
|
|
|
|
|
{
|
2016-11-26 01:15:34 +03:00
|
|
|
|
// NOTE: This is going to cause problems with i18n strings since various languages have difference string sizes
|
2016-11-08 07:45:46 +03:00
|
|
|
|
PasswordCell.Button1.WidthRequest = 40;
|
2016-12-07 06:36:33 +03:00
|
|
|
|
PasswordCell.Button2.WidthRequest = 59;
|
|
|
|
|
UsernameCell.Button1.WidthRequest = 59;
|
2016-12-07 06:31:07 +03:00
|
|
|
|
UriCell.Button1.WidthRequest = 75;
|
2016-11-08 07:45:46 +03:00
|
|
|
|
}
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
Title = AppResources.ViewLogin;
|
2016-05-24 06:48:34 +03:00
|
|
|
|
Content = Table;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
BindingContext = Model;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 07:00:12 +03:00
|
|
|
|
protected async override void OnAppearing()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-02-17 08:16:09 +03:00
|
|
|
|
EditItem.InitEvents();
|
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
var login = await _loginService.GetByIdAsync(_loginId);
|
|
|
|
|
if(login == null)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await Navigation.PopForDeviceAsync();
|
2016-05-08 06:11:47 +03:00
|
|
|
|
return;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-08 06:11:47 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
Model.Update(login);
|
2016-05-12 00:30:09 +03:00
|
|
|
|
|
2016-06-14 03:03:16 +03:00
|
|
|
|
if(!Model.ShowUri)
|
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Remove(UriCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2017-01-03 08:17:15 +03:00
|
|
|
|
else if(!LoginInformationSection.Contains(UriCell))
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Add(UriCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!Model.ShowUsername)
|
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Remove(UsernameCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2017-01-03 08:17:15 +03:00
|
|
|
|
else if(!LoginInformationSection.Contains(UsernameCell))
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Add(UsernameCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!Model.ShowPassword)
|
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Remove(PasswordCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2017-01-03 08:17:15 +03:00
|
|
|
|
else if(!LoginInformationSection.Contains(PasswordCell))
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Add(PasswordCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
2016-06-14 03:03:16 +03:00
|
|
|
|
if(!Model.ShowNotes)
|
|
|
|
|
{
|
|
|
|
|
Table.Root.Remove(NotesSection);
|
|
|
|
|
}
|
|
|
|
|
else if(!Table.Root.Contains(NotesSection))
|
|
|
|
|
{
|
|
|
|
|
Table.Root.Add(NotesSection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnAppearing();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 08:16:09 +03:00
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
EditItem.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 20:42:09 +03:00
|
|
|
|
private void Copy(string copyText, string alertLabel)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
|
|
|
|
_clipboardService.CopyToClipboard(copyText);
|
2016-07-26 07:38:41 +03:00
|
|
|
|
_userDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 08:16:09 +03:00
|
|
|
|
private class EditLoginToolBarItem : ExtendedToolbarItem
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private readonly VaultViewLoginPage _page;
|
|
|
|
|
private readonly string _loginId;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
public EditLoginToolBarItem(VaultViewLoginPage page, string loginId)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
|
|
|
|
_page = page;
|
2017-01-03 08:17:15 +03:00
|
|
|
|
_loginId = loginId;
|
2016-05-07 20:42:09 +03:00
|
|
|
|
Text = AppResources.Edit;
|
2017-02-17 08:16:09 +03:00
|
|
|
|
ClickAction = async () => await ClickedItem();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2017-02-17 08:16:09 +03:00
|
|
|
|
private async Task ClickedItem()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
var page = new VaultEditLoginPage(_loginId);
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await _page.Navigation.PushForDeviceAsync(page);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|