bitwarden-mobile/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.Windows.Input;
using Bit.App.Abstractions;
2019-04-22 23:08:37 +02:00
using Bit.Core.Models.View;
using Bit.Core.Utilities;
2019-03-29 21:52:57 +01:00
using Xamarin.Forms;
namespace Bit.App.Controls
{
public partial class CipherViewCell : ExtendedGrid
2019-03-29 21:52:57 +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(
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(ICommand), typeof(CipherViewCell));
2019-04-30 17:27:53 +02:00
2019-03-29 21:52:57 +01:00
public CipherViewCell()
{
InitializeComponent();
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
}
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);
}
public ICommand ButtonCommand
2019-04-30 17:27:53 +02:00
{
get => GetValue(ButtonCommandProperty) as ICommand;
2019-04-30 17:27:53 +02:00
set => SetValue(ButtonCommandProperty, value);
}
2019-03-29 21:52:57 +01:00
protected override void OnPropertyChanged(string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == CipherProperty.PropertyName)
2019-03-29 21:52:57 +01:00
{
if (Cipher == null)
2019-04-22 23:08:37 +02:00
{
return;
2019-04-22 23:08:37 +02:00
}
BindingContext = new CipherViewCellViewModel(Cipher, WebsiteIconsEnabled ?? false);
2019-04-22 23:08:37 +02:00
}
else if (propertyName == WebsiteIconsEnabledProperty.PropertyName)
2019-06-08 17:48:45 +02:00
{
if (Cipher == null)
2019-04-22 23:08:37 +02:00
{
return;
2019-04-22 23:08:37 +02:00
}
((CipherViewCellViewModel)BindingContext).WebsiteIconsEnabled = WebsiteIconsEnabled ?? false;
2019-04-22 23:08:37 +02:00
}
}
2019-04-30 17:27:53 +02:00
private void MoreButton_Clicked(object sender, EventArgs e)
2019-04-30 17:27:53 +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
}
}