From 08f371b0dbbb5a67c907d3f0a817dfef20179b04 Mon Sep 17 00:00:00 2001 From: Dinis Vieira Date: Thu, 11 Apr 2024 13:14:45 +0100 Subject: [PATCH] [PM-7369] Show passkey icon on android when the item has a Fido2 credential (#3148) * PM-7369 Show passkey icon on android when the item has a Fido2 credential * PM-7369 alternative way to show passkey icon only in scenarios where we are trying to create a passkey * PM-7369 moved logic to show passkey icon to CipherItemViewModel * Update src/Core/Utilities/IconGlyphConverter.cs Co-authored-by: Federico Maccaroni --------- Co-authored-by: Federico Maccaroni --- src/Core/Controls/CipherViewCell/CipherViewCell.xaml | 2 +- src/Core/Models/View/CipherView.cs | 2 +- src/Core/Pages/Vault/AutofillCiphersPageViewModel.cs | 6 +++++- src/Core/Pages/Vault/CipherItemViewModel.cs | 2 ++ src/Core/Utilities/IconGlyphConverter.cs | 6 ++++++ src/Core/Utilities/IconGlyphExtensions.cs | 8 ++++---- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Core/Controls/CipherViewCell/CipherViewCell.xaml b/src/Core/Controls/CipherViewCell/CipherViewCell.xaml index bbfdd41ee..4a8ebaeba 100644 --- a/src/Core/Controls/CipherViewCell/CipherViewCell.xaml +++ b/src/Core/Controls/CipherViewCell/CipherViewCell.xaml @@ -50,7 +50,7 @@ HorizontalOptions="Center" VerticalOptions="Center" StyleClass="list-icon, list-icon-platform" - Text="{Binding Cipher, Converter={StaticResource iconGlyphConverter}}" + Text="{Binding ., Converter={StaticResource iconGlyphConverter}}" ShouldUpdateFontSizeDynamicallyForAccesibility="True" AutomationProperties.IsInAccessibleTree="False" AutomationId="CipherTypeIcon" /> diff --git a/src/Core/Models/View/CipherView.cs b/src/Core/Models/View/CipherView.cs index 2a9f20d9c..6919e3854 100644 --- a/src/Core/Models/View/CipherView.cs +++ b/src/Core/Models/View/CipherView.cs @@ -51,7 +51,7 @@ namespace Bit.Core.Models.View public DateTime? DeletedDate { get; set; } public CipherRepromptType Reprompt { get; set; } public CipherKey Key { get; set; } - + public ItemView Item { get diff --git a/src/Core/Pages/Vault/AutofillCiphersPageViewModel.cs b/src/Core/Pages/Vault/AutofillCiphersPageViewModel.cs index 40a6962ce..980962581 100644 --- a/src/Core/Pages/Vault/AutofillCiphersPageViewModel.cs +++ b/src/Core/Pages/Vault/AutofillCiphersPageViewModel.cs @@ -52,7 +52,11 @@ namespace Bit.App.Pages var groupedItems = new List(); var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(Uri, null); - var matching = ciphers.Item1?.Select(c => new CipherItemViewModel(c, WebsiteIconsEnabled)).ToList(); + var matching = ciphers.Item1?.Select(c => new CipherItemViewModel(c, WebsiteIconsEnabled) + { + UsePasskeyIconAsPlaceholderFallback = _isAndroidFido2CredentialCreation + }).ToList(); + var hasMatching = matching?.Any() ?? false; if (matching?.Any() ?? false) { diff --git a/src/Core/Pages/Vault/CipherItemViewModel.cs b/src/Core/Pages/Vault/CipherItemViewModel.cs index 28dee6780..a5f094d9d 100644 --- a/src/Core/Pages/Vault/CipherItemViewModel.cs +++ b/src/Core/Pages/Vault/CipherItemViewModel.cs @@ -44,5 +44,7 @@ namespace Bit.App.Pages /// This is useful to check when the cell is being reused. /// public bool IconImageSuccesfullyLoaded { get; set; } + + public bool UsePasskeyIconAsPlaceholderFallback { get; set; } } } diff --git a/src/Core/Utilities/IconGlyphConverter.cs b/src/Core/Utilities/IconGlyphConverter.cs index 1c51688fb..c849781fc 100644 --- a/src/Core/Utilities/IconGlyphConverter.cs +++ b/src/Core/Utilities/IconGlyphConverter.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using Bit.App.Pages; using Bit.Core.Models.View; using Microsoft.Maui.Controls; using Microsoft.Maui; @@ -10,6 +11,11 @@ namespace Bit.App.Utilities { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + if (value is CipherItemViewModel cipherItemViewModel) + { + return cipherItemViewModel.Cipher?.GetIcon(cipherItemViewModel.UsePasskeyIconAsPlaceholderFallback); + } + if (value is CipherView cipher) { return cipher.GetIcon(); diff --git a/src/Core/Utilities/IconGlyphExtensions.cs b/src/Core/Utilities/IconGlyphExtensions.cs index 62a327d76..ee24c3782 100644 --- a/src/Core/Utilities/IconGlyphExtensions.cs +++ b/src/Core/Utilities/IconGlyphExtensions.cs @@ -6,12 +6,12 @@ namespace Bit.App.Utilities { public static class IconGlyphExtensions { - public static string GetIcon(this CipherView cipher) + public static string GetIcon(this CipherView cipher, bool usePasskeyIconAsPlaceholderFallback = false) { switch (cipher.Type) { case CipherType.Login: - return GetLoginIconGlyph(cipher); + return GetLoginIconGlyph(cipher, usePasskeyIconAsPlaceholderFallback); case CipherType.SecureNote: return BitwardenIcons.StickyNote; case CipherType.Card: @@ -22,9 +22,9 @@ namespace Bit.App.Utilities return null; } - static string GetLoginIconGlyph(CipherView cipher) + static string GetLoginIconGlyph(CipherView cipher, bool usePasskeyIconAsPlaceholderFallback = false) { - var icon = BitwardenIcons.Globe; + var icon = cipher.HasFido2Credential && usePasskeyIconAsPlaceholderFallback ? BitwardenIcons.Passkey : BitwardenIcons.Globe; if (cipher.Login.Uri != null) { var hostnameUri = cipher.Login.Uri;