mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-26 12:16:07 +01:00
PM-3349 PM-3350 Changed SendViewCell and its binding to be directly against the ViewModel
This commit is contained in:
parent
363da063fa
commit
e0a3c301fb
@ -1,62 +1,28 @@
|
|||||||
using System;
|
using Bit.App.Abstractions;
|
||||||
using Bit.App.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.Controls
|
namespace Bit.App.Controls
|
||||||
{
|
{
|
||||||
public partial class SendViewCell : ExtendedGrid
|
public partial class SendViewCell : ExtendedGrid
|
||||||
{
|
{
|
||||||
public static readonly BindableProperty SendProperty = BindableProperty.Create(
|
|
||||||
nameof(Send), typeof(SendView), typeof(SendViewCell), default(SendView), BindingMode.OneWay);
|
|
||||||
|
|
||||||
public static readonly BindableProperty ButtonCommandProperty = BindableProperty.Create(
|
public static readonly BindableProperty ButtonCommandProperty = BindableProperty.Create(
|
||||||
nameof(ButtonCommand), typeof(Command<SendView>), typeof(SendViewCell));
|
nameof(ButtonCommand), typeof(Command<SendView>), typeof(SendViewCell));
|
||||||
|
|
||||||
public static readonly BindableProperty ShowOptionsProperty = BindableProperty.Create(
|
|
||||||
nameof(ShowOptions), typeof(bool), typeof(SendViewCell), true, BindingMode.OneWay);
|
|
||||||
|
|
||||||
public SendViewCell()
|
public SendViewCell()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>();
|
||||||
_iconColumn.Width = new GridLength(40 * deviceActionService.GetSystemFontSizeScale(), GridUnitType.Absolute);
|
_iconColumn.Width = new GridLength(40 * deviceActionService.GetSystemFontSizeScale(), GridUnitType.Absolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SendView Send
|
|
||||||
{
|
|
||||||
get => GetValue(SendProperty) as SendView;
|
|
||||||
set => SetValue(SendProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Command<SendView> ButtonCommand
|
public Command<SendView> ButtonCommand
|
||||||
{
|
{
|
||||||
get => GetValue(ButtonCommandProperty) as Command<SendView>;
|
get => GetValue(ButtonCommandProperty) as Command<SendView>;
|
||||||
set => SetValue(ButtonCommandProperty, value);
|
set => SetValue(ButtonCommandProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ShowOptions
|
|
||||||
{
|
|
||||||
get => (bool)GetValue(ShowOptionsProperty);
|
|
||||||
set => SetValue(ShowOptionsProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPropertyChanged(string propertyName = null)
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged(propertyName);
|
|
||||||
if (propertyName == SendProperty.PropertyName)
|
|
||||||
{
|
|
||||||
if (Send == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BindingContext = new SendViewCellViewModel(Send, ShowOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MoreButton_Clicked(object sender, EventArgs e)
|
private void MoreButton_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var send = ((sender as MiButton)?.BindingContext as SendViewCellViewModel)?.Send;
|
var send = ((sender as MiButton)?.BindingContext as SendViewCellViewModel)?.Send;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Bit.Core.Models.View;
|
using System.Globalization;
|
||||||
|
using Bit.Core.Models.View;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.App.Controls
|
namespace Bit.App.Controls
|
||||||
|
@ -38,11 +38,12 @@
|
|||||||
|
|
||||||
<DataTemplate x:Key="sendTemplate"
|
<DataTemplate x:Key="sendTemplate"
|
||||||
x:DataType="pages:SendGroupingsPageListItem">
|
x:DataType="pages:SendGroupingsPageListItem">
|
||||||
|
<Grid>
|
||||||
<controls:SendViewCell
|
<controls:SendViewCell
|
||||||
Send="{Binding Send}"
|
BindingContext="{Binding SendItemViewModel}"
|
||||||
ButtonCommand="{Binding BindingContext.SendOptionsCommand, Source={x:Reference _page}}"
|
ButtonCommand="{Binding BindingContext.SendOptionsCommand, Source={x:Reference _page}}"
|
||||||
ShowOptions="{Binding BindingContext.SendEnabled, Source={x:Reference _page}}"
|
|
||||||
AutomationId="SendCell" />
|
AutomationId="SendCell" />
|
||||||
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate x:Key="sendGroupTemplate"
|
<DataTemplate x:Key="sendGroupTemplate"
|
||||||
|
@ -156,9 +156,9 @@ namespace Bit.App.Pages
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.Send != null)
|
if (item.SendItemViewModel != null)
|
||||||
{
|
{
|
||||||
await _vm.SelectSendAsync(item.Send);
|
await _vm.SelectSendAsync(item.SendItemViewModel.Send);
|
||||||
}
|
}
|
||||||
else if (item.Type != null)
|
else if (item.Type != null)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
using Bit.Core.Resources.Localization;
|
using Bit.App.Controls;
|
||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Models.View;
|
using Bit.Core.Models.View;
|
||||||
|
using Bit.Core.Resources.Localization;
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
@ -10,10 +11,22 @@ namespace Bit.App.Pages
|
|||||||
private string _icon;
|
private string _icon;
|
||||||
private string _name;
|
private string _name;
|
||||||
|
|
||||||
public SendView Send { get; set; }
|
public SendGroupingsPageListItem(SendType type, int itemCount)
|
||||||
|
{
|
||||||
|
Type = type;
|
||||||
|
ItemCount = itemCount.ToString("N0");
|
||||||
|
}
|
||||||
|
|
||||||
|
public SendGroupingsPageListItem(SendView send, bool showOptions)
|
||||||
|
{
|
||||||
|
SendItemViewModel = new SendViewCellViewModel(send, showOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
//public SendView Send { get; set; }
|
||||||
public SendType? Type { get; set; }
|
public SendType? Type { get; set; }
|
||||||
|
public SendViewCellViewModel SendItemViewModel { get; }
|
||||||
public string ItemCount { get; set; }
|
public string ItemCount { get; set; }
|
||||||
public bool ShowOptions { get; set; }
|
//public bool ShowOptions { get; set; }
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
@ -23,8 +36,12 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
if (Type != null)
|
|
||||||
|
if (!Type.HasValue)
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
switch (Type.Value)
|
switch (Type.Value)
|
||||||
{
|
{
|
||||||
case SendType.Text:
|
case SendType.Text:
|
||||||
@ -33,9 +50,6 @@ namespace Bit.App.Pages
|
|||||||
case SendType.File:
|
case SendType.File:
|
||||||
_name = AppResources.TypeFile;
|
_name = AppResources.TypeFile;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
@ -49,8 +63,12 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
return _icon;
|
return _icon;
|
||||||
}
|
}
|
||||||
if (Type != null)
|
|
||||||
|
if (!Type.HasValue)
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
switch (Type.Value)
|
switch (Type.Value)
|
||||||
{
|
{
|
||||||
case SendType.Text:
|
case SendType.Text:
|
||||||
@ -59,9 +77,6 @@ namespace Bit.App.Pages
|
|||||||
case SendType.File:
|
case SendType.File:
|
||||||
_icon = BitwardenIcons.File;
|
_icon = BitwardenIcons.File;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return _icon;
|
return _icon;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
if (item is SendGroupingsPageListItem listItem)
|
if (item is SendGroupingsPageListItem listItem)
|
||||||
{
|
{
|
||||||
return listItem.Send != null ? SendTemplate : GroupTemplate;
|
return listItem.SendItemViewModel != null ? SendTemplate : GroupTemplate;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -153,36 +153,20 @@ namespace Bit.App.Pages
|
|||||||
groupedSends.Add(new SendGroupingsPageListGroup(
|
groupedSends.Add(new SendGroupingsPageListGroup(
|
||||||
AppResources.Types, 0, uppercaseGroupNames, true)
|
AppResources.Types, 0, uppercaseGroupNames, true)
|
||||||
{
|
{
|
||||||
new SendGroupingsPageListItem
|
new SendGroupingsPageListItem(SendType.Text, _typeCounts.TryGetValue(SendType.Text, out var textCountValue) ? textCountValue : 0),
|
||||||
{
|
new SendGroupingsPageListItem(SendType.File, _typeCounts.TryGetValue(SendType.File, out var fileCountValue) ? fileCountValue : 0)
|
||||||
Type = SendType.Text,
|
|
||||||
ItemCount = (_typeCounts.ContainsKey(SendType.Text) ?
|
|
||||||
_typeCounts[SendType.Text] : 0).ToString("N0")
|
|
||||||
},
|
|
||||||
new SendGroupingsPageListItem
|
|
||||||
{
|
|
||||||
Type = SendType.File,
|
|
||||||
ItemCount = (_typeCounts.ContainsKey(SendType.File) ?
|
|
||||||
_typeCounts[SendType.File] : 0).ToString("N0")
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Sends?.Any() ?? false)
|
if (Sends?.Any() == true)
|
||||||
{
|
{
|
||||||
var sendsListItems = Sends.Select(s => new SendGroupingsPageListItem
|
var sendsListItems = Sends.Select(s => new SendGroupingsPageListItem(s, SendEnabled)).ToList();
|
||||||
{
|
|
||||||
Send = s,
|
|
||||||
ShowOptions = SendEnabled
|
|
||||||
}).ToList();
|
|
||||||
groupedSends.Add(new SendGroupingsPageListGroup(sendsListItems,
|
groupedSends.Add(new SendGroupingsPageListGroup(sendsListItems,
|
||||||
MainPage ? AppResources.AllSends : AppResources.Sends, sendsListItems.Count,
|
MainPage ? AppResources.AllSends : AppResources.Sends, sendsListItems.Count,
|
||||||
uppercaseGroupNames, !MainPage));
|
uppercaseGroupNames, !MainPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor this
|
if (DeviceInfo.Platform == DevicePlatform.Android
|
||||||
// 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
|
|
||||||
||
|
||
|
||||||
GroupedSends.Any())
|
GroupedSends.Any())
|
||||||
{
|
{
|
||||||
|
@ -71,11 +71,9 @@
|
|||||||
ExtraDataForLogging="Sends Page"
|
ExtraDataForLogging="Sends Page"
|
||||||
AutomationId="SendCellList">
|
AutomationId="SendCellList">
|
||||||
<CollectionView.ItemTemplate>
|
<CollectionView.ItemTemplate>
|
||||||
<DataTemplate x:DataType="views:SendView">
|
<DataTemplate x:DataType="controls:SendViewCellViewModel">
|
||||||
<controls:SendViewCell
|
<controls:SendViewCell
|
||||||
Send="{Binding .}"
|
|
||||||
ButtonCommand="{Binding BindingContext.SendOptionsCommand, Source={x:Reference _page}}"
|
ButtonCommand="{Binding BindingContext.SendOptionsCommand, Source={x:Reference _page}}"
|
||||||
ShowOptions="{Binding BindingContext.SendEnabled, Source={x:Reference _page}}"
|
|
||||||
AutomationId="SendCell" />
|
AutomationId="SendCell" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</CollectionView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
|
@ -108,9 +108,9 @@ namespace Bit.App.Pages
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.CurrentSelection?.FirstOrDefault() is SendView send)
|
if (e.CurrentSelection?.FirstOrDefault() is SendViewCellViewModel sendVM)
|
||||||
{
|
{
|
||||||
await _vm.SelectSendAsync(send);
|
await _vm.SelectSendAsync(sendVM.Send);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
using System;
|
using Bit.App.Controls;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bit.App.Utilities;
|
using Bit.App.Utilities;
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -22,13 +17,13 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
public SendsPageViewModel()
|
public SendsPageViewModel()
|
||||||
{
|
{
|
||||||
_searchService = ServiceContainer.Resolve<ISearchService>("searchService");
|
_searchService = ServiceContainer.Resolve<ISearchService>();
|
||||||
Sends = new ExtendedObservableCollection<SendView>();
|
Sends = new ExtendedObservableCollection<SendViewCellViewModel>();
|
||||||
SendOptionsCommand = new Command<SendView>(SendOptionsAsync);
|
SendOptionsCommand = new Command<SendView>(SendOptionsAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command SendOptionsCommand { get; set; }
|
public Command SendOptionsCommand { get; set; }
|
||||||
public ExtendedObservableCollection<SendView> Sends { get; set; }
|
public ExtendedObservableCollection<SendViewCellViewModel> Sends { get; set; }
|
||||||
public Func<SendView, bool> Filter { get; set; }
|
public Func<SendView, bool> Filter { get; set; }
|
||||||
|
|
||||||
public bool SendEnabled
|
public bool SendEnabled
|
||||||
@ -102,9 +97,9 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
sends = new List<SendView>();
|
sends = new List<SendView>();
|
||||||
}
|
}
|
||||||
Device.BeginInvokeOnMainThread(() =>
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
{
|
{
|
||||||
Sends.ResetWithRange(sends);
|
Sends.ResetWithRange(sends.Select(s => new SendViewCellViewModel(s, SendEnabled)).ToList());
|
||||||
ShowNoData = searchable && Sends.Count == 0;
|
ShowNoData = searchable && Sends.Count == 0;
|
||||||
ShowList = searchable && !ShowNoData;
|
ShowList = searchable && !ShowNoData;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user