From d168a7b750bce7c4980c759a98682bb5f4b533af Mon Sep 17 00:00:00 2001 From: Dinis Vieira Date: Fri, 1 Dec 2023 15:02:12 +0000 Subject: [PATCH] PM-3349 PM-3350 Added workaround for More Options to work on Search and Groupings Page Updated some code to MAUI Style also --- .../CipherViewCell/CipherViewCell.xaml.cs | 18 ++++++++++++++--- src/Core/Controls/ExtendedGrid.cs | 3 ++- src/Core/Controls/ExtendedStackLayout.cs | 3 ++- .../Vault/CipherSelectionPageViewModel.cs | 20 ++++--------------- src/Core/Pages/Vault/CiphersPage.xaml.cs | 11 +++------- src/Core/Pages/Vault/CiphersPageViewModel.cs | 13 ++---------- 6 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/Core/Controls/CipherViewCell/CipherViewCell.xaml.cs b/src/Core/Controls/CipherViewCell/CipherViewCell.xaml.cs index 664bcfbe1..111de479a 100644 --- a/src/Core/Controls/CipherViewCell/CipherViewCell.xaml.cs +++ b/src/Core/Controls/CipherViewCell/CipherViewCell.xaml.cs @@ -1,5 +1,6 @@ using System.Windows.Input; using Bit.App.Abstractions; +using Bit.App.Pages; using Bit.Core.Models.View; using Bit.Core.Utilities; @@ -59,10 +60,21 @@ namespace Bit.App.Controls private void MoreButton_Clicked(object sender, EventArgs e) { - var cipher = ((sender as MiButton)?.BindingContext as CipherViewCellViewModel)?.Cipher; - if (cipher != null) + // WORKAROUND: Added a temporary workaround so that the MoreButton still works in all pages even if it uses GroupingsPageListItem instead of CipherViewCellViewModel. + // Ideally this should be fixed so that even Groupings Page uses CipherViewCellViewModel + CipherView cipherView = null; + if (BindingContext is CipherViewCellViewModel cipherViewCellViewModel) { - ButtonCommand?.Execute(cipher); + cipherView = cipherViewCellViewModel.Cipher; + } + else if (BindingContext is GroupingsPageListItem groupingsPageListItem) + { + cipherView = groupingsPageListItem.Cipher; + } + + if (cipherView != null) + { + ButtonCommand?.Execute(cipherView); } } } diff --git a/src/Core/Controls/ExtendedGrid.cs b/src/Core/Controls/ExtendedGrid.cs index f7d221ad1..00048d570 100644 --- a/src/Core/Controls/ExtendedGrid.cs +++ b/src/Core/Controls/ExtendedGrid.cs @@ -11,7 +11,8 @@ namespace Bit.App.Controls // TODO: [TouchEffect] When this TouchBehavior is replaced we can delete the existing TouchBehavior support files (which is all the files and folders inside "Core.Behaviors.PlatformBehaviors.MCTTouch.*") var touchBehavior = new TouchBehavior() { - NativeAnimation = true + NativeAnimation = true, + ShouldMakeChildrenInputTransparent = false }; Behaviors.Add(touchBehavior); #endif diff --git a/src/Core/Controls/ExtendedStackLayout.cs b/src/Core/Controls/ExtendedStackLayout.cs index 6cb6c4343..b4097520b 100644 --- a/src/Core/Controls/ExtendedStackLayout.cs +++ b/src/Core/Controls/ExtendedStackLayout.cs @@ -11,7 +11,8 @@ namespace Bit.App.Controls // TODO: [TouchEffect] When this TouchBehavior is replaced we can delete the existing TouchBehavior support files (which is all the files and folders inside "Core.Behaviors.PlatformBehaviors.MCTTouch.*") var touchBehavior = new TouchBehavior() { - NativeAnimation = true + NativeAnimation = true, + ShouldMakeChildrenInputTransparent = false }; Behaviors.Add(touchBehavior); #endif diff --git a/src/Core/Pages/Vault/CipherSelectionPageViewModel.cs b/src/Core/Pages/Vault/CipherSelectionPageViewModel.cs index c98c467e4..71445af70 100644 --- a/src/Core/Pages/Vault/CipherSelectionPageViewModel.cs +++ b/src/Core/Pages/Vault/CipherSelectionPageViewModel.cs @@ -1,20 +1,11 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Input; +using System.Windows.Input; using Bit.App.Abstractions; using Bit.App.Controls; -using Bit.App.Models; -using Bit.Core.Resources.Localization; using Bit.App.Utilities; -using Bit.Core; using Bit.Core.Abstractions; using Bit.Core.Models.View; using Bit.Core.Utilities; -using Microsoft.Maui.Controls; -using Microsoft.Maui; - namespace Bit.App.Pages { public abstract class CipherSelectionPageViewModel : BaseViewModel @@ -108,10 +99,7 @@ namespace Bit.App.Pages var groupedItems = await LoadGroupedItemsAsync(); // TODO: refactor this - // TODO Xamarin.Forms.Device.RuntimePlatform is no longer supported. Use Microsoft.Maui.Devices.DeviceInfo.Platform instead. For more details see https://learn.microsoft.com/en-us/dotnet/maui/migration/forms-projects#device-changes - if (Device.RuntimePlatform == Device.Android - || - GroupedItems.Any()) + if (DeviceInfo.Platform == DevicePlatform.Android || GroupedItems.Any()) { var items = new List(); foreach (var itemGroup in groupedItems) @@ -140,7 +128,7 @@ namespace Bit.App.Pages items.AddRange(itemGroup); } - await Device.InvokeOnMainThreadAsync(() => + await MainThread.InvokeOnMainThreadAsync(() => { if (groupedItems.Any()) { @@ -153,7 +141,7 @@ namespace Bit.App.Pages } }); } - await Device.InvokeOnMainThreadAsync(() => + await MainThread.InvokeOnMainThreadAsync(() => { ShowList = groupedItems.Any(); ShowNoData = !ShowList; diff --git a/src/Core/Pages/Vault/CiphersPage.xaml.cs b/src/Core/Pages/Vault/CiphersPage.xaml.cs index ae87a3555..0ae1561a8 100644 --- a/src/Core/Pages/Vault/CiphersPage.xaml.cs +++ b/src/Core/Pages/Vault/CiphersPage.xaml.cs @@ -1,13 +1,9 @@ -using System; -using System.Linq; -using Bit.App.Controls; +using Bit.App.Controls; using Bit.App.Models; using Bit.Core.Resources.Localization; using Bit.Core.Abstractions; using Bit.Core.Models.View; using Bit.Core.Utilities; -using Microsoft.Maui.Controls; -using Microsoft.Maui; namespace Bit.App.Pages { @@ -41,8 +37,7 @@ namespace Bit.App.Pages } _vm.VaultFilterDescription = vaultFilterSelection; - // TODO Xamarin.Forms.Device.RuntimePlatform is no longer supported. Use Microsoft.Maui.Devices.DeviceInfo.Platform instead. For more details see https://learn.microsoft.com/en-us/dotnet/maui/migration/forms-projects#device-changes - if (Device.RuntimePlatform == Device.iOS) + if (DeviceInfo.Platform == DevicePlatform.iOS) { ToolbarItems.Add(_closeItem); _searchBar.Placeholder = AppResources.Search; @@ -59,7 +54,7 @@ namespace Bit.App.Pages public SearchBar SearchBar => _searchBar; - protected async override void OnAppearing() + protected override async void OnAppearing() { base.OnAppearing(); await _vm.InitAsync(); diff --git a/src/Core/Pages/Vault/CiphersPageViewModel.cs b/src/Core/Pages/Vault/CiphersPageViewModel.cs index d4747e2a9..b9ba2ba02 100644 --- a/src/Core/Pages/Vault/CiphersPageViewModel.cs +++ b/src/Core/Pages/Vault/CiphersPageViewModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Input; +using System.Windows.Input; using Bit.App.Abstractions; using Bit.App.Models; using Bit.Core.Resources.Localization; @@ -13,10 +8,6 @@ using Bit.Core.Exceptions; using Bit.Core.Models.View; using Bit.Core.Utilities; -using Microsoft.Maui.Controls; -using Microsoft.Maui; -using Bit.App.Utilities; - namespace Bit.App.Pages { public class CiphersPageViewModel : VaultFilterViewModel @@ -164,7 +155,7 @@ namespace Bit.App.Pages { ciphers = new List(); } - Device.BeginInvokeOnMainThread(() => + MainThread.BeginInvokeOnMainThread(() => { Ciphers.ResetWithRange(ciphers); ShowNoData = !shouldShowAllWhenEmpty && searchable && Ciphers.Count == 0;