PM-3349 PM-3350 Added workaround for More Options to work on Search and Groupings Page

Updated some code to MAUI Style also
This commit is contained in:
Dinis Vieira 2023-12-01 15:02:12 +00:00
parent bfa2a51608
commit d168a7b750
No known key found for this signature in database
GPG key ID: 9389160FF6C295F3
6 changed files with 28 additions and 40 deletions

View file

@ -1,5 +1,6 @@
using System.Windows.Input; using System.Windows.Input;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Pages;
using Bit.Core.Models.View; using Bit.Core.Models.View;
using Bit.Core.Utilities; using Bit.Core.Utilities;
@ -59,10 +60,21 @@ namespace Bit.App.Controls
private void MoreButton_Clicked(object sender, EventArgs e) private void MoreButton_Clicked(object sender, EventArgs e)
{ {
var cipher = ((sender as MiButton)?.BindingContext as CipherViewCellViewModel)?.Cipher; // WORKAROUND: Added a temporary workaround so that the MoreButton still works in all pages even if it uses GroupingsPageListItem instead of CipherViewCellViewModel.
if (cipher != null) // 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);
} }
} }
} }

View file

@ -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.*") // 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() var touchBehavior = new TouchBehavior()
{ {
NativeAnimation = true NativeAnimation = true,
ShouldMakeChildrenInputTransparent = false
}; };
Behaviors.Add(touchBehavior); Behaviors.Add(touchBehavior);
#endif #endif

View file

@ -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.*") // 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() var touchBehavior = new TouchBehavior()
{ {
NativeAnimation = true NativeAnimation = true,
ShouldMakeChildrenInputTransparent = false
}; };
Behaviors.Add(touchBehavior); Behaviors.Add(touchBehavior);
#endif #endif

View file

@ -1,20 +1,11 @@
using System.Collections.Generic; using System.Windows.Input;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Controls; using Bit.App.Controls;
using Bit.App.Models;
using Bit.Core.Resources.Localization;
using Bit.App.Utilities; using Bit.App.Utilities;
using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Models.View; using Bit.Core.Models.View;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.Maui.Controls;
using Microsoft.Maui;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
public abstract class CipherSelectionPageViewModel : BaseViewModel public abstract class CipherSelectionPageViewModel : BaseViewModel
@ -108,10 +99,7 @@ namespace Bit.App.Pages
var groupedItems = await LoadGroupedItemsAsync(); var groupedItems = await LoadGroupedItemsAsync();
// TODO: refactor this // 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 (DeviceInfo.Platform == DevicePlatform.Android || GroupedItems.Any())
if (Device.RuntimePlatform == Device.Android
||
GroupedItems.Any())
{ {
var items = new List<IGroupingsPageListItem>(); var items = new List<IGroupingsPageListItem>();
foreach (var itemGroup in groupedItems) foreach (var itemGroup in groupedItems)
@ -140,7 +128,7 @@ namespace Bit.App.Pages
items.AddRange(itemGroup); items.AddRange(itemGroup);
} }
await Device.InvokeOnMainThreadAsync(() => await MainThread.InvokeOnMainThreadAsync(() =>
{ {
if (groupedItems.Any()) if (groupedItems.Any())
{ {
@ -153,7 +141,7 @@ namespace Bit.App.Pages
} }
}); });
} }
await Device.InvokeOnMainThreadAsync(() => await MainThread.InvokeOnMainThreadAsync(() =>
{ {
ShowList = groupedItems.Any(); ShowList = groupedItems.Any();
ShowNoData = !ShowList; ShowNoData = !ShowList;

View file

@ -1,13 +1,9 @@
using System; using Bit.App.Controls;
using System.Linq;
using Bit.App.Controls;
using Bit.App.Models; using Bit.App.Models;
using Bit.Core.Resources.Localization; using Bit.Core.Resources.Localization;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Models.View; using Bit.Core.Models.View;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.Maui.Controls;
using Microsoft.Maui;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
@ -41,8 +37,7 @@ namespace Bit.App.Pages
} }
_vm.VaultFilterDescription = vaultFilterSelection; _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 (DeviceInfo.Platform == DevicePlatform.iOS)
if (Device.RuntimePlatform == Device.iOS)
{ {
ToolbarItems.Add(_closeItem); ToolbarItems.Add(_closeItem);
_searchBar.Placeholder = AppResources.Search; _searchBar.Placeholder = AppResources.Search;
@ -59,7 +54,7 @@ namespace Bit.App.Pages
public SearchBar SearchBar => _searchBar; public SearchBar SearchBar => _searchBar;
protected async override void OnAppearing() protected override async void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
await _vm.InitAsync(); await _vm.InitAsync();

View file

@ -1,9 +1,4 @@
using System; using System.Windows.Input;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Models; using Bit.App.Models;
using Bit.Core.Resources.Localization; using Bit.Core.Resources.Localization;
@ -13,10 +8,6 @@ using Bit.Core.Exceptions;
using Bit.Core.Models.View; using Bit.Core.Models.View;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Microsoft.Maui.Controls;
using Microsoft.Maui;
using Bit.App.Utilities;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
public class CiphersPageViewModel : VaultFilterViewModel public class CiphersPageViewModel : VaultFilterViewModel
@ -164,7 +155,7 @@ namespace Bit.App.Pages
{ {
ciphers = new List<CipherView>(); ciphers = new List<CipherView>();
} }
Device.BeginInvokeOnMainThread(() => MainThread.BeginInvokeOnMainThread(() =>
{ {
Ciphers.ResetWithRange(ciphers); Ciphers.ResetWithRange(ciphers);
ShowNoData = !shouldShowAllWhenEmpty && searchable && Ciphers.Count == 0; ShowNoData = !shouldShowAllWhenEmpty && searchable && Ciphers.Count == 0;