From 95c07334d7ca607be43f6b778eecd3df384bdd86 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 8 Jun 2019 12:18:49 -0400 Subject: [PATCH] website icons enabled property --- .../Renderers/CipherViewCellRenderer.cs | 36 ++++++++++++------- .../CipherViewCell/CipherViewCell.xaml.cs | 9 ++++- src/App/Pages/Vault/AutofillCiphersPage.xaml | 3 +- .../Vault/AutofillCiphersPageViewModel.cs | 10 ++++++ src/App/Pages/Vault/CiphersPage.xaml | 4 ++- src/App/Pages/Vault/CiphersPage.xaml.cs | 3 +- src/App/Pages/Vault/CiphersPageViewModel.cs | 16 +++++++++ .../Vault/GroupingsPage/GroupingsPage.xaml | 3 +- .../GroupingsPage/GroupingsPageViewModel.cs | 11 ++++++ 9 files changed, 77 insertions(+), 18 deletions(-) diff --git a/src/Android/Renderers/CipherViewCellRenderer.cs b/src/Android/Renderers/CipherViewCellRenderer.cs index 4af046545..a6cbab6c2 100644 --- a/src/Android/Renderers/CipherViewCellRenderer.cs +++ b/src/Android/Renderers/CipherViewCellRenderer.cs @@ -60,6 +60,10 @@ namespace Bit.Droid.Renderers { _cell.UpdateCell(cipherCell); } + else if(e.PropertyName == CipherViewCell.WebsiteIconsEnabledProperty.PropertyName) + { + _cell.UpdateIconImage(cipherCell); + } } } @@ -105,6 +109,25 @@ namespace Bit.Droid.Renderers public Android.Widget.Button MoreButton { get; set; } public void UpdateCell(CipherViewCell cipherCell) + { + UpdateIconImage(cipherCell); + + var cipher = cipherCell.Cipher; + Name.Text = cipher.Name; + if(!string.IsNullOrWhiteSpace(cipher.SubTitle)) + { + SubTitle.Text = cipher.SubTitle; + SubTitle.Visibility = ViewStates.Visible; + } + else + { + SubTitle.Visibility = ViewStates.Gone; + } + SharedIcon.Visibility = cipher.Shared ? ViewStates.Visible : ViewStates.Gone; + AttachmentsIcon.Visibility = cipher.HasAttachments ? ViewStates.Visible : ViewStates.Gone; + } + + public void UpdateIconImage(CipherViewCell cipherCell) { if(_currentTask != null && !_currentTask.IsCancelled && !_currentTask.IsCompleted) { @@ -128,19 +151,6 @@ namespace Bit.Droid.Renderers Icon.Visibility = ViewStates.Visible; Icon.Text = iconImage.Item1; } - - Name.Text = cipher.Name; - if(!string.IsNullOrWhiteSpace(cipher.SubTitle)) - { - SubTitle.Text = cipher.SubTitle; - SubTitle.Visibility = ViewStates.Visible; - } - else - { - SubTitle.Visibility = ViewStates.Gone; - } - SharedIcon.Visibility = cipher.Shared ? ViewStates.Visible : ViewStates.Gone; - AttachmentsIcon.Visibility = cipher.HasAttachments ? ViewStates.Visible : ViewStates.Gone; } } diff --git a/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs b/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs index 7503a4a8e..8dc186b17 100644 --- a/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs +++ b/src/App/Controls/CipherViewCell/CipherViewCell.xaml.cs @@ -14,6 +14,9 @@ namespace Bit.App.Controls public static readonly BindableProperty CipherProperty = BindableProperty.Create( nameof(Cipher), typeof(CipherView), typeof(CipherViewCell), default(CipherView), BindingMode.OneWay); + public static readonly BindableProperty WebsiteIconsEnabledProperty = BindableProperty.Create( + nameof(WebsiteIconsEnabled), typeof(bool), typeof(CipherViewCell), true, BindingMode.OneWay); + public static readonly BindableProperty ButtonCommandProperty = BindableProperty.Create( nameof(ButtonCommand), typeof(Command), typeof(CipherViewCell)); @@ -36,7 +39,11 @@ namespace Bit.App.Controls } } - public bool WebsiteIconsEnabled { get; set; } = true; + public bool WebsiteIconsEnabled + { + get => (bool)GetValue(WebsiteIconsEnabledProperty); + set => SetValue(WebsiteIconsEnabledProperty, value); + } public CipherView Cipher { diff --git a/src/App/Pages/Vault/AutofillCiphersPage.xaml b/src/App/Pages/Vault/AutofillCiphersPage.xaml index 1cce91ac7..95c4f879d 100644 --- a/src/App/Pages/Vault/AutofillCiphersPage.xaml +++ b/src/App/Pages/Vault/AutofillCiphersPage.xaml @@ -26,7 +26,8 @@ x:DataType="pages:GroupingsPageListItem"> + ButtonCommand="{Binding BindingContext.CipherOptionsCommand, Source={x:Reference _page}}" + WebsiteIconsEnabled="{Binding BindingContext.WebsiteIconsEnabled, Source={x:Reference _page}}" /> ("platformUtilsService"); _cipherService = ServiceContainer.Resolve("cipherService"); _deviceActionService = ServiceContainer.Resolve("deviceActionService"); + _stateService = ServiceContainer.Resolve("stateService"); GroupedItems = new ExtendedObservableCollection(); CipherOptionsCommand = new Command(CipherOptionsAsync); @@ -53,6 +56,11 @@ namespace Bit.App.Pages get => _noDataText; set => SetProperty(ref _noDataText, value); } + public bool WebsiteIconsEnabled + { + get => _websiteIconsEnabled; + set => SetProperty(ref _websiteIconsEnabled, value); + } public void Init(AppOptions appOptions) { @@ -78,6 +86,8 @@ namespace Bit.App.Pages public async Task LoadAsync() { + WebsiteIconsEnabled = !(await _stateService.GetAsync(Constants.DisableFaviconKey)) + .GetValueOrDefault(); ShowList = false; var groupedItems = new List(); var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(Uri, null); diff --git a/src/App/Pages/Vault/CiphersPage.xaml b/src/App/Pages/Vault/CiphersPage.xaml index 2040e8ca0..eb12cebf5 100644 --- a/src/App/Pages/Vault/CiphersPage.xaml +++ b/src/App/Pages/Vault/CiphersPage.xaml @@ -69,7 +69,9 @@ + ButtonCommand="{Binding BindingContext.CipherOptionsCommand, Source={x:Reference _page}}" + WebsiteIconsEnabled="{Binding BindingContext.WebsiteIconsEnabled, Source={x:Reference _page}}" + /> diff --git a/src/App/Pages/Vault/CiphersPage.xaml.cs b/src/App/Pages/Vault/CiphersPage.xaml.cs index 14f0eb61e..15a9143b2 100644 --- a/src/App/Pages/Vault/CiphersPage.xaml.cs +++ b/src/App/Pages/Vault/CiphersPage.xaml.cs @@ -45,9 +45,10 @@ namespace Bit.App.Pages public SearchBar SearchBar => _searchBar; - protected override void OnAppearing() + protected async override void OnAppearing() { base.OnAppearing(); + await _vm.InitAsync(); if(!_hasFocused) { _hasFocused = true; diff --git a/src/App/Pages/Vault/CiphersPageViewModel.cs b/src/App/Pages/Vault/CiphersPageViewModel.cs index d144a2305..bce8d2ab0 100644 --- a/src/App/Pages/Vault/CiphersPageViewModel.cs +++ b/src/App/Pages/Vault/CiphersPageViewModel.cs @@ -1,5 +1,6 @@ using Bit.App.Abstractions; using Bit.App.Resources; +using Bit.Core; using Bit.Core.Abstractions; using Bit.Core.Enums; using Bit.Core.Exceptions; @@ -20,10 +21,12 @@ namespace Bit.App.Pages private readonly ICipherService _cipherService; private readonly ISearchService _searchService; private readonly IDeviceActionService _deviceActionService; + private readonly IStateService _stateService; private CancellationTokenSource _searchCancellationTokenSource; private bool _showNoData; private bool _showList; + private bool _websiteIconsEnabled; public CiphersPageViewModel() { @@ -31,6 +34,7 @@ namespace Bit.App.Pages _cipherService = ServiceContainer.Resolve("cipherService"); _searchService = ServiceContainer.Resolve("searchService"); _deviceActionService = ServiceContainer.Resolve("deviceActionService"); + _stateService = ServiceContainer.Resolve("stateService"); Ciphers = new ExtendedObservableCollection(); CipherOptionsCommand = new Command(CipherOptionsAsync); @@ -61,6 +65,18 @@ namespace Bit.App.Pages public bool ShowSearchDirection => !ShowList && !ShowNoData; + public bool WebsiteIconsEnabled + { + get => _websiteIconsEnabled; + set => SetProperty(ref _websiteIconsEnabled, value); + } + + public async Task InitAsync() + { + WebsiteIconsEnabled = !(await _stateService.GetAsync(Constants.DisableFaviconKey)) + .GetValueOrDefault(); + } + public void Search(string searchText, int? timeout = null) { var previousCts = _searchCancellationTokenSource; diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml index c33a47e9f..c7a312f2a 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml @@ -33,7 +33,8 @@ x:DataType="pages:GroupingsPageListItem"> + ButtonCommand="{Binding BindingContext.CipherOptionsCommand, Source={x:Reference _page}}" + WebsiteIconsEnabled="{Binding BindingContext.WebsiteIconsEnabled, Source={x:Reference _page}}" /> _allCiphers; private Dictionary _folderCounts = new Dictionary(); @@ -38,6 +40,7 @@ namespace Bit.App.Pages private readonly IDeviceActionService _deviceActionService; private readonly IPlatformUtilsService _platformUtilsService; private readonly IMessagingService _messagingService; + private readonly IStateService _stateService; public GroupingsPageViewModel() { @@ -48,6 +51,7 @@ namespace Bit.App.Pages _deviceActionService = ServiceContainer.Resolve("deviceActionService"); _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); _messagingService = ServiceContainer.Resolve("messagingService"); + _stateService = ServiceContainer.Resolve("stateService"); Loading = true; PageTitle = AppResources.MyVault; @@ -114,6 +118,11 @@ namespace Bit.App.Pages get => _showList; set => SetProperty(ref _showList, value); } + public bool WebsiteIconsEnabled + { + get => _websiteIconsEnabled; + set => SetProperty(ref _websiteIconsEnabled, value); + } public ExtendedObservableCollection GroupedItems { get; set; } public Command RefreshCommand { get; set; } public Command CipherOptionsCommand { get; set; } @@ -132,6 +141,8 @@ namespace Bit.App.Pages var groupedItems = new List(); var page = Page as GroupingsPage; + WebsiteIconsEnabled = !(await _stateService.GetAsync(Constants.DisableFaviconKey)) + .GetValueOrDefault(); try { await LoadDataAsync();