mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 07:05:35 +03:00
Extended observable collection for bulk addrange
This commit is contained in:
parent
11f908aab2
commit
c4161ac5a5
4 changed files with 45 additions and 18 deletions
|
@ -124,6 +124,7 @@
|
|||
<Compile Include="Pages\VaultEditSitePage.cs" />
|
||||
<Compile Include="Pages\VaultListSitesPage.cs" />
|
||||
<Compile Include="Utilities\Extentions.cs" />
|
||||
<Compile Include="Utilities\ExtendedObservableCollection.cs" />
|
||||
<Compile Include="Utilities\TokenHttpRequestMessage.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Bit.App.Resources;
|
||||
using Bit.App.Utilities;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.App.Models.Page
|
||||
{
|
||||
|
@ -27,14 +28,12 @@ namespace Bit.App.Models.Page
|
|||
public string Uri { get; set; }
|
||||
}
|
||||
|
||||
public class Folder : ObservableCollection<Site>
|
||||
public class Folder : List<Site>
|
||||
{
|
||||
public Folder(IEnumerable<Models.Site> sites, string folderId = null)
|
||||
{
|
||||
foreach(var site in sites)
|
||||
{
|
||||
Items.Add(new Site(site, folderId));
|
||||
}
|
||||
var pageSites = sites.Select(s => new Site(s, folderId));
|
||||
AddRange(pageSites);
|
||||
}
|
||||
|
||||
public Folder(Models.Folder folder, IEnumerable<Models.Site> sites)
|
||||
|
@ -46,7 +45,6 @@ namespace Bit.App.Models.Page
|
|||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; } = AppResources.FolderNone;
|
||||
public string FirstLetter { get { return Name.Substring(0, 1); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ using Bit.App.Models.Page;
|
|||
using Bit.App.Resources;
|
||||
using Xamarin.Forms;
|
||||
using XLabs.Ioc;
|
||||
using Bit.App.Utilities;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
|
@ -29,7 +30,7 @@ namespace Bit.App.Pages
|
|||
Init();
|
||||
}
|
||||
|
||||
public ObservableCollection<VaultListPageModel.Folder> Folders { get; private set; } = new ObservableCollection<VaultListPageModel.Folder>();
|
||||
public ExtendedObservableCollection<VaultListPageModel.Folder> Folders { get; private set; } = new ExtendedObservableCollection<VaultListPageModel.Folder>();
|
||||
|
||||
private void Init()
|
||||
{
|
||||
|
@ -59,20 +60,14 @@ namespace Bit.App.Pages
|
|||
|
||||
private async Task LoadFoldersAsync()
|
||||
{
|
||||
Folders.Clear();
|
||||
|
||||
var folders = await _folderService.GetAllAsync();
|
||||
var sites = await _siteService.GetAllAsync();
|
||||
|
||||
foreach(var folder in folders)
|
||||
{
|
||||
var f = new VaultListPageModel.Folder(folder, sites.Where(s => s.FolderId == folder.Id));
|
||||
Folders.Add(f);
|
||||
}
|
||||
|
||||
// add the sites with no folder
|
||||
var pageFolders = folders.Select(f => new VaultListPageModel.Folder(f, sites.Where(s => s.FolderId == f.Id))).ToList();
|
||||
var noneFolder = new VaultListPageModel.Folder(sites.Where(s => s.FolderId == null));
|
||||
Folders.Add(noneFolder);
|
||||
pageFolders.Add(noneFolder);
|
||||
|
||||
Folders.Reset(pageFolders);
|
||||
}
|
||||
|
||||
private void SiteSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
|
|
33
src/App/Utilities/ExtendedObservableCollection.cs
Normal file
33
src/App/Utilities/ExtendedObservableCollection.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
{
|
||||
public class ExtendedObservableCollection<T> : ObservableCollection<T>
|
||||
{
|
||||
public ExtendedObservableCollection() : base() { }
|
||||
public ExtendedObservableCollection(IEnumerable<T> collection) : base(collection) { }
|
||||
public ExtendedObservableCollection(List<T> list) : base(list) { }
|
||||
|
||||
public void AddRange(IEnumerable<T> range)
|
||||
{
|
||||
foreach(var item in range)
|
||||
{
|
||||
Items.Add(item);
|
||||
}
|
||||
|
||||
OnPropertyChanged(new PropertyChangedEventArgs("Count"));
|
||||
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
public void Reset(IEnumerable<T> range)
|
||||
{
|
||||
Items.Clear();
|
||||
AddRange(range);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue