new LabelValueCell for tableview on site view page

This commit is contained in:
Kyle Spearrin 2016-05-13 19:57:07 -04:00
parent 83f308cbf0
commit d288116b39
4 changed files with 144 additions and 74 deletions

View file

@ -53,6 +53,7 @@
<Compile Include="Controls\ExtendedEntry.cs" /> <Compile Include="Controls\ExtendedEntry.cs" />
<Compile Include="Controls\ExtendedTabbedPage.cs" /> <Compile Include="Controls\ExtendedTabbedPage.cs" />
<Compile Include="Controls\FormEditorCell.cs" /> <Compile Include="Controls\FormEditorCell.cs" />
<Compile Include="Controls\LabeledValueCell.cs" />
<Compile Include="Controls\FormPickerCell.cs" /> <Compile Include="Controls\FormPickerCell.cs" />
<Compile Include="Controls\FormEntryCell.cs" /> <Compile Include="Controls\FormEntryCell.cs" />
<Compile Include="Models\Api\ApiError.cs" /> <Compile Include="Models\Api\ApiError.cs" />

View file

@ -0,0 +1,97 @@
using Acr.UserDialogs;
using Bit.App.Abstractions;
using Bit.App.Resources;
using System;
using Xamarin.Forms;
using XLabs.Ioc;
namespace Bit.App.Controls
{
public class LabeledValueCell : ViewCell
{
private readonly IUserDialogs _userDialogs;
private readonly IClipboardService _clipboardService;
public LabeledValueCell(
string labelText,
string valueText = null,
bool copyValue = false,
bool password = false,
bool launch = false)
{
_userDialogs = Resolver.Resolve<IUserDialogs>();
_clipboardService = Resolver.Resolve<IClipboardService>();
var stackLayout = new StackLayout
{
Padding = new Thickness(15, 15, 15, 0),
BackgroundColor = Color.White
};
if(labelText != null)
{
Label = new Label
{
Text = labelText,
FontSize = 14,
TextColor = Color.FromHex("777777")
};
stackLayout.Children.Add(Label);
}
Value = new Label
{
Text = valueText,
LineBreakMode = LineBreakMode.TailTruncation,
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center
};
var valueStackLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
valueStackLayout.Children.Add(Value);
if(copyValue)
{
var copyButton = new Button
{
Text = AppResources.Copy,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Copy())
};
valueStackLayout.Children.Add(copyButton);
}
if(launch)
{
var launchButton = new Button
{
Text = AppResources.Launch,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Device.OpenUri(new Uri(Value.Text)))
};
valueStackLayout.Children.Add(launchButton);
}
stackLayout.Children.Add(valueStackLayout);
View = stackLayout;
}
public Label Label { get; private set; }
public Label Value { get; private set; }
private void Copy()
{
_clipboardService.CopyToClipboard(Value.Text);
_userDialogs.SuccessToast(string.Format(AppResources.ValueHasBeenCopied, Label.Text));
}
}
}

View file

@ -42,7 +42,6 @@ namespace Bit.App.Pages
Title = AppResources.MyVault; Title = AppResources.MyVault;
Content = listView; Content = listView;
NavigationPage.SetBackButtonTitle(this, AppResources.Back);
} }
protected override void OnAppearing() protected override void OnAppearing()

View file

@ -27,101 +27,70 @@ namespace Bit.App.Pages
} }
private VaultViewSitePageModel Model { get; set; } = new VaultViewSitePageModel(); private VaultViewSitePageModel Model { get; set; } = new VaultViewSitePageModel();
private ExtendedTableView Table { get; set; }
private void Init() private void Init()
{ {
ToolbarItems.Add(new EditSiteToolBarItem(this, _siteId)); ToolbarItems.Add(new EditSiteToolBarItem(this, _siteId));
ToolbarItems.Add(new DismissModalToolBarItem(this)); ToolbarItems.Add(new DismissModalToolBarItem(this));
var stackLayout = new StackLayout();
// Username // Username
var usernameRow = new StackLayout { Orientation = StackOrientation.Horizontal }; var nameCell = new LabeledValueCell(AppResources.Name);
var usernameLabel = new Label nameCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Name);
{
HorizontalOptions = LayoutOptions.StartAndExpand, // Username
VerticalOptions = LayoutOptions.Center, var usernameCell = new LabeledValueCell(AppResources.Username, copyValue: true);
LineBreakMode = LineBreakMode.TailTruncation usernameCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Username);
};
usernameLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Username);
usernameRow.Children.Add(usernameLabel);
usernameRow.Children.Add(new Button
{
Text = AppResources.Copy,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Copy(usernameLabel.Text, AppResources.Username))
});
stackLayout.Children.Add(new Label { Text = AppResources.Username });
stackLayout.Children.Add(usernameRow);
// Password // Password
var passwordRow = new StackLayout { Orientation = StackOrientation.Horizontal }; var passwordCell = new LabeledValueCell(AppResources.Password, copyValue: true);
var passwordLabel = new Label passwordCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Password);
{
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.TailTruncation
};
passwordLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.MaskedPassword);
passwordRow.Children.Add(passwordLabel);
var togglePasswordButton = new Button
{
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Model.ShowPassword = !Model.ShowPassword)
};
togglePasswordButton.CommandParameter = togglePasswordButton;
togglePasswordButton.SetBinding<VaultViewSitePageModel>(Button.TextProperty, s => s.ShowHideText);
passwordRow.Children.Add(togglePasswordButton);
passwordRow.Children.Add(new Button
{
Text = AppResources.Copy,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Copy(Model.Password, AppResources.Password))
});
stackLayout.Children.Add(new Label { Text = AppResources.Password });
stackLayout.Children.Add(passwordRow);
// URI // URI
var uriRow = new StackLayout { Orientation = StackOrientation.Horizontal }; var uriCell = new LabeledValueCell(AppResources.URI, launch: true);
var uriLabel = new Label uriCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Uri);
{
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.TailTruncation
};
uriLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Uri);
uriRow.Children.Add(uriLabel);
uriRow.Children.Add(new Button
{
Text = AppResources.Launch,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Device.OpenUri(new Uri(uriLabel.Text)))
});
stackLayout.Children.Add(new Label { Text = AppResources.Website });
stackLayout.Children.Add(uriRow);
// Notes // Notes
var notes = new Label { Text = AppResources.Notes }; var notesCell = new LabeledValueCell(AppResources.Notes);
notes.SetBinding<VaultViewSitePageModel>(Label.IsVisibleProperty, s => s.ShowNotes); notesCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Notes);
stackLayout.Children.Add(notes);
var notesLabel = new Label(); Table = new ExtendedTableView
notesLabel.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.Notes); {
notesLabel.SetBinding<VaultViewSitePageModel>(Label.IsVisibleProperty, s => s.ShowNotes); Intent = TableIntent.Settings,
stackLayout.Children.Add(notesLabel); EnableScrolling = false,
HasUnevenRows = true,
EnableSelection = true,
Root = new TableRoot
{
new TableSection("Site Information")
{
uriCell,
nameCell,
usernameCell,
passwordCell
},
new TableSection(AppResources.Notes)
{
notesCell
}
}
};
if(Device.OS == TargetPlatform.iOS)
{
Table.RowHeight = -1;
Table.EstimatedRowHeight = 70;
}
var scrollView = new ScrollView var scrollView = new ScrollView
{ {
Content = stackLayout, Content = Table,
Orientation = ScrollOrientation.Vertical Orientation = ScrollOrientation.Vertical
}; };
SetBinding(Page.TitleProperty, new Binding("PageTitle")); SetBinding(Page.TitleProperty, new Binding("PageTitle"));
Content = scrollView; Content = scrollView;
BindingContext = Model; BindingContext = Model;
NavigationPage.SetBackButtonTitle(this, AppResources.Back);
} }
protected override void OnAppearing() protected override void OnAppearing()
@ -136,6 +105,10 @@ namespace Bit.App.Pages
Model.Update(site); Model.Update(site);
base.OnAppearing(); base.OnAppearing();
// 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);
} }
private void Copy(string copyText, string alertLabel) private void Copy(string copyText, string alertLabel)