2021-05-13 20:36:20 +02:00
|
|
|
|
using System;
|
2022-02-17 23:34:22 +01:00
|
|
|
|
using Bit.App.Abstractions;
|
2019-04-22 23:08:37 +02:00
|
|
|
|
using Bit.Core.Models.View;
|
2022-02-17 23:34:22 +01:00
|
|
|
|
using Bit.Core.Utilities;
|
2019-03-29 21:52:57 +01:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Controls
|
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
public partial class CipherViewCell : ExtendedGrid
|
2019-03-29 21:52:57 +01:00
|
|
|
|
{
|
2022-02-22 16:33:38 +01:00
|
|
|
|
private const int ICON_COLUMN_DEFAULT_WIDTH = 40;
|
|
|
|
|
private const int ICON_IMAGE_DEFAULT_WIDTH = 22;
|
|
|
|
|
|
2019-03-29 21:52:57 +01:00
|
|
|
|
public static readonly BindableProperty CipherProperty = BindableProperty.Create(
|
|
|
|
|
nameof(Cipher), typeof(CipherView), typeof(CipherViewCell), default(CipherView), BindingMode.OneWay);
|
|
|
|
|
|
2019-06-08 18:18:49 +02:00
|
|
|
|
public static readonly BindableProperty WebsiteIconsEnabledProperty = BindableProperty.Create(
|
2021-05-13 20:36:20 +02:00
|
|
|
|
nameof(WebsiteIconsEnabled), typeof(bool?), typeof(CipherViewCell));
|
2019-06-08 18:18:49 +02:00
|
|
|
|
|
2019-04-30 17:27:53 +02:00
|
|
|
|
public static readonly BindableProperty ButtonCommandProperty = BindableProperty.Create(
|
|
|
|
|
nameof(ButtonCommand), typeof(Command<CipherView>), typeof(CipherViewCell));
|
|
|
|
|
|
2019-03-29 21:52:57 +01:00
|
|
|
|
public CipherViewCell()
|
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
InitializeComponent();
|
2022-02-17 23:34:22 +01:00
|
|
|
|
|
2022-02-22 16:33:38 +01:00
|
|
|
|
var fontScale = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService").GetSystemFontSizeScale();
|
|
|
|
|
_iconColumn.Width = new GridLength(ICON_COLUMN_DEFAULT_WIDTH * fontScale, GridUnitType.Absolute);
|
|
|
|
|
_iconImage.WidthRequest = ICON_IMAGE_DEFAULT_WIDTH * fontScale;
|
|
|
|
|
_iconImage.HeightRequest = ICON_IMAGE_DEFAULT_WIDTH * fontScale;
|
2019-03-29 21:52:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 20:36:20 +02:00
|
|
|
|
public bool? WebsiteIconsEnabled
|
2019-06-08 18:18:49 +02:00
|
|
|
|
{
|
|
|
|
|
get => (bool)GetValue(WebsiteIconsEnabledProperty);
|
|
|
|
|
set => SetValue(WebsiteIconsEnabledProperty, value);
|
|
|
|
|
}
|
2019-06-08 17:48:45 +02:00
|
|
|
|
|
2019-03-29 21:52:57 +01:00
|
|
|
|
public CipherView Cipher
|
|
|
|
|
{
|
|
|
|
|
get => GetValue(CipherProperty) as CipherView;
|
|
|
|
|
set => SetValue(CipherProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 17:27:53 +02:00
|
|
|
|
public Command<CipherView> ButtonCommand
|
|
|
|
|
{
|
|
|
|
|
get => GetValue(ButtonCommandProperty) as Command<CipherView>;
|
|
|
|
|
set => SetValue(ButtonCommandProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 21:52:57 +01:00
|
|
|
|
protected override void OnPropertyChanged(string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
base.OnPropertyChanged(propertyName);
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (propertyName == CipherProperty.PropertyName)
|
2019-03-29 21:52:57 +01:00
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
if (Cipher == null)
|
2019-04-22 23:08:37 +02:00
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
return;
|
2019-04-22 23:08:37 +02:00
|
|
|
|
}
|
2021-05-13 20:36:20 +02:00
|
|
|
|
BindingContext = new CipherViewCellViewModel(Cipher, WebsiteIconsEnabled ?? false);
|
2019-04-22 23:08:37 +02:00
|
|
|
|
}
|
2021-05-13 20:36:20 +02:00
|
|
|
|
else if (propertyName == WebsiteIconsEnabledProperty.PropertyName)
|
2019-06-08 17:48:45 +02:00
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
if (Cipher == null)
|
2019-04-22 23:08:37 +02:00
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
return;
|
2019-04-22 23:08:37 +02:00
|
|
|
|
}
|
2021-05-13 20:36:20 +02:00
|
|
|
|
((CipherViewCellViewModel)BindingContext).WebsiteIconsEnabled = WebsiteIconsEnabled ?? false;
|
2019-04-22 23:08:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-30 17:27:53 +02:00
|
|
|
|
|
2019-06-21 15:46:46 +02:00
|
|
|
|
private void MoreButton_Clicked(object sender, EventArgs e)
|
2019-04-30 17:27:53 +02:00
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
var cipher = ((sender as MiButton)?.BindingContext as CipherViewCellViewModel)?.Cipher;
|
|
|
|
|
if (cipher != null)
|
|
|
|
|
{
|
|
|
|
|
ButtonCommand?.Execute(cipher);
|
|
|
|
|
}
|
2019-04-30 17:27:53 +02:00
|
|
|
|
}
|
2019-03-29 21:52:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|