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();
|
|
|
|
|
|
|
|
|
|
private void Init()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(new EditSiteToolBarItem(this, _siteId));
|
2016-05-13 07:11:32 +03:00
|
|
|
|
ToolbarItems.Add(new DismissModalToolBarItem(this));
|
2016-05-08 06:11:47 +03:00
|
|
|
|
var stackLayout = new StackLayout();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// Username
|
2016-05-07 05:29:03 +03:00
|
|
|
|
var usernameRow = new StackLayout { Orientation = StackOrientation.Horizontal };
|
|
|
|
|
var usernameLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
HorizontalOptions = LayoutOptions.StartAndExpand,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.TailTruncation
|
|
|
|
|
};
|
2016-05-08 06:11:47 +03:00
|
|
|
|
usernameLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Username);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
usernameRow.Children.Add(usernameLabel);
|
|
|
|
|
usernameRow.Children.Add(new Button
|
|
|
|
|
{
|
2016-05-07 20:42:09 +03:00
|
|
|
|
Text = AppResources.Copy,
|
2016-05-07 05:29:03 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.End,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
2016-05-07 20:42:09 +03:00
|
|
|
|
Command = new Command(() => Copy(usernameLabel.Text, AppResources.Username))
|
2016-05-07 05:29:03 +03:00
|
|
|
|
});
|
2016-05-08 06:11:47 +03:00
|
|
|
|
stackLayout.Children.Add(new Label { Text = AppResources.Username });
|
|
|
|
|
stackLayout.Children.Add(usernameRow);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// Password
|
2016-05-07 05:29:03 +03:00
|
|
|
|
var passwordRow = new StackLayout { Orientation = StackOrientation.Horizontal };
|
|
|
|
|
var passwordLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
HorizontalOptions = LayoutOptions.StartAndExpand,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.TailTruncation
|
|
|
|
|
};
|
2016-05-08 06:11:47 +03:00
|
|
|
|
passwordLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.MaskedPassword);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
passwordRow.Children.Add(passwordLabel);
|
|
|
|
|
var togglePasswordButton = new Button
|
|
|
|
|
{
|
|
|
|
|
HorizontalOptions = LayoutOptions.End,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
2016-05-08 06:11:47 +03:00
|
|
|
|
Command = new Command(() => Model.ShowPassword = !Model.ShowPassword)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
};
|
|
|
|
|
togglePasswordButton.CommandParameter = togglePasswordButton;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
togglePasswordButton.SetBinding<VaultViewSitePageModel>(Button.TextProperty, s => s.ShowHideText);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
passwordRow.Children.Add(togglePasswordButton);
|
|
|
|
|
passwordRow.Children.Add(new Button
|
|
|
|
|
{
|
2016-05-07 20:42:09 +03:00
|
|
|
|
Text = AppResources.Copy,
|
2016-05-07 05:29:03 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.End,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
2016-05-08 06:11:47 +03:00
|
|
|
|
Command = new Command(() => Copy(Model.Password, AppResources.Password))
|
2016-05-07 05:29:03 +03:00
|
|
|
|
});
|
2016-05-08 06:11:47 +03:00
|
|
|
|
stackLayout.Children.Add(new Label { Text = AppResources.Password });
|
|
|
|
|
stackLayout.Children.Add(passwordRow);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// URI
|
2016-05-07 05:29:03 +03:00
|
|
|
|
var uriRow = new StackLayout { Orientation = StackOrientation.Horizontal };
|
2016-05-08 06:11:47 +03:00
|
|
|
|
var uriLabel = new Label
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
|
|
|
|
HorizontalOptions = LayoutOptions.StartAndExpand,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.TailTruncation
|
2016-05-08 06:11:47 +03:00
|
|
|
|
};
|
|
|
|
|
uriLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Uri);
|
|
|
|
|
uriRow.Children.Add(uriLabel);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
uriRow.Children.Add(new Button
|
|
|
|
|
{
|
2016-05-07 20:42:09 +03:00
|
|
|
|
Text = AppResources.Launch,
|
2016-05-07 05:29:03 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.End,
|
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
2016-05-08 06:11:47 +03:00
|
|
|
|
Command = new Command(() => Device.OpenUri(new Uri(uriLabel.Text)))
|
2016-05-07 05:29:03 +03:00
|
|
|
|
});
|
2016-05-07 20:42:09 +03:00
|
|
|
|
stackLayout.Children.Add(new Label { Text = AppResources.Website });
|
2016-05-07 05:29:03 +03:00
|
|
|
|
stackLayout.Children.Add(uriRow);
|
2016-05-08 06:11:47 +03:00
|
|
|
|
|
|
|
|
|
// Notes
|
|
|
|
|
var notes = new Label { Text = AppResources.Notes };
|
|
|
|
|
notes.SetBinding<VaultViewSitePageModel>(Label.IsVisibleProperty, s => s.ShowNotes);
|
|
|
|
|
stackLayout.Children.Add(notes);
|
|
|
|
|
var notesLabel = new Label();
|
|
|
|
|
notesLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Notes);
|
|
|
|
|
notesLabel.SetBinding<VaultViewSitePageModel>(Label.IsVisibleProperty, s => s.ShowNotes);
|
|
|
|
|
stackLayout.Children.Add(notesLabel);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
|
|
|
|
var scrollView = new ScrollView
|
|
|
|
|
{
|
|
|
|
|
Content = stackLayout,
|
|
|
|
|
Orientation = ScrollOrientation.Vertical
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
SetBinding(Page.TitleProperty, new Binding("PageTitle"));
|
2016-05-07 05:29:03 +03:00
|
|
|
|
Content = scrollView;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
BindingContext = Model;
|
2016-05-08 07:28:14 +03:00
|
|
|
|
NavigationPage.SetBackButtonTitle(this, AppResources.Back);
|
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-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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|