From c95251c90323a78b9129b87c8f47a9b31d5a621c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 14 Mar 2018 22:59:31 -0400 Subject: [PATCH] switch cell for fields, btn widths on ios too --- src/App/Controls/FormEntryCell.cs | 30 ++++------ src/App/Controls/FormSwitchCell.cs | 47 +++++++++++++++ src/App/Controls/LabeledValueCell.cs | 32 ++++------ src/App/Pages/Vault/VaultViewCipherPage.cs | 9 --- src/App/Utilities/Helpers.cs | 65 +++++++++------------ src/UWP.Images/UWP.Images.projitems | 3 + src/UWP.Images/cog_alt.png | Bin 0 -> 738 bytes 7 files changed, 99 insertions(+), 87 deletions(-) create mode 100644 src/App/Controls/FormSwitchCell.cs create mode 100644 src/UWP.Images/cog_alt.png diff --git a/src/App/Controls/FormEntryCell.cs b/src/App/Controls/FormEntryCell.cs index 218c7d673..8ceb1dc3d 100644 --- a/src/App/Controls/FormEntryCell.cs +++ b/src/App/Controls/FormEntryCell.cs @@ -98,7 +98,8 @@ namespace Bit.App.Controls _buttonStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, - VerticalOptions = LayoutOptions.CenterAndExpand + VerticalOptions = LayoutOptions.CenterAndExpand, + Spacing = 5 }; imageStackLayout.Children.Add(_buttonStackLayout); @@ -106,36 +107,25 @@ namespace Bit.App.Controls { Button1 = new ExtendedButton { Image = button1 }; _buttonStackLayout.Children.Add(Button1); - - if(Device.RuntimePlatform == Device.Android) - { - Button1.Padding = new Thickness(0); - Button1.BackgroundColor = Color.Transparent; - Button1.WidthRequest = 40; - } + Button1.Padding = new Thickness(0); + Button1.BackgroundColor = Color.Transparent; + Button1.WidthRequest = 40; + Button1.VerticalOptions = LayoutOptions.FillAndExpand; } if(!string.IsNullOrWhiteSpace(button2)) { Button2 = new ExtendedButton { Image = button2 }; _buttonStackLayout.Children.Add(Button2); - - if(Device.RuntimePlatform == Device.Android) - { - Button2.Padding = new Thickness(0); - Button2.BackgroundColor = Color.Transparent; - Button2.WidthRequest = 40; - } + Button2.Padding = new Thickness(0); + Button2.BackgroundColor = Color.Transparent; + Button2.WidthRequest = 40; + Button2.VerticalOptions = LayoutOptions.FillAndExpand; } } if(Device.RuntimePlatform == Device.Android) { - if(_buttonStackLayout != null) - { - _buttonStackLayout.Spacing = 5; - } - var deviceInfo = Resolver.Resolve(); if(useLabelAsPlaceholder) { diff --git a/src/App/Controls/FormSwitchCell.cs b/src/App/Controls/FormSwitchCell.cs new file mode 100644 index 000000000..28ec98eb8 --- /dev/null +++ b/src/App/Controls/FormSwitchCell.cs @@ -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; } + } +} diff --git a/src/App/Controls/LabeledValueCell.cs b/src/App/Controls/LabeledValueCell.cs index aec9fdf9a..d2b84fc04 100644 --- a/src/App/Controls/LabeledValueCell.cs +++ b/src/App/Controls/LabeledValueCell.cs @@ -54,7 +54,8 @@ namespace Bit.App.Controls var buttonStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, - VerticalOptions = LayoutOptions.CenterAndExpand + VerticalOptions = LayoutOptions.CenterAndExpand, + Spacing = 5 }; if(subText != null) @@ -75,8 +76,11 @@ namespace Bit.App.Controls { Image = button1Image, HorizontalOptions = LayoutOptions.End, - VerticalOptions = LayoutOptions.Center, - Margin = new Thickness(0) + VerticalOptions = LayoutOptions.FillAndExpand, + Margin = new Thickness(0), + Padding = new Thickness(0), + BackgroundColor = Color.Transparent, + WidthRequest = 40 }; buttonStackLayout.Children.Add(Button1); @@ -88,8 +92,11 @@ namespace Bit.App.Controls { Image = button2Image, HorizontalOptions = LayoutOptions.End, - VerticalOptions = LayoutOptions.Center, - Margin = new Thickness(0) + VerticalOptions = LayoutOptions.FillAndExpand, + Margin = new Thickness(0), + Padding = new Thickness(0), + BackgroundColor = Color.Transparent, + WidthRequest = 40 }; buttonStackLayout.Children.Add(Button2); @@ -97,21 +104,6 @@ namespace Bit.App.Controls 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(); } else if(Device.RuntimePlatform == Device.UWP) diff --git a/src/App/Pages/Vault/VaultViewCipherPage.cs b/src/App/Pages/Vault/VaultViewCipherPage.cs index 520c763f1..8da39c72c 100644 --- a/src/App/Pages/Vault/VaultViewCipherPage.cs +++ b/src/App/Pages/Vault/VaultViewCipherPage.cs @@ -129,10 +129,6 @@ namespace Bit.App.Pages nameof(VaultViewCipherPageModel.MaskedLoginPassword)); LoginPasswordCell.Button1.SetBinding(Button.ImageProperty, nameof(VaultViewCipherPageModel.LoginShowHideImage)); - if(Device.RuntimePlatform == Device.iOS) - { - LoginPasswordCell.Button1.Margin = new Thickness(10, 0); - } LoginPasswordCell.Button1.Command = new Command(() => Model.RevealLoginPassword = !Model.RevealLoginPassword); LoginPasswordCell.Button2.Command = @@ -575,11 +571,6 @@ namespace Bit.App.Pages : base(field.Name, field.MaskedValue, string.Empty, "clipboard.png") { 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.Command = new Command(() => { diff --git a/src/App/Utilities/Helpers.cs b/src/App/Utilities/Helpers.cs index 4e472c38e..ce63116da 100644 --- a/src/App/Utilities/Helpers.cs +++ b/src/App/Utilities/Helpers.cs @@ -253,46 +253,43 @@ namespace Bit.App.Utilities TableSection fieldsSection, Page page) { Cell cell; + FormEntryCell feCell = null; + FormSwitchCell fsCell = null; switch(type) { case FieldType.Text: case 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); - textFieldCell.Entry.Text = value; - textFieldCell.Entry.DisableAutocapitalize = true; - textFieldCell.Entry.Autocorrect = false; + feCell.Entry.Text = value; + feCell.Entry.DisableAutocapitalize = true; + feCell.Entry.Autocorrect = false; if(hidden) { - textFieldCell.Entry.FontFamily = OnPlatform(iOS: "Menlo-Regular", Android: "monospace", + feCell.Entry.FontFamily = OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier"); - textFieldCell.Button1.Command = new Command(() => + feCell.Button1.Command = new Command(() => { - textFieldCell.Entry.InvokeToggleIsPassword(); - textFieldCell.Button1.Image = "eye" + - (!textFieldCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty) + ".png"; + feCell.Entry.InvokeToggleIsPassword(); + feCell.Button1.Image = "eye" + + (!feCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty) + ".png"; }); } - cell = textFieldCell; break; case FieldType.Boolean: - var switchFieldCell = new ExtendedSwitchCell - { - Text = label, - On = value == "true" - }; - cell = switchFieldCell; + cell = fsCell = new FormSwitchCell(label, "cog_alt.png"); + fsCell.Switch.IsToggled = value == "true"; break; default: cell = null; 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 () => { var optionsVal = await page.DisplayActionSheet(AppResources.Options, AppResources.Cancel, @@ -304,25 +301,17 @@ namespace Bit.App.Utilities 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) { - string existingLabel = null; - var esCell = cell as ExtendedSwitchCell; - if(feCell != null) - { - existingLabel = feCell.Label.Text; - } - else if(esCell != null) - { - existingLabel = esCell.Text; - } - + var existingLabel = feCell?.Label.Text ?? fsCell?.Label.Text; var daService = Resolver.Resolve(); var editLabel = await daService.DisplayPromptAync(AppResources.CustomFieldName, null, existingLabel); @@ -332,9 +321,9 @@ namespace Bit.App.Utilities { 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 }); } - 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 { - Name = string.IsNullOrWhiteSpace(switchCell.Text) ? null : - switchCell.Text.Encrypt(cipher.OrganizationId), + Name = string.IsNullOrWhiteSpace(switchCell.Label.Text) ? null : + switchCell.Label.Text.Encrypt(cipher.OrganizationId), Value = value.Encrypt(cipher.OrganizationId), Type = FieldType.Boolean }); diff --git a/src/UWP.Images/UWP.Images.projitems b/src/UWP.Images/UWP.Images.projitems index 8b39eb181..b62873882 100644 --- a/src/UWP.Images/UWP.Images.projitems +++ b/src/UWP.Images/UWP.Images.projitems @@ -56,4 +56,7 @@ + + + \ No newline at end of file diff --git a/src/UWP.Images/cog_alt.png b/src/UWP.Images/cog_alt.png new file mode 100644 index 0000000000000000000000000000000000000000..de8375761c80f708269e6329f7ebc61850957fbf GIT binary patch literal 738 zcmeAS@N?(olHy`uVBq!ia0vp^iXhCv3?vh*jA9uW7`X#{LR^7do8CR62p9sBR5QK+ zgCn9O$S;_Ik%^gwm6KaQNLXA-R!%`tO;bx-&&1Ts+{)J3#m(J2FeoxPJtH%}w4%DM zwXLJGyRU!Z^ck~eFIu)@)!I#4x9{4s@8IF1$4{I&ck|ApXD?p9e*6C8=bwKA)pni( z2ECrAi(`m{Wa+{7FkwfAwu||~EgXVA9jrX6O-c(c^|l6-8B9!KVTascU2xt&*}_ex!YI;Q}>vMzwmqAdg*_{o-1ovc_oAn^T#+4^``*%J_w^IQQ-85|Jvc&CVOv6zP9_)wQF#t9a!M z#&gw2OFnE%t@WGwd!u^x+yrl_eGTD7^Bk=wn^h#dO<|Il9?ZB*&uYqvl)s933a_;b h-(HcJeD2c)TQ`|AVs1J)V!+s8@O1TaS?83{1OTnWQyKsO literal 0 HcmV?d00001