autofill page fixes

This commit is contained in:
Kyle Spearrin 2019-05-17 14:58:42 -04:00
parent 22366ec0a2
commit 65f3a146fa
3 changed files with 28 additions and 19 deletions

View file

@ -20,6 +20,8 @@
<ContentPage.Resources> <ContentPage.Resources>
<ResourceDictionary> <ResourceDictionary>
<u:InverseBoolConverter x:Key="inverseBool" />
<DataTemplate x:Key="cipherTemplate" <DataTemplate x:Key="cipherTemplate"
x:DataType="pages:GroupingsPageListItem"> x:DataType="pages:GroupingsPageListItem">
<controls:CipherViewCell <controls:CipherViewCell
@ -35,9 +37,9 @@
VerticalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
Padding="20, 0" Padding="20, 0"
Spacing="20" Spacing="20"
IsVisible="{Binding ShowNoData}"> IsVisible="{Binding ShowList, Converter={StaticResource inverseBool}}">
<Label <Label
Text="TODO: no data" Text="{Binding NoDataText}"
HorizontalTextAlignment="Center"></Label> HorizontalTextAlignment="Center"></Label>
<Button <Button
Text="{u:I18n AddAnItem}" Text="{u:I18n AddAnItem}"

View file

@ -15,6 +15,7 @@ namespace Bit.App.Pages
InitializeComponent(); InitializeComponent();
_vm = BindingContext as AutofillCiphersPageViewModel; _vm = BindingContext as AutofillCiphersPageViewModel;
_vm.Page = this; _vm.Page = this;
_fab.Clicked = AddButton_Clicked;
_vm.Init(appOptions); _vm.Init(appOptions);
} }

View file

@ -25,8 +25,8 @@ namespace Bit.App.Pages
private AppOptions _appOptions; private AppOptions _appOptions;
private string _name; private string _name;
private string _uri; private string _uri;
private bool _showNoData;
private bool _showList; private bool _showList;
private string _noDataText;
public AutofillCiphersPageViewModel() public AutofillCiphersPageViewModel()
{ {
@ -41,18 +41,18 @@ namespace Bit.App.Pages
public Command CipherOptionsCommand { get; set; } public Command CipherOptionsCommand { get; set; }
public ExtendedObservableCollection<GroupingsPageListGroup> GroupedItems { get; set; } public ExtendedObservableCollection<GroupingsPageListGroup> GroupedItems { get; set; }
public bool ShowNoData
{
get => _showNoData;
set => SetProperty(ref _showNoData, value);
}
public bool ShowList public bool ShowList
{ {
get => _showList; get => _showList;
set => SetProperty(ref _showList, value); set => SetProperty(ref _showList, value);
} }
public string NoDataText
{
get => _noDataText;
set => SetProperty(ref _noDataText, value);
}
public void Init(AppOptions appOptions) public void Init(AppOptions appOptions)
{ {
_appOptions = appOptions; _appOptions = appOptions;
@ -67,23 +67,29 @@ namespace Bit.App.Pages
_name = "--"; _name = "--";
} }
PageTitle = string.Format(AppResources.ItemsForUri, _name ?? "--"); PageTitle = string.Format(AppResources.ItemsForUri, _name ?? "--");
NoDataText = string.Format(AppResources.NoItemsForUri, _name ?? "--");
} }
public async Task LoadAsync() public async Task LoadAsync()
{ {
ShowNoData = false;
ShowList = false; ShowList = false;
var groupedItems = new List<GroupingsPageListGroup>();
var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(_uri, null); var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(_uri, null);
var matching = ciphers.Item1?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList(); var matching = ciphers.Item1?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList();
var matchingGroup = new GroupingsPageListGroup(matching, AppResources.MatchingItems, matching.Count, false); if(matching?.Any() ?? false)
var fuzzy = ciphers.Item2?.Select(c => new GroupingsPageListItem { Cipher = c, FuzzyAutofill = true }) {
.ToList(); groupedItems.Add(
var fuzzyGroup = new GroupingsPageListGroup(fuzzy, AppResources.PossibleMatchingItems, fuzzy.Count, false); new GroupingsPageListGroup(matching, AppResources.MatchingItems, matching.Count, false));
GroupedItems.ResetWithRange(new List<GroupingsPageListGroup> { matchingGroup, fuzzyGroup }); }
var fuzzy = ciphers.Item2?.Select(c =>
ShowNoData = !matching.Any() && !fuzzy.Any(); new GroupingsPageListItem { Cipher = c, FuzzyAutofill = true }).ToList();
ShowList = !ShowNoData; if(fuzzy?.Any() ?? false)
{
groupedItems.Add(
new GroupingsPageListGroup(fuzzy, AppResources.PossibleMatchingItems, fuzzy.Count, false));
}
GroupedItems.ResetWithRange(groupedItems);
ShowList = groupedItems.Any();
} }
public async Task SelectCipherAsync(CipherView cipher, bool fuzzy) public async Task SelectCipherAsync(CipherView cipher, bool fuzzy)