From 3799eb460337b6377bb288fb94abc79f2dd6f46d Mon Sep 17 00:00:00 2001 From: Matt Portune <59324545+mportune-bw@users.noreply.github.com> Date: Thu, 18 Feb 2021 16:58:20 -0500 Subject: [PATCH] Support for Disable Send policy (#1271) * add support for disable send policy * cleanup * show/hide options support for send search results * additional failsafes and copy function consolidation * added missing disabled send icon to android renderer * async fix and string updates --- src/Android/Renderers/SendViewCellRenderer.cs | 11 ++++ .../Resources/layout/SendViewCell.axml | 8 +++ .../Controls/SendViewCell/SendViewCell.xaml | 1 + .../SendViewCell/SendViewCell.xaml.cs | 13 +++++ .../SendViewCell/SendViewCellViewModel.cs | 7 +++ src/App/Pages/Send/SendAddEditPage.xaml | 33 +++++++++++- src/App/Pages/Send/SendAddEditPage.xaml.cs | 34 ++++++++---- .../Pages/Send/SendAddEditPageViewModel.cs | 27 ++++++---- .../SendGroupingsPage/SendGroupingsPage.xaml | 18 ++++++- .../SendGroupingsPage.xaml.cs | 9 +++- .../SendGroupingsPageListItem.cs | 1 + .../SendGroupingsPageViewModel.cs | 17 +++++- src/App/Pages/Send/SendsPage.xaml | 3 +- src/App/Pages/Send/SendsPageViewModel.cs | 8 +++ src/App/Resources/AppResources.Designer.cs | 12 +++++ src/App/Resources/AppResources.resx | 10 +++- src/App/Utilities/AppHelpers.cs | 52 ++++++++++++++++--- src/Core/Enums/PolicyType.cs | 13 ++--- 18 files changed, 235 insertions(+), 42 deletions(-) diff --git a/src/Android/Renderers/SendViewCellRenderer.cs b/src/Android/Renderers/SendViewCellRenderer.cs index 4842c37af..5363bd374 100644 --- a/src/Android/Renderers/SendViewCellRenderer.cs +++ b/src/Android/Renderers/SendViewCellRenderer.cs @@ -102,6 +102,7 @@ namespace Bit.Droid.Renderers Icon = view.FindViewById(Resource.Id.SendCellIcon); Name = view.FindViewById(Resource.Id.SendCellName); SubTitle = view.FindViewById(Resource.Id.SendCellSubTitle); + DisabledIcon = view.FindViewById(Resource.Id.SendCellDisabledIcon); HasPasswordIcon = view.FindViewById(Resource.Id.SendCellHasPasswordIcon); MaxAccessCountReachedIcon = view.FindViewById(Resource.Id.SendCellMaxAccessCountReachedIcon); ExpiredIcon = view.FindViewById(Resource.Id.SendCellExpiredIcon); @@ -110,6 +111,7 @@ namespace Bit.Droid.Renderers MoreButton.Click += MoreButton_Click; Icon.Typeface = _faTypeface; + DisabledIcon.Typeface = _faTypeface; HasPasswordIcon.Typeface = _faTypeface; MaxAccessCountReachedIcon.Typeface = _faTypeface; ExpiredIcon.Typeface = _faTypeface; @@ -120,12 +122,18 @@ namespace Bit.Droid.Renderers Icon.SetTextSize(ComplexUnitType.Pt, 10); Name.SetTextSize(ComplexUnitType.Sp, (float)Device.GetNamedSize(NamedSize.Medium, typeof(Label))); SubTitle.SetTextSize(ComplexUnitType.Sp, small); + DisabledIcon.SetTextSize(ComplexUnitType.Sp, small); HasPasswordIcon.SetTextSize(ComplexUnitType.Sp, small); MaxAccessCountReachedIcon.SetTextSize(ComplexUnitType.Sp, small); ExpiredIcon.SetTextSize(ComplexUnitType.Sp, small); PendingDeleteIcon.SetTextSize(ComplexUnitType.Sp, small); MoreButton.SetTextSize(ComplexUnitType.Sp, 25); + if (!SendViewCell.ShowOptions) + { + MoreButton.Visibility = ViewStates.Gone; + } + AddView(view); } @@ -135,6 +143,7 @@ namespace Bit.Droid.Renderers public TextView Icon { get; set; } public TextView Name { get; set; } public TextView SubTitle { get; set; } + public TextView DisabledIcon { get; set; } public TextView HasPasswordIcon { get; set; } public TextView MaxAccessCountReachedIcon { get; set; } public TextView ExpiredIcon { get; set; } @@ -148,6 +157,7 @@ namespace Bit.Droid.Renderers var send = sendCell.Send; Name.Text = send.Name; SubTitle.Text = send.DisplayDate; + DisabledIcon.Visibility = send.Disabled ? ViewStates.Visible : ViewStates.Gone; HasPasswordIcon.Visibility = send.HasPassword ? ViewStates.Visible : ViewStates.Gone; MaxAccessCountReachedIcon.Visibility = send.MaxAccessCountReached ? ViewStates.Visible : ViewStates.Gone; ExpiredIcon.Visibility = send.Expired ? ViewStates.Visible : ViewStates.Gone; @@ -172,6 +182,7 @@ namespace Bit.Droid.Renderers Name.SetTextColor(textColor); SubTitle.SetTextColor(mutedColor); Icon.SetTextColor(mutedColor); + DisabledIcon.SetTextColor(mutedColor); HasPasswordIcon.SetTextColor(mutedColor); MaxAccessCountReachedIcon.SetTextColor(mutedColor); ExpiredIcon.SetTextColor(mutedColor); diff --git a/src/Android/Resources/layout/SendViewCell.axml b/src/Android/Resources/layout/SendViewCell.axml index 1e7d62d00..9565cf19e 100644 --- a/src/Android/Resources/layout/SendViewCell.axml +++ b/src/Android/Resources/layout/SendViewCell.axml @@ -43,6 +43,14 @@ android:singleLine="true" android:ellipsize="end" android:text="Name" /> + ), typeof(SendViewCell)); + + public static readonly BindableProperty ShowOptionsProperty = BindableProperty.Create( + nameof(ShowOptions), typeof(bool), typeof(SendViewCell)); private readonly IEnvironmentService _environmentService; @@ -47,6 +50,12 @@ namespace Bit.App.Controls set => SetValue(ButtonCommandProperty, value); } + public bool ShowOptions + { + get => GetValue(ShowOptionsProperty) is bool && (bool)GetValue(ShowOptionsProperty); + set => SetValue(ShowOptionsProperty, value); + } + protected override void OnPropertyChanged(string propertyName = null) { base.OnPropertyChanged(propertyName); @@ -58,6 +67,10 @@ namespace Bit.App.Controls { _viewModel.Send = Send; } + else if (propertyName == ShowOptionsProperty.PropertyName) + { + _viewModel.ShowOptions = ShowOptions; + } } protected override void OnBindingContextChanged() diff --git a/src/App/Controls/SendViewCell/SendViewCellViewModel.cs b/src/App/Controls/SendViewCell/SendViewCellViewModel.cs index 0a9ce452b..3f10447ce 100644 --- a/src/App/Controls/SendViewCell/SendViewCellViewModel.cs +++ b/src/App/Controls/SendViewCell/SendViewCellViewModel.cs @@ -6,11 +6,18 @@ namespace Bit.App.Controls public class SendViewCellViewModel : ExtendedViewModel { private SendView _send; + private bool _showOptions; public SendView Send { get => _send; set => SetProperty(ref _send, value); } + + public bool ShowOptions + { + get => _showOptions; + set => SetProperty(ref _showOptions, value); + } } } diff --git a/src/App/Pages/Send/SendAddEditPage.xaml b/src/App/Pages/Send/SendAddEditPage.xaml index 2a712e573..4f5b9cb34 100644 --- a/src/App/Pages/Send/SendAddEditPage.xaml +++ b/src/App/Pages/Send/SendAddEditPage.xaml @@ -14,7 +14,8 @@ - + @@ -76,6 +77,18 @@ + +