2016-08-24 06:15:28 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
2017-02-16 05:56:02 +03:00
|
|
|
|
using FFImageLoading.Forms;
|
2016-08-24 06:15:28 +03:00
|
|
|
|
using System;
|
2016-05-24 04:56:38 +03:00
|
|
|
|
using Xamarin.Forms;
|
2016-08-24 06:15:28 +03:00
|
|
|
|
using XLabs.Ioc;
|
2016-05-13 07:11:32 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Controls
|
|
|
|
|
{
|
2017-02-15 08:28:05 +03:00
|
|
|
|
public class FormEntryCell : ExtendedViewCell, IDisposable
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2017-02-15 08:28:05 +03:00
|
|
|
|
private VisualElement _nextElement;
|
|
|
|
|
private TapGestureRecognizer _tgr;
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
public FormEntryCell(
|
|
|
|
|
string labelText,
|
|
|
|
|
Keyboard entryKeyboard = null,
|
2016-11-09 05:29:24 +03:00
|
|
|
|
bool isPassword = false,
|
2016-06-28 05:17:49 +03:00
|
|
|
|
VisualElement nextElement = null,
|
|
|
|
|
bool useLabelAsPlaceholder = false,
|
2016-07-03 07:27:10 +03:00
|
|
|
|
string imageSource = null,
|
2016-11-08 06:07:33 +03:00
|
|
|
|
Thickness? containerPadding = null,
|
|
|
|
|
bool useButton = false)
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2017-02-15 08:28:05 +03:00
|
|
|
|
_nextElement = nextElement;
|
|
|
|
|
|
2016-06-28 03:56:59 +03:00
|
|
|
|
if(!useLabelAsPlaceholder)
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2016-06-28 03:56:59 +03:00
|
|
|
|
Label = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = labelText,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
|
2016-06-28 05:17:49 +03:00
|
|
|
|
Style = (Style)Application.Current.Resources["text-muted"],
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand
|
2016-06-28 03:56:59 +03:00
|
|
|
|
};
|
|
|
|
|
}
|
2016-05-13 07:11:32 +03:00
|
|
|
|
|
|
|
|
|
Entry = new ExtendedEntry
|
|
|
|
|
{
|
|
|
|
|
Keyboard = entryKeyboard,
|
2016-05-17 06:54:24 +03:00
|
|
|
|
HasBorder = false,
|
2016-11-09 05:29:24 +03:00
|
|
|
|
IsPassword = isPassword,
|
2016-06-28 05:17:49 +03:00
|
|
|
|
AllowClear = true,
|
2016-08-23 01:59:15 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
2016-11-08 08:02:43 +03:00
|
|
|
|
WidthRequest = 1,
|
2016-08-23 01:59:15 +03:00
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Entry))
|
2016-05-13 07:11:32 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-28 03:56:59 +03:00
|
|
|
|
if(useLabelAsPlaceholder)
|
|
|
|
|
{
|
|
|
|
|
Entry.Placeholder = labelText;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-24 04:56:38 +03:00
|
|
|
|
if(nextElement != null)
|
|
|
|
|
{
|
|
|
|
|
Entry.ReturnType = Enums.ReturnType.Next;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
var imageStackLayout = new StackLayout
|
2016-05-13 07:11:32 +03:00
|
|
|
|
{
|
2016-07-03 07:27:10 +03:00
|
|
|
|
Padding = containerPadding ?? new Thickness(15, 10),
|
2016-06-28 05:17:49 +03:00
|
|
|
|
Orientation = StackOrientation.Horizontal,
|
|
|
|
|
Spacing = 10,
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand
|
2016-05-13 07:11:32 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
if(imageSource != null)
|
|
|
|
|
{
|
2017-02-15 08:28:05 +03:00
|
|
|
|
_tgr = new TapGestureRecognizer();
|
2016-06-28 05:17:49 +03:00
|
|
|
|
|
2017-02-16 05:56:02 +03:00
|
|
|
|
var theImage = new CachedImage
|
2016-06-28 05:17:49 +03:00
|
|
|
|
{
|
|
|
|
|
Source = imageSource,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Start,
|
2017-02-16 05:56:02 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Center,
|
|
|
|
|
WidthRequest = 18,
|
|
|
|
|
HeightRequest = 18
|
2016-06-28 05:17:49 +03:00
|
|
|
|
};
|
2017-02-15 08:28:05 +03:00
|
|
|
|
theImage.GestureRecognizers.Add(_tgr);
|
2016-06-28 05:17:49 +03:00
|
|
|
|
|
|
|
|
|
imageStackLayout.Children.Add(theImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var formStackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
2016-08-14 07:54:07 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand
|
2016-06-28 05:17:49 +03:00
|
|
|
|
};
|
2016-08-14 07:54:07 +03:00
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.Android)
|
2016-08-14 07:54:07 +03:00
|
|
|
|
{
|
2016-08-24 06:15:28 +03:00
|
|
|
|
var deviceInfo = Resolver.Resolve<IDeviceInfoService>();
|
|
|
|
|
if(useLabelAsPlaceholder)
|
2016-08-17 07:39:42 +03:00
|
|
|
|
{
|
2016-08-24 06:57:11 +03:00
|
|
|
|
if(deviceInfo.Version < 21)
|
|
|
|
|
{
|
2016-08-26 04:43:47 +03:00
|
|
|
|
Entry.Margin = new Thickness(-9, 1, -9, 0);
|
2016-08-24 06:57:11 +03:00
|
|
|
|
}
|
|
|
|
|
else if(deviceInfo.Version == 21)
|
2016-08-24 06:15:28 +03:00
|
|
|
|
{
|
|
|
|
|
Entry.Margin = new Thickness(0, 4, 0, -4);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-08-24 06:57:11 +03:00
|
|
|
|
Entry.AdjustMarginsForDevice();
|
2016-08-17 07:39:42 +03:00
|
|
|
|
}
|
2016-08-26 04:43:47 +03:00
|
|
|
|
|
|
|
|
|
if(containerPadding == null)
|
|
|
|
|
{
|
|
|
|
|
imageStackLayout.AdjustPaddingForDevice();
|
|
|
|
|
}
|
2016-08-14 07:54:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 03:56:59 +03:00
|
|
|
|
if(!useLabelAsPlaceholder)
|
|
|
|
|
{
|
2016-06-28 05:17:49 +03:00
|
|
|
|
formStackLayout.Children.Add(Label);
|
2016-06-28 03:56:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
formStackLayout.Children.Add(Entry);
|
|
|
|
|
imageStackLayout.Children.Add(formStackLayout);
|
2016-05-13 07:11:32 +03:00
|
|
|
|
|
2016-11-08 06:07:33 +03:00
|
|
|
|
if(useButton)
|
|
|
|
|
{
|
|
|
|
|
Button = new ExtendedButton();
|
|
|
|
|
imageStackLayout.Children.Add(Button);
|
2016-11-08 07:45:46 +03:00
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.Android)
|
2016-11-08 07:45:46 +03:00
|
|
|
|
{
|
|
|
|
|
Button.Padding = new Thickness(0);
|
|
|
|
|
Button.BackgroundColor = Color.Transparent;
|
|
|
|
|
}
|
2016-11-08 06:07:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
View = imageStackLayout;
|
2016-05-13 07:11:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Label Label { get; private set; }
|
|
|
|
|
public ExtendedEntry Entry { get; private set; }
|
2016-11-08 06:07:33 +03:00
|
|
|
|
public ExtendedButton Button { get; private set; }
|
2016-06-28 05:17:49 +03:00
|
|
|
|
|
2017-02-15 08:28:05 +03:00
|
|
|
|
public void InitEvents()
|
|
|
|
|
{
|
|
|
|
|
if(_nextElement != null)
|
|
|
|
|
{
|
|
|
|
|
Entry.Completed += Entry_Completed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_tgr != null)
|
|
|
|
|
{
|
|
|
|
|
_tgr.Tapped += Tgr_Tapped;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tapped += FormEntryCell_Tapped;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 05:17:49 +03:00
|
|
|
|
private void Tgr_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Entry.Focus();
|
|
|
|
|
}
|
2016-07-05 05:35:49 +03:00
|
|
|
|
|
|
|
|
|
private void FormEntryCell_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Entry.Focus();
|
|
|
|
|
}
|
2017-02-15 08:28:05 +03:00
|
|
|
|
|
|
|
|
|
private void Entry_Completed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_nextElement?.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if(_tgr != null)
|
|
|
|
|
{
|
|
|
|
|
_tgr.Tapped -= Tgr_Tapped;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tapped -= FormEntryCell_Tapped;
|
|
|
|
|
Entry.Completed -= Entry_Completed;
|
|
|
|
|
}
|
2016-05-13 07:11:32 +03:00
|
|
|
|
}
|
|
|
|
|
}
|