mirror of
https://github.com/bitwarden/android.git
synced 2024-12-26 19:08:32 +03: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
10 changed files with 70 additions and 110 deletions
|
@ -1,62 +1,28 @@
|
|||
using System;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
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(
|
||||
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()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>();
|
||||
_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
|
||||
{
|
||||
get => GetValue(ButtonCommandProperty) as Command<SendView>;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
|
|
|
@ -37,12 +37,13 @@
|
|||
SemanticProperties.Description="{u:I18n AddItem}" />
|
||||
|
||||
<DataTemplate x:Key="sendTemplate"
|
||||
x:DataType="pages:SendGroupingsPageListItem">
|
||||
<controls:SendViewCell
|
||||
Send="{Binding Send}"
|
||||
ButtonCommand="{Binding BindingContext.SendOptionsCommand, Source={x:Reference _page}}"
|
||||
ShowOptions="{Binding BindingContext.SendEnabled, Source={x:Reference _page}}"
|
||||
AutomationId="SendCell" />
|
||||
x:DataType="pages:SendGroupingsPageListItem">
|
||||
<Grid>
|
||||
<controls:SendViewCell
|
||||
BindingContext="{Binding SendItemViewModel}"
|
||||
ButtonCommand="{Binding BindingContext.SendOptionsCommand, Source={x:Reference _page}}"
|
||||
AutomationId="SendCell" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="sendGroupTemplate"
|
||||
|
|
|
@ -156,9 +156,9 @@ namespace Bit.App.Pages
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using Bit.Core.Resources.Localization;
|
||||
using Bit.App.Controls;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Resources.Localization;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
|
@ -10,10 +11,22 @@ namespace Bit.App.Pages
|
|||
private string _icon;
|
||||
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 SendViewCellViewModel SendItemViewModel { get; }
|
||||
public string ItemCount { get; set; }
|
||||
public bool ShowOptions { get; set; }
|
||||
//public bool ShowOptions { get; set; }
|
||||
|
||||
public string Name
|
||||
{
|
||||
|
@ -23,19 +36,20 @@ namespace Bit.App.Pages
|
|||
{
|
||||
return _name;
|
||||
}
|
||||
if (Type != null)
|
||||
|
||||
if (!Type.HasValue)
|
||||
{
|
||||
switch (Type.Value)
|
||||
{
|
||||
case SendType.Text:
|
||||
_name = AppResources.TypeText;
|
||||
break;
|
||||
case SendType.File:
|
||||
_name = AppResources.TypeFile;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (Type.Value)
|
||||
{
|
||||
case SendType.Text:
|
||||
_name = AppResources.TypeText;
|
||||
break;
|
||||
case SendType.File:
|
||||
_name = AppResources.TypeFile;
|
||||
break;
|
||||
}
|
||||
return _name;
|
||||
}
|
||||
|
@ -49,19 +63,20 @@ namespace Bit.App.Pages
|
|||
{
|
||||
return _icon;
|
||||
}
|
||||
if (Type != null)
|
||||
|
||||
if (!Type.HasValue)
|
||||
{
|
||||
switch (Type.Value)
|
||||
{
|
||||
case SendType.Text:
|
||||
_icon = BitwardenIcons.FileText;
|
||||
break;
|
||||
case SendType.File:
|
||||
_icon = BitwardenIcons.File;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (Type.Value)
|
||||
{
|
||||
case SendType.Text:
|
||||
_icon = BitwardenIcons.FileText;
|
||||
break;
|
||||
case SendType.File:
|
||||
_icon = BitwardenIcons.File;
|
||||
break;
|
||||
}
|
||||
return _icon;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Bit.App.Pages
|
|||
|
||||
if (item is SendGroupingsPageListItem listItem)
|
||||
{
|
||||
return listItem.Send != null ? SendTemplate : GroupTemplate;
|
||||
return listItem.SendItemViewModel != null ? SendTemplate : GroupTemplate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -153,36 +153,20 @@ namespace Bit.App.Pages
|
|||
groupedSends.Add(new SendGroupingsPageListGroup(
|
||||
AppResources.Types, 0, uppercaseGroupNames, true)
|
||||
{
|
||||
new SendGroupingsPageListItem
|
||||
{
|
||||
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")
|
||||
},
|
||||
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)
|
||||
});
|
||||
}
|
||||
|
||||
if (Sends?.Any() ?? false)
|
||||
if (Sends?.Any() == true)
|
||||
{
|
||||
var sendsListItems = Sends.Select(s => new SendGroupingsPageListItem
|
||||
{
|
||||
Send = s,
|
||||
ShowOptions = SendEnabled
|
||||
}).ToList();
|
||||
var sendsListItems = Sends.Select(s => new SendGroupingsPageListItem(s, SendEnabled)).ToList();
|
||||
groupedSends.Add(new SendGroupingsPageListGroup(sendsListItems,
|
||||
MainPage ? AppResources.AllSends : AppResources.Sends, sendsListItems.Count,
|
||||
uppercaseGroupNames, !MainPage));
|
||||
}
|
||||
|
||||
// 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
|
||||
if (DeviceInfo.Platform == DevicePlatform.Android
|
||||
||
|
||||
GroupedSends.Any())
|
||||
{
|
||||
|
|
|
@ -71,11 +71,9 @@
|
|||
ExtraDataForLogging="Sends Page"
|
||||
AutomationId="SendCellList">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:DataType="views:SendView">
|
||||
<DataTemplate x:DataType="controls:SendViewCellViewModel">
|
||||
<controls:SendViewCell
|
||||
Send="{Binding .}"
|
||||
ButtonCommand="{Binding BindingContext.SendOptionsCommand, Source={x:Reference _page}}"
|
||||
ShowOptions="{Binding BindingContext.SendEnabled, Source={x:Reference _page}}"
|
||||
AutomationId="SendCell" />
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
|
|
|
@ -108,9 +108,9 @@ namespace Bit.App.Pages
|
|||
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 System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Controls;
|
||||
using Bit.App.Utilities;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
|
@ -22,13 +17,13 @@ namespace Bit.App.Pages
|
|||
|
||||
public SendsPageViewModel()
|
||||
{
|
||||
_searchService = ServiceContainer.Resolve<ISearchService>("searchService");
|
||||
Sends = new ExtendedObservableCollection<SendView>();
|
||||
_searchService = ServiceContainer.Resolve<ISearchService>();
|
||||
Sends = new ExtendedObservableCollection<SendViewCellViewModel>();
|
||||
SendOptionsCommand = new Command<SendView>(SendOptionsAsync);
|
||||
}
|
||||
|
||||
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 bool SendEnabled
|
||||
|
@ -102,9 +97,9 @@ namespace Bit.App.Pages
|
|||
{
|
||||
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;
|
||||
ShowList = searchable && !ShowNoData;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue