From a1c853d7fc9dcfdb705436bdab4e53df13e1d04f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 29 Mar 2019 16:52:57 -0400 Subject: [PATCH] cipher view cell control --- src/App/App.csproj | 6 ++ .../CipherViewCell/CipherViewCell.xaml | 23 +++++ .../CipherViewCell/CipherViewCell.xaml.cs | 34 ++++++++ .../CipherViewCell/CipherViewCellViewModel.cs | 16 ++++ .../Pages/GroupingsPage/GroupingsPage.xaml | 84 ++++++++----------- src/Core/Utilities/ExtendedViewModel.cs | 13 +-- 6 files changed, 118 insertions(+), 58 deletions(-) create mode 100644 src/App/Controls/CipherViewCell/CipherViewCell.xaml create mode 100644 src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs create mode 100644 src/App/Controls/CipherViewCell/CipherViewCellViewModel.cs diff --git a/src/App/App.csproj b/src/App/App.csproj index 2649ac490..bd628bc3d 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -37,4 +37,10 @@ + + + + MSBuild:UpdateDesignTimeXaml + + \ No newline at end of file diff --git a/src/App/Controls/CipherViewCell/CipherViewCell.xaml b/src/App/Controls/CipherViewCell/CipherViewCell.xaml new file mode 100644 index 000000000..b560b7862 --- /dev/null +++ b/src/App/Controls/CipherViewCell/CipherViewCell.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs b/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs new file mode 100644 index 000000000..9a77b5ebb --- /dev/null +++ b/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs @@ -0,0 +1,34 @@ +using Bit.Core.Models.View; +using Xamarin.Forms; + +namespace Bit.App.Controls +{ + public partial class CipherViewCell : ViewCell + { + public static readonly BindableProperty CipherProperty = BindableProperty.Create( + nameof(Cipher), typeof(CipherView), typeof(CipherViewCell), default(CipherView), BindingMode.OneWay); + + private CipherViewCellViewModel _viewModel; + + public CipherViewCell() + { + InitializeComponent(); + _viewModel = _layout.BindingContext as CipherViewCellViewModel; + } + + public CipherView Cipher + { + get => GetValue(CipherProperty) as CipherView; + set => SetValue(CipherProperty, value); + } + + protected override void OnPropertyChanged(string propertyName = null) + { + base.OnPropertyChanged(propertyName); + if(propertyName == CipherProperty.PropertyName) + { + _viewModel.Cipher = Cipher; + } + } + } +} diff --git a/src/App/Controls/CipherViewCell/CipherViewCellViewModel.cs b/src/App/Controls/CipherViewCell/CipherViewCellViewModel.cs new file mode 100644 index 000000000..728b3591c --- /dev/null +++ b/src/App/Controls/CipherViewCell/CipherViewCellViewModel.cs @@ -0,0 +1,16 @@ +using Bit.Core.Models.View; +using Bit.Core.Utilities; + +namespace Bit.App.Controls +{ + public class CipherViewCellViewModel : ExtendedViewModel + { + private CipherView _cipher; + + public CipherView Cipher + { + get => _cipher; + set => SetProperty(ref _cipher, value); + } + } +} diff --git a/src/App/Pages/GroupingsPage/GroupingsPage.xaml b/src/App/Pages/GroupingsPage/GroupingsPage.xaml index b80c03b88..656ea2823 100644 --- a/src/App/Pages/GroupingsPage/GroupingsPage.xaml +++ b/src/App/Pages/GroupingsPage/GroupingsPage.xaml @@ -1,11 +1,11 @@  - + @@ -13,64 +13,50 @@ - + + + + + - - + - - - - - - - - - + - + diff --git a/src/Core/Utilities/ExtendedViewModel.cs b/src/Core/Utilities/ExtendedViewModel.cs index 35d5ab789..62ac8df1a 100644 --- a/src/Core/Utilities/ExtendedViewModel.cs +++ b/src/Core/Utilities/ExtendedViewModel.cs @@ -9,8 +9,8 @@ namespace Bit.Core.Utilities { public event PropertyChangedEventHandler PropertyChanged; - protected bool SetProperty(ref T backingStore, T value, [CallerMemberName]string propertyName = "", - Action onChanged = null) + protected bool SetProperty(ref T backingStore, T value, Action onChanged = null, + [CallerMemberName]string propertyName = "") { if(EqualityComparer.Default.Equals(backingStore, value)) { @@ -18,14 +18,9 @@ namespace Bit.Core.Utilities } backingStore = value; - onChanged?.Invoke(); - OnPropertyChanged(propertyName); - return true; - } - - protected void OnPropertyChanged([CallerMemberName] string propertyName = "") - { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + onChanged?.Invoke(); + return true; } } }