mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
switch cell for fields, btn widths on ios too
This commit is contained in:
parent
e08a0a0938
commit
c95251c903
7 changed files with 99 additions and 87 deletions
|
@ -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.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.VerticalOptions = LayoutOptions.FillAndExpand;
|
||||
}
|
||||
}
|
||||
|
||||
if(Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
if(_buttonStackLayout != null)
|
||||
{
|
||||
_buttonStackLayout.Spacing = 5;
|
||||
}
|
||||
|
||||
var deviceInfo = Resolver.Resolve<IDeviceInfoService>();
|
||||
if(useLabelAsPlaceholder)
|
||||
{
|
||||
|
|
47
src/App/Controls/FormSwitchCell.cs
Normal file
47
src/App/Controls/FormSwitchCell.cs
Normal 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; }
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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(() =>
|
||||
{
|
||||
|
|
|
@ -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<IDeviceActionService>();
|
||||
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
|
||||
});
|
||||
|
|
|
@ -56,4 +56,7 @@
|
|||
<Content Include="$(MSBuildThisFileDirectory)user.png" />
|
||||
<Content Include="$(MSBuildThisFileDirectory)yubikey.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="$(MSBuildThisFileDirectory)cog_alt.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
BIN
src/UWP.Images/cog_alt.png
Normal file
BIN
src/UWP.Images/cog_alt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 738 B |
Loading…
Reference in a new issue