diff --git a/src/App/Models/Page/VaultListPageModel.cs b/src/App/Models/Page/VaultListPageModel.cs index b9a6227da..06fb78728 100644 --- a/src/App/Models/Page/VaultListPageModel.cs +++ b/src/App/Models/Page/VaultListPageModel.cs @@ -183,30 +183,25 @@ namespace Bit.App.Models.Page public string Name { get; set; } = AppResources.FolderNone; } - public class NameGroup : List + public class Section : List { - public NameGroup(string nameGroup, List ciphers) + public Section(List groupItems, string name, bool doUpper = true) { - Name = nameGroup.ToUpperInvariant(); - AddRange(ciphers); + AddRange(groupItems); + + if(doUpper) + { + Name = name.ToUpperInvariant(); + } + else + { + Name = name; + } } public string Name { get; set; } } - public class Section : List - { - public Section(List groupings, string name) - { - AddRange(groupings); - Name = name.ToUpperInvariant(); - ItemCount = groupings.Count; - } - - public string Name { get; set; } - public int ItemCount { get; set; } - } - public class Grouping { public Grouping(string name, int count) @@ -239,16 +234,5 @@ namespace Bit.App.Models.Page public bool Folder { get; set; } public bool Collection { get; set; } } - - public class AutofillGrouping : List - { - public AutofillGrouping(List logins, string name) - { - AddRange(logins); - Name = name; - } - - public string Name { get; set; } - } } } diff --git a/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs b/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs index f04b3fc1d..2ca338b83 100644 --- a/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs +++ b/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs @@ -13,6 +13,7 @@ using System.Threading; using Bit.App.Models; using System.Collections.Generic; using Bit.App.Enums; +using static Bit.App.Models.Page.VaultListPageModel; namespace Bit.App.Pages { @@ -53,8 +54,8 @@ namespace Bit.App.Pages Init(); } - public ExtendedObservableCollection PresentationCiphersGroup { get; private set; } - = new ExtendedObservableCollection(); + public ExtendedObservableCollection> PresentationCiphersGroup { get; private set; } + = new ExtendedObservableCollection>(); public StackLayout NoDataStackLayout { get; set; } public ListView ListView { get; set; } public ActivityIndicator LoadingIndicator { get; set; } @@ -100,7 +101,7 @@ namespace Bit.App.Pages ItemsSource = PresentationCiphersGroup, HasUnevenRows = true, GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell( - nameof(VaultListPageModel.AutofillGrouping.Name))), + nameof(Section.Name))), ItemTemplate = new DataTemplate(() => new VaultListViewCell( (VaultListPageModel.Cipher c) => Helpers.CipherMoreClickedAsync(this, c, true))) }; @@ -165,42 +166,42 @@ namespace Bit.App.Pages Task.Run(async () => { - var autofillGroupings = new List(); + var autofillGroupings = new List>(); var ciphers = await _cipherService.GetAllAsync(Uri); if(_appOptions.FillType.HasValue && _appOptions.FillType.Value != CipherType.Login) { var others = ciphers?.Item3.Where(c => c.Type == _appOptions.FillType.Value) - .Select(c => new VaultListPageModel.AutofillCipher(c, _appSettingsService, false)) + .Select(c => new AutofillCipher(c, _appSettingsService, false)) .OrderBy(s => s.Name) .ThenBy(s => s.Subtitle) .ToList(); if(others?.Any() ?? false) { - autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(others, AppResources.Items)); + autofillGroupings.Add(new Section(others, AppResources.Items)); } } else { var normalLogins = ciphers?.Item1 - .Select(l => new VaultListPageModel.AutofillCipher(l, _appSettingsService, false)) + .Select(l => new AutofillCipher(l, _appSettingsService, false)) .OrderBy(s => s.Name) .ThenBy(s => s.Subtitle) .ToList(); if(normalLogins?.Any() ?? false) { - autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(normalLogins, + autofillGroupings.Add(new Section(normalLogins, AppResources.MatchingItems)); } var fuzzyLogins = ciphers?.Item2 - .Select(l => new VaultListPageModel.AutofillCipher(l, _appSettingsService, true)) + .Select(l => new AutofillCipher(l, _appSettingsService, true)) .OrderBy(s => s.Name) .ThenBy(s => s.Subtitle) .ToList(); if(fuzzyLogins?.Any() ?? false) { - autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(fuzzyLogins, + autofillGroupings.Add(new Section(fuzzyLogins, AppResources.PossibleMatchingItems)); } } @@ -221,7 +222,7 @@ namespace Bit.App.Pages private async void CipherSelected(object sender, SelectedItemChangedEventArgs e) { - var cipher = e.SelectedItem as VaultListPageModel.AutofillCipher; + var cipher = e.SelectedItem as AutofillCipher; if(cipher == null) { return; diff --git a/src/App/Pages/Vault/VaultListGroupingsPage.cs b/src/App/Pages/Vault/VaultListGroupingsPage.cs index 854cfbc85..cbb9b6383 100644 --- a/src/App/Pages/Vault/VaultListGroupingsPage.cs +++ b/src/App/Pages/Vault/VaultListGroupingsPage.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Acr.UserDialogs; using Bit.App.Abstractions; using Bit.App.Controls; -using Bit.App.Models.Page; using Bit.App.Resources; using Xamarin.Forms; using XLabs.Ioc; @@ -14,6 +13,7 @@ using Plugin.Connectivity.Abstractions; using System.Collections.Generic; using System.Threading; using Bit.App.Enums; +using static Bit.App.Models.Page.VaultListPageModel; namespace Bit.App.Pages { @@ -52,8 +52,8 @@ namespace Bit.App.Pages Init(); } - public ExtendedObservableCollection PresentationSections { get; private set; } - = new ExtendedObservableCollection(); + public ExtendedObservableCollection> PresentationSections { get; private set; } + = new ExtendedObservableCollection>(); public ListView ListView { get; set; } public StackLayout NoDataStackLayout { get; set; } public ActivityIndicator LoadingIndicator { get; set; } @@ -73,7 +73,7 @@ namespace Bit.App.Pages ItemsSource = PresentationSections, HasUnevenRows = true, GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell( - nameof(VaultListPageModel.Section.Name), nameof(VaultListPageModel.Section.ItemCount), + nameof(Section.Name), nameof(Section.Count), new Thickness(16, Helpers.OnPlatform(20, 12, 12), 16, 12))), ItemTemplate = new DataTemplate(() => new VaultGroupingViewCell()) }; @@ -154,7 +154,7 @@ namespace Bit.App.Pages Task.Run(async () => { - var sections = new List(); + var sections = new List>(); var ciphers = await _cipherService.GetAllAsync(); var collectionsDict = (await _collectionService.GetAllCipherAssociationsAsync()) .GroupBy(c => c.Item2).ToDictionary(g => g.Key, v => v.ToList()); @@ -178,19 +178,19 @@ namespace Bit.App.Pages var folders = await _folderService.GetAllAsync(); var folderGroupings = folders? - .Select(f => new VaultListPageModel.Grouping(f, folderCounts.ContainsKey(f.Id) ? folderCounts[f.Id] : 0)) + .Select(f => new Grouping(f, folderCounts.ContainsKey(f.Id) ? folderCounts[f.Id] : 0)) .OrderBy(g => g.Name).ToList(); - folderGroupings.Add(new VaultListPageModel.Grouping(AppResources.FolderNone, folderCounts["none"])); - sections.Add(new VaultListPageModel.Section(folderGroupings, AppResources.Folders)); + folderGroupings.Add(new Grouping(AppResources.FolderNone, folderCounts["none"])); + sections.Add(new Section(folderGroupings, AppResources.Folders)); var collections = await _collectionService.GetAllAsync(); var collectionGroupings = collections? - .Select(c => new VaultListPageModel.Grouping(c, + .Select(c => new Grouping(c, collectionsDict.ContainsKey(c.Id) ? collectionsDict[c.Id].Count() : 0)) .OrderBy(g => g.Name).ToList(); if(collectionGroupings?.Any() ?? false) { - sections.Add(new VaultListPageModel.Section(collectionGroupings, AppResources.Collections)); + sections.Add(new Section(collectionGroupings, AppResources.Collections)); } Device.BeginInvokeOnMainThread(() => @@ -216,7 +216,7 @@ namespace Bit.App.Pages private void GroupingSelected(object sender, SelectedItemChangedEventArgs e) { - var grouping = e.SelectedItem as VaultListPageModel.Grouping; + var grouping = e.SelectedItem as Grouping; if(grouping == null) { return; diff --git a/src/App/Pages/Vault/VaultSearchCiphersPage.cs b/src/App/Pages/Vault/VaultSearchCiphersPage.cs index a81a7ad24..11826b3e5 100644 --- a/src/App/Pages/Vault/VaultSearchCiphersPage.cs +++ b/src/App/Pages/Vault/VaultSearchCiphersPage.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Threading.Tasks; using Bit.App.Abstractions; using Bit.App.Controls; -using Bit.App.Models.Page; using Bit.App.Resources; using Xamarin.Forms; using XLabs.Ioc; @@ -11,6 +10,7 @@ using Bit.App.Utilities; using Plugin.Settings.Abstractions; using Plugin.Connectivity.Abstractions; using System.Threading; +using static Bit.App.Models.Page.VaultListPageModel; namespace Bit.App.Pages { @@ -39,9 +39,9 @@ namespace Bit.App.Pages Init(); } - public ExtendedObservableCollection PresentationLetters { get; private set; } - = new ExtendedObservableCollection(); - public VaultListPageModel.Cipher[] Ciphers { get; set; } = new VaultListPageModel.Cipher[] { }; + public ExtendedObservableCollection> PresentationLetters { get; private set; } + = new ExtendedObservableCollection>(); + public Cipher[] Ciphers { get; set; } = new Cipher[] { }; public ListView ListView { get; set; } public SearchBar Search { get; set; } public StackLayout ResultsStackLayout { get; set; } @@ -53,10 +53,11 @@ namespace Bit.App.Pages IsGroupingEnabled = true, ItemsSource = PresentationLetters, HasUnevenRows = true, - GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell( - nameof(VaultListPageModel.NameGroup.Name), nameof(VaultListPageModel.NameGroup.Count))), + GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell(nameof(Section.Name), + nameof(Section.Count))), + GroupShortNameBinding = new Binding(nameof(Section.Name)), ItemTemplate = new DataTemplate(() => new VaultListViewCell( - (VaultListPageModel.Cipher c) => Helpers.CipherMoreClickedAsync(this, c, false))) + (Cipher c) => Helpers.CipherMoreClickedAsync(this, c, false))) }; if(Device.RuntimePlatform == Device.iOS) @@ -70,7 +71,7 @@ namespace Bit.App.Pages FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Button)), CancelButtonColor = Color.FromHex("3c8dbc") }; - // Bug with searchbar on android 7, ref https://bugzilla.xamarin.com/show_bug.cgi?id=43975 + // Bug with search bar on android 7, ref https://bugzilla.xamarin.com/show_bug.cgi?id=43975 if(Device.RuntimePlatform == Device.Android && _deviceInfoService.Version >= 24) { Search.HeightRequest = 50; @@ -204,7 +205,7 @@ namespace Bit.App.Pages var ciphers = await _cipherService.GetAllAsync(); Ciphers = ciphers - .Select(s => new VaultListPageModel.Cipher(s, _appSettingsService)) + .Select(s => new Cipher(s, _appSettingsService)) .OrderBy(s => { // Sort numbers and letters before special characters @@ -225,11 +226,10 @@ namespace Bit.App.Pages return cts; } - private void LoadLetters(VaultListPageModel.Cipher[] ciphers, CancellationToken ct) + private void LoadLetters(Cipher[] ciphers, CancellationToken ct) { ct.ThrowIfCancellationRequested(); - var letterGroups = ciphers.GroupBy(c => c.NameGroup) - .Select(g => new VaultListPageModel.NameGroup(g.Key, g.ToList())); + var letterGroups = ciphers.GroupBy(c => c.NameGroup).Select(g => new Section(g.ToList(), g.Key)); ct.ThrowIfCancellationRequested(); Device.BeginInvokeOnMainThread(() => { @@ -240,7 +240,7 @@ namespace Bit.App.Pages private async void CipherSelected(object sender, SelectedItemChangedEventArgs e) { - var cipher = e.SelectedItem as VaultListPageModel.Cipher; + var cipher = e.SelectedItem as Cipher; if(cipher == null) { return;