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;
|
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 VaultViewSitePage : ContentPage
|
|
|
|
|
{
|
2016-05-07 05:29:03 +03:00
|
|
|
|
private readonly string _siteId;
|
|
|
|
|
private readonly ISiteService _siteService;
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
private readonly IClipboardService _clipboardService;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-05-07 05:29:03 +03:00
|
|
|
|
public VaultViewSitePage(string siteId)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
|
|
|
|
_siteId = siteId;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
_siteService = Resolver.Resolve<ISiteService>();
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_clipboardService = Resolver.Resolve<IClipboardService>();
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
private VaultViewSitePageModel Model { get; set; } = new VaultViewSitePageModel();
|
2016-05-14 02:57:07 +03:00
|
|
|
|
private ExtendedTableView Table { get; set; }
|
2016-05-08 06:11:47 +03:00
|
|
|
|
|
|
|
|
|
private void Init()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(new EditSiteToolBarItem(this, _siteId));
|
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-05-08 06:11:47 +03:00
|
|
|
|
// Username
|
2016-05-14 02:57:07 +03:00
|
|
|
|
var nameCell = new LabeledValueCell(AppResources.Name);
|
|
|
|
|
nameCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Name);
|
|
|
|
|
|
|
|
|
|
// Username
|
2016-05-14 08:34:42 +03:00
|
|
|
|
var usernameCell = new LabeledValueCell(AppResources.Username, button1Text: AppResources.Copy);
|
2016-05-14 02:57:07 +03:00
|
|
|
|
usernameCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Username);
|
2016-05-14 08:34:42 +03:00
|
|
|
|
usernameCell.Button1.Command = new Command(() => Copy(Model.Username, AppResources.Username));
|
2016-05-17 06:54:24 +03:00
|
|
|
|
usernameCell.View.SetBinding<VaultViewSitePageModel>(IsVisibleProperty, s => s.ShowUsername);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// Password
|
2016-05-14 08:34:42 +03:00
|
|
|
|
var passwordCell = new LabeledValueCell(AppResources.Password, button1Text: AppResources.Show, button2Text: AppResources.Copy);
|
|
|
|
|
passwordCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.MaskedPassword);
|
|
|
|
|
passwordCell.Button1.SetBinding<VaultViewSitePageModel>(Button.TextProperty, s => s.ShowHideText);
|
|
|
|
|
passwordCell.Button1.Command = new Command(() => Model.ShowPassword = !Model.ShowPassword);
|
|
|
|
|
passwordCell.Button2.Command = new Command(() => Copy(Model.Password, AppResources.Password));
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// URI
|
2016-05-14 08:34:42 +03:00
|
|
|
|
var uriCell = new LabeledValueCell(AppResources.Website, button1Text: AppResources.Launch);
|
|
|
|
|
uriCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.UriHost);
|
2016-05-17 06:54:24 +03:00
|
|
|
|
uriCell.Button1.Command = new Command(() => Device.OpenUri(new Uri(Model.Uri)));
|
|
|
|
|
uriCell.View.SetBinding<VaultViewSitePageModel>(IsVisibleProperty, s => s.ShowUri);
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
|
|
|
|
// Notes
|
2016-05-14 08:34:42 +03:00
|
|
|
|
var notesCell = new LabeledValueCell();
|
2016-05-14 02:57:07 +03:00
|
|
|
|
notesCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Notes);
|
2016-05-17 06:54:24 +03:00
|
|
|
|
notesCell.View.SetBinding<VaultViewSitePageModel>(IsVisibleProperty, s => s.ShowNotes);
|
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,
|
|
|
|
|
EnableScrolling = false,
|
|
|
|
|
HasUnevenRows = true,
|
2016-05-17 06:54:24 +03:00
|
|
|
|
EnableSelection = false,
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Root = new TableRoot
|
|
|
|
|
{
|
|
|
|
|
new TableSection("Site Information")
|
|
|
|
|
{
|
|
|
|
|
nameCell,
|
2016-05-17 06:54:24 +03:00
|
|
|
|
uriCell,
|
2016-05-14 02:57:07 +03:00
|
|
|
|
usernameCell,
|
|
|
|
|
passwordCell
|
|
|
|
|
},
|
|
|
|
|
new TableSection(AppResources.Notes)
|
|
|
|
|
{
|
|
|
|
|
notesCell
|
|
|
|
|
}
|
|
|
|
|
}
|
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-05-07 05:29:03 +03:00
|
|
|
|
|
|
|
|
|
var scrollView = new ScrollView
|
|
|
|
|
{
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Content = Table,
|
2016-05-07 05:29:03 +03:00
|
|
|
|
Orientation = ScrollOrientation.Vertical
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-17 06:54:24 +03:00
|
|
|
|
Title = "View Site";
|
2016-05-07 05:29:03 +03:00
|
|
|
|
Content = scrollView;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
BindingContext = Model;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
protected override void OnAppearing()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2016-05-08 06:11:47 +03:00
|
|
|
|
var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult();
|
|
|
|
|
if(site == null)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// TODO: handle error. navigate back? should never happen...
|
|
|
|
|
return;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-08 06:11:47 +03:00
|
|
|
|
|
|
|
|
|
Model.Update(site);
|
2016-05-12 00:30:09 +03:00
|
|
|
|
|
|
|
|
|
base.OnAppearing();
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
|
|
|
|
// Hack to get table row height binding to update. Better way to do this probably?
|
|
|
|
|
Table.Root.Add(new TableSection { new TextCell() });
|
|
|
|
|
Table.Root.RemoveAt(Table.Root.Count - 1);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
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-05-07 20:42:09 +03:00
|
|
|
|
_userDialogs.SuccessToast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class EditSiteToolBarItem : ToolbarItem
|
|
|
|
|
{
|
|
|
|
|
private readonly VaultViewSitePage _page;
|
|
|
|
|
private readonly string _siteId;
|
|
|
|
|
|
|
|
|
|
public EditSiteToolBarItem(VaultViewSitePage page, string siteId)
|
|
|
|
|
{
|
|
|
|
|
_page = page;
|
|
|
|
|
_siteId = siteId;
|
2016-05-07 20:42:09 +03:00
|
|
|
|
Text = AppResources.Edit;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
Clicked += ClickedItem;
|
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-05-07 05:29:03 +03:00
|
|
|
|
private async void ClickedItem(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-05-13 07:11:32 +03:00
|
|
|
|
var page = new ExtendedNavigationPage(new VaultEditSitePage(_siteId));
|
|
|
|
|
await _page.Navigation.PushModalAsync(page);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|