bitwarden-android/src/App/Controls/LabeledValueCell.cs

101 lines
3.1 KiB
C#
Raw Normal View History

using Xamarin.Forms;
namespace Bit.App.Controls
{
public class LabeledValueCell : ExtendedViewCell
{
public LabeledValueCell(
string labelText = null,
string valueText = null,
string button1Text = null,
string button2Text = null)
{
2016-05-17 06:54:24 +03:00
var containerStackLayout = new StackLayout
{
Padding = new Thickness(15, 10),
2016-05-17 06:54:24 +03:00
Orientation = StackOrientation.Horizontal
};
var labelValueStackLayout = new StackLayout
{
HorizontalOptions = LayoutOptions.StartAndExpand,
2016-08-14 07:54:07 +03:00
VerticalOptions = LayoutOptions.CenterAndExpand
};
if(labelText != null)
{
Label = new Label
{
Text = labelText,
2016-06-28 03:56:59 +03:00
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
2016-08-14 07:54:07 +03:00
Style = (Style)Application.Current.Resources["text-muted"]
};
2016-08-14 07:54:07 +03:00
if(Device.OS == TargetPlatform.Android)
{
Label.FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label));
}
2016-05-17 06:54:24 +03:00
labelValueStackLayout.Children.Add(Label);
}
Value = new Label
{
Text = valueText,
FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)),
2016-08-14 07:54:07 +03:00
LineBreakMode = LineBreakMode.TailTruncation
};
2016-08-14 07:54:07 +03:00
if(Device.OS == TargetPlatform.Android)
{
Value.TextColor = Color.Black;
}
2016-05-17 06:54:24 +03:00
labelValueStackLayout.Children.Add(Value);
containerStackLayout.Children.Add(labelValueStackLayout);
var buttonStackLayout = new StackLayout
{
2016-08-14 07:54:07 +03:00
Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.CenterAndExpand
};
if(button1Text != null)
{
Button1 = new Button
{
Text = button1Text,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
2016-06-17 07:01:25 +03:00
Margin = new Thickness(0)
};
2016-05-17 06:54:24 +03:00
buttonStackLayout.Children.Add(Button1);
}
if(button2Text != null)
{
Button2 = new Button
{
Text = button2Text,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
2016-06-17 07:01:25 +03:00
Margin = new Thickness(0)
};
2016-05-17 06:54:24 +03:00
buttonStackLayout.Children.Add(Button2);
}
2016-05-17 06:54:24 +03:00
containerStackLayout.Children.Add(buttonStackLayout);
2016-05-17 06:54:24 +03:00
View = containerStackLayout;
}
public Label Label { get; private set; }
public Label Value { get; private set; }
public Button Button1 { get; private set; }
public Button Button2 { get; private set; }
}
}