switch cell for fields, btn widths on ios too

This commit is contained in:
Kyle Spearrin 2018-03-14 22:59:31 -04:00
parent e08a0a0938
commit c95251c903
7 changed files with 99 additions and 87 deletions

View file

@ -98,7 +98,8 @@ namespace Bit.App.Controls
_buttonStackLayout = new StackLayout _buttonStackLayout = new StackLayout
{ {
Orientation = StackOrientation.Horizontal, Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.CenterAndExpand VerticalOptions = LayoutOptions.CenterAndExpand,
Spacing = 5
}; };
imageStackLayout.Children.Add(_buttonStackLayout); imageStackLayout.Children.Add(_buttonStackLayout);
@ -106,36 +107,25 @@ namespace Bit.App.Controls
{ {
Button1 = new ExtendedButton { Image = button1 }; Button1 = new ExtendedButton { Image = button1 };
_buttonStackLayout.Children.Add(Button1); _buttonStackLayout.Children.Add(Button1);
Button1.Padding = new Thickness(0);
if(Device.RuntimePlatform == Device.Android) Button1.BackgroundColor = Color.Transparent;
{ Button1.WidthRequest = 40;
Button1.Padding = new Thickness(0); Button1.VerticalOptions = LayoutOptions.FillAndExpand;
Button1.BackgroundColor = Color.Transparent;
Button1.WidthRequest = 40;
}
} }
if(!string.IsNullOrWhiteSpace(button2)) if(!string.IsNullOrWhiteSpace(button2))
{ {
Button2 = new ExtendedButton { Image = button2 }; Button2 = new ExtendedButton { Image = button2 };
_buttonStackLayout.Children.Add(Button2); _buttonStackLayout.Children.Add(Button2);
Button2.Padding = new Thickness(0);
if(Device.RuntimePlatform == Device.Android) Button2.BackgroundColor = Color.Transparent;
{ Button2.WidthRequest = 40;
Button2.Padding = new Thickness(0); Button2.VerticalOptions = LayoutOptions.FillAndExpand;
Button2.BackgroundColor = Color.Transparent;
Button2.WidthRequest = 40;
}
} }
} }
if(Device.RuntimePlatform == Device.Android) if(Device.RuntimePlatform == Device.Android)
{ {
if(_buttonStackLayout != null)
{
_buttonStackLayout.Spacing = 5;
}
var deviceInfo = Resolver.Resolve<IDeviceInfoService>(); var deviceInfo = Resolver.Resolve<IDeviceInfoService>();
if(useLabelAsPlaceholder) if(useLabelAsPlaceholder)
{ {

View file

@ -0,0 +1,47 @@
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class FormSwitchCell : ExtendedViewCell
{
public FormSwitchCell(string labelText, string button1 = null)
{
Label = new Label
{
Text = labelText,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black,
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
};
Switch = new Switch
{
VerticalOptions = LayoutOptions.Center
};
var stackLayout = new StackLayout
{
Padding = new Thickness(15, 5),
Orientation = StackOrientation.Horizontal,
Children = { Label, Switch }
};
stackLayout.AdjustPaddingForDevice();
if(!string.IsNullOrWhiteSpace(button1))
{
Button1 = new ExtendedButton { Image = button1 };
stackLayout.Children.Add(Button1);
Button1.BackgroundColor = Color.Transparent;
Button1.Padding = new Thickness(0);
Button1.WidthRequest = 40;
Button1.VerticalOptions = LayoutOptions.FillAndExpand;
}
View = stackLayout;
}
public Switch Switch { get; private set; }
public Label Label { get; set; }
public ExtendedButton Button1 { get; set; }
}
}

View file

@ -54,7 +54,8 @@ namespace Bit.App.Controls
var buttonStackLayout = new StackLayout var buttonStackLayout = new StackLayout
{ {
Orientation = StackOrientation.Horizontal, Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.CenterAndExpand VerticalOptions = LayoutOptions.CenterAndExpand,
Spacing = 5
}; };
if(subText != null) if(subText != null)
@ -75,8 +76,11 @@ namespace Bit.App.Controls
{ {
Image = button1Image, Image = button1Image,
HorizontalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.FillAndExpand,
Margin = new Thickness(0) Margin = new Thickness(0),
Padding = new Thickness(0),
BackgroundColor = Color.Transparent,
WidthRequest = 40
}; };
buttonStackLayout.Children.Add(Button1); buttonStackLayout.Children.Add(Button1);
@ -88,8 +92,11 @@ namespace Bit.App.Controls
{ {
Image = button2Image, Image = button2Image,
HorizontalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.FillAndExpand,
Margin = new Thickness(0) Margin = new Thickness(0),
Padding = new Thickness(0),
BackgroundColor = Color.Transparent,
WidthRequest = 40
}; };
buttonStackLayout.Children.Add(Button2); buttonStackLayout.Children.Add(Button2);
@ -97,21 +104,6 @@ namespace Bit.App.Controls
if(Device.RuntimePlatform == Device.Android) if(Device.RuntimePlatform == Device.Android)
{ {
buttonStackLayout.Spacing = 5;
if(Button1 != null)
{
Button1.Padding = new Thickness(0);
Button1.BackgroundColor = Color.Transparent;
Button1.WidthRequest = 40;
}
if(Button2 != null)
{
Button2.Padding = new Thickness(0);
Button2.BackgroundColor = Color.Transparent;
Button2.WidthRequest = 40;
}
containerStackLayout.AdjustPaddingForDevice(); containerStackLayout.AdjustPaddingForDevice();
} }
else if(Device.RuntimePlatform == Device.UWP) else if(Device.RuntimePlatform == Device.UWP)

View file

@ -129,10 +129,6 @@ namespace Bit.App.Pages
nameof(VaultViewCipherPageModel.MaskedLoginPassword)); nameof(VaultViewCipherPageModel.MaskedLoginPassword));
LoginPasswordCell.Button1.SetBinding(Button.ImageProperty, LoginPasswordCell.Button1.SetBinding(Button.ImageProperty,
nameof(VaultViewCipherPageModel.LoginShowHideImage)); nameof(VaultViewCipherPageModel.LoginShowHideImage));
if(Device.RuntimePlatform == Device.iOS)
{
LoginPasswordCell.Button1.Margin = new Thickness(10, 0);
}
LoginPasswordCell.Button1.Command = LoginPasswordCell.Button1.Command =
new Command(() => Model.RevealLoginPassword = !Model.RevealLoginPassword); new Command(() => Model.RevealLoginPassword = !Model.RevealLoginPassword);
LoginPasswordCell.Button2.Command = LoginPasswordCell.Button2.Command =
@ -575,11 +571,6 @@ namespace Bit.App.Pages
: base(field.Name, field.MaskedValue, string.Empty, "clipboard.png") : base(field.Name, field.MaskedValue, string.Empty, "clipboard.png")
{ {
Value.FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier"); Value.FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier");
if(Device.RuntimePlatform == Device.iOS)
{
Button1.Margin = new Thickness(10, 0);
}
Button1.Image = "eye"; Button1.Image = "eye";
Button1.Command = new Command(() => Button1.Command = new Command(() =>
{ {

View file

@ -253,46 +253,43 @@ namespace Bit.App.Utilities
TableSection fieldsSection, Page page) TableSection fieldsSection, Page page)
{ {
Cell cell; Cell cell;
FormEntryCell feCell = null;
FormSwitchCell fsCell = null;
switch(type) switch(type)
{ {
case FieldType.Text: case FieldType.Text:
case FieldType.Hidden: case FieldType.Hidden:
var hidden = type == FieldType.Hidden; var hidden = type == FieldType.Hidden;
var textFieldCell = new FormEntryCell(label, isPassword: hidden, cell = feCell = new FormEntryCell(label, isPassword: hidden,
button1: hidden ? "eye.png" : "cog_alt.png", button2: hidden ? "cog_alt.png" : null); button1: hidden ? "eye.png" : "cog_alt.png", button2: hidden ? "cog_alt.png" : null);
textFieldCell.Entry.Text = value; feCell.Entry.Text = value;
textFieldCell.Entry.DisableAutocapitalize = true; feCell.Entry.DisableAutocapitalize = true;
textFieldCell.Entry.Autocorrect = false; feCell.Entry.Autocorrect = false;
if(hidden) if(hidden)
{ {
textFieldCell.Entry.FontFamily = OnPlatform(iOS: "Menlo-Regular", Android: "monospace", feCell.Entry.FontFamily = OnPlatform(iOS: "Menlo-Regular", Android: "monospace",
Windows: "Courier"); Windows: "Courier");
textFieldCell.Button1.Command = new Command(() => feCell.Button1.Command = new Command(() =>
{ {
textFieldCell.Entry.InvokeToggleIsPassword(); feCell.Entry.InvokeToggleIsPassword();
textFieldCell.Button1.Image = "eye" + feCell.Button1.Image = "eye" +
(!textFieldCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty) + ".png"; (!feCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty) + ".png";
}); });
} }
cell = textFieldCell;
break; break;
case FieldType.Boolean: case FieldType.Boolean:
var switchFieldCell = new ExtendedSwitchCell cell = fsCell = new FormSwitchCell(label, "cog_alt.png");
{ fsCell.Switch.IsToggled = value == "true";
Text = label,
On = value == "true"
};
cell = switchFieldCell;
break; break;
default: default:
cell = null; cell = null;
break; break;
} }
if(cell is FormEntryCell feCell) if(cell != null)
{ {
var optionsButton = feCell.Button2 ?? feCell.Button1; var optionsButton = feCell != null ? feCell.Button2 ?? feCell.Button1 : fsCell.Button1;
optionsButton.Command = new Command(async () => optionsButton.Command = new Command(async () =>
{ {
var optionsVal = await page.DisplayActionSheet(AppResources.Options, AppResources.Cancel, var optionsVal = await page.DisplayActionSheet(AppResources.Options, AppResources.Cancel,
@ -304,25 +301,17 @@ namespace Bit.App.Utilities
fieldsSection.Remove(cell); fieldsSection.Remove(cell);
} }
if(cell is IDisposable disposableCell) if(feCell != null)
{ {
disposableCell.Dispose(); feCell.Dispose();
} }
cell = feCell = null; cell = null;
feCell = null;
fsCell = null;
} }
else if(optionsVal == AppResources.Edit) else if(optionsVal == AppResources.Edit)
{ {
string existingLabel = null; var existingLabel = feCell?.Label.Text ?? fsCell?.Label.Text;
var esCell = cell as ExtendedSwitchCell;
if(feCell != null)
{
existingLabel = feCell.Label.Text;
}
else if(esCell != null)
{
existingLabel = esCell.Text;
}
var daService = Resolver.Resolve<IDeviceActionService>(); var daService = Resolver.Resolve<IDeviceActionService>();
var editLabel = await daService.DisplayPromptAync(AppResources.CustomFieldName, var editLabel = await daService.DisplayPromptAync(AppResources.CustomFieldName,
null, existingLabel); null, existingLabel);
@ -332,9 +321,9 @@ namespace Bit.App.Utilities
{ {
feCell.Label.Text = editLabel; feCell.Label.Text = editLabel;
} }
else if(esCell != null) else if(fsCell != null)
{ {
esCell.Text = editLabel; fsCell.Label.Text = editLabel;
} }
} }
} }
@ -362,13 +351,13 @@ namespace Bit.App.Utilities
Type = entryCell.Entry.IsPassword ? FieldType.Hidden : FieldType.Text Type = entryCell.Entry.IsPassword ? FieldType.Hidden : FieldType.Text
}); });
} }
else if(cell is ExtendedSwitchCell switchCell) else if(cell is FormSwitchCell switchCell)
{ {
var value = switchCell.On ? "true" : "false"; var value = switchCell.Switch.IsToggled ? "true" : "false";
fields.Add(new Field fields.Add(new Field
{ {
Name = string.IsNullOrWhiteSpace(switchCell.Text) ? null : Name = string.IsNullOrWhiteSpace(switchCell.Label.Text) ? null :
switchCell.Text.Encrypt(cipher.OrganizationId), switchCell.Label.Text.Encrypt(cipher.OrganizationId),
Value = value.Encrypt(cipher.OrganizationId), Value = value.Encrypt(cipher.OrganizationId),
Type = FieldType.Boolean Type = FieldType.Boolean
}); });

View file

@ -56,4 +56,7 @@
<Content Include="$(MSBuildThisFileDirectory)user.png" /> <Content Include="$(MSBuildThisFileDirectory)user.png" />
<Content Include="$(MSBuildThisFileDirectory)yubikey.png" /> <Content Include="$(MSBuildThisFileDirectory)yubikey.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)cog_alt.png" />
</ItemGroup>
</Project> </Project>

BIN
src/UWP.Images/cog_alt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B