1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-10-02 04:37:50 +02:00
bitwarden-mobile/src/App/Controls/VaultListViewCell.cs

85 lines
3.3 KiB
C#
Raw Normal View History

2017-01-31 01:26:39 +01:00
using Bit.App.Models.Page;
using System;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class VaultListViewCell : LabeledDetailCell
{
public static readonly BindableProperty CipherParameterProperty = BindableProperty.Create(nameof(CipherParameter),
typeof(VaultListPageModel.Cipher), typeof(VaultListViewCell), null);
2017-12-20 05:59:12 +01:00
public static readonly BindableProperty GroupingOrCipherParameterProperty =
BindableProperty.Create(nameof(GroupingOrCipherParameter), typeof(VaultListPageModel.GroupingOrCipher),
typeof(VaultListViewCell), null);
2017-01-31 01:26:39 +01:00
2017-12-20 05:59:12 +01:00
public VaultListViewCell(Action<VaultListPageModel.Cipher> moreClickedAction, bool groupingOrCipherBinding = false)
2017-01-31 01:26:39 +01:00
{
2017-12-20 05:59:12 +01:00
string bindingPrefix = null;
if(groupingOrCipherBinding)
{
SetBinding(GroupingOrCipherParameterProperty, new Binding("."));
bindingPrefix = string.Concat(nameof(VaultListPageModel.GroupingOrCipher.Cipher), ".");
Button.Command = new Command(() => moreClickedAction?.Invoke(GroupingOrCipherParameter?.Cipher));
}
else
{
SetBinding(CipherParameterProperty, new Binding("."));
Button.Command = new Command(() => moreClickedAction?.Invoke(CipherParameter));
}
Label.SetBinding(Label.TextProperty, bindingPrefix + nameof(VaultListPageModel.Cipher.Name));
Detail.SetBinding(Label.TextProperty, bindingPrefix + nameof(VaultListPageModel.Cipher.Subtitle));
LabelIcon.SetBinding(VisualElement.IsVisibleProperty,
bindingPrefix + nameof(VaultListPageModel.Cipher.Shared));
LabelIcon2.SetBinding(VisualElement.IsVisibleProperty,
bindingPrefix + nameof(VaultListPageModel.Cipher.HasAttachments));
2017-01-31 01:26:39 +01:00
2017-10-20 19:03:04 +02:00
Button.Image = "more.png";
2017-01-31 01:26:39 +01:00
Button.BackgroundColor = Color.Transparent;
2017-10-20 19:03:04 +02:00
LabelIcon.Source = "share.png";
LabelIcon2.Source = "paperclip.png";
2017-04-24 21:00:55 +02:00
2017-01-31 01:26:39 +01:00
BackgroundColor = Color.White;
}
public VaultListPageModel.Cipher CipherParameter
2017-01-31 01:26:39 +01:00
{
get { return GetValue(CipherParameterProperty) as VaultListPageModel.Cipher; }
set { SetValue(CipherParameterProperty, value); }
}
2017-12-20 05:59:12 +01:00
public VaultListPageModel.GroupingOrCipher GroupingOrCipherParameter
{
get { return GetValue(GroupingOrCipherParameterProperty) as VaultListPageModel.GroupingOrCipher; }
set { SetValue(GroupingOrCipherParameterProperty, value); }
}
protected override void OnBindingContextChanged()
{
Icon.Source = null;
2017-12-20 05:59:12 +01:00
VaultListPageModel.Cipher cipher = null;
if(BindingContext is VaultListPageModel.Cipher item)
{
2017-12-20 05:59:12 +01:00
cipher = item;
}
else if(BindingContext is VaultListPageModel.GroupingOrCipher groupingOrCipherItem)
{
cipher = groupingOrCipherItem.Cipher;
}
if(cipher != null)
{
if(cipher.Type == Enums.CipherType.Login)
{
Icon.LoadingPlaceholder = "login.png";
}
2017-12-20 05:59:12 +01:00
Icon.Source = cipher.Icon;
}
base.OnBindingContextChanged();
2017-01-31 01:26:39 +01:00
}
}
}