repurpose vaultlistpage to also serve favorites page

This commit is contained in:
Kyle Spearrin 2016-06-14 23:23:05 -04:00
parent 3c14eaf3f8
commit a238523551
6 changed files with 26 additions and 6 deletions

View file

@ -8,5 +8,6 @@ namespace Bit.App.Abstractions
public interface ISiteRepository : IRepository<SiteData, string> public interface ISiteRepository : IRepository<SiteData, string>
{ {
Task<IEnumerable<SiteData>> GetAllByUserIdAsync(string userId); Task<IEnumerable<SiteData>> GetAllByUserIdAsync(string userId);
Task<IEnumerable<SiteData>> GetAllByUserIdAsync(string userId, bool favorite);
} }
} }

View file

@ -9,6 +9,7 @@ namespace Bit.App.Abstractions
{ {
Task<Site> GetByIdAsync(string id); Task<Site> GetByIdAsync(string id);
Task<IEnumerable<Site>> GetAllAsync(); Task<IEnumerable<Site>> GetAllAsync();
Task<IEnumerable<Site>> GetAllAsync(bool favorites);
Task<ApiResult<SiteResponse>> SaveAsync(Site site); Task<ApiResult<SiteResponse>> SaveAsync(Site site);
Task<ApiResult<object>> DeleteAsync(string id); Task<ApiResult<object>> DeleteAsync(string id);
} }

View file

@ -13,8 +13,8 @@ namespace Bit.App.Pages
TintColor = Color.FromHex("ffffff"); TintColor = Color.FromHex("ffffff");
var settingsNavigation = new ExtendedNavigationPage(new SettingsPage()); var settingsNavigation = new ExtendedNavigationPage(new SettingsPage());
var favoritesNavigation = new ExtendedNavigationPage(new VaultListSitesPage()); var favoritesNavigation = new ExtendedNavigationPage(new VaultListSitesPage(true));
var vaultNavigation = new ExtendedNavigationPage(new VaultListSitesPage()); var vaultNavigation = new ExtendedNavigationPage(new VaultListSitesPage(false));
var syncNavigation = new ExtendedNavigationPage(new SyncPage()); var syncNavigation = new ExtendedNavigationPage(new SyncPage());
favoritesNavigation.Title = AppResources.Favorites; favoritesNavigation.Title = AppResources.Favorites;

View file

@ -19,9 +19,11 @@ namespace Bit.App.Pages
private readonly ISiteService _siteService; private readonly ISiteService _siteService;
private readonly IUserDialogs _userDialogs; private readonly IUserDialogs _userDialogs;
private readonly IClipboardService _clipboardService; private readonly IClipboardService _clipboardService;
private readonly bool _favorites;
public VaultListSitesPage() public VaultListSitesPage(bool favorites)
{ {
_favorites = favorites;
_folderService = Resolver.Resolve<IFolderService>(); _folderService = Resolver.Resolve<IFolderService>();
_siteService = Resolver.Resolve<ISiteService>(); _siteService = Resolver.Resolve<ISiteService>();
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();
@ -34,7 +36,10 @@ namespace Bit.App.Pages
private void Init() private void Init()
{ {
ToolbarItems.Add(new AddSiteToolBarItem(this)); if(!_favorites)
{
ToolbarItems.Add(new AddSiteToolBarItem(this));
}
var listView = new ListView var listView = new ListView
{ {
@ -47,7 +52,7 @@ namespace Bit.App.Pages
}; };
listView.ItemSelected += SiteSelected; listView.ItemSelected += SiteSelected;
Title = AppResources.MyVault; Title = _favorites ? AppResources.Favorites : AppResources.MyVault;
Content = listView; Content = listView;
} }
@ -60,7 +65,7 @@ namespace Bit.App.Pages
private async Task LoadFoldersAsync() private async Task LoadFoldersAsync()
{ {
var folders = await _folderService.GetAllAsync(); var folders = await _folderService.GetAllAsync();
var sites = await _siteService.GetAllAsync(); var sites = _favorites ? await _siteService.GetAllAsync(true) : await _siteService.GetAllAsync();
var pageFolders = folders.Select(f => new VaultListPageModel.Folder(f, sites.Where(s => s.FolderId == f.Id))).ToList(); 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)); var noneFolder = new VaultListPageModel.Folder(sites.Where(s => s.FolderId == null));

View file

@ -18,5 +18,11 @@ namespace Bit.App.Repositories
var sites = Connection.Table<SiteData>().Where(f => f.UserId == userId).Cast<SiteData>(); var sites = Connection.Table<SiteData>().Where(f => f.UserId == userId).Cast<SiteData>();
return Task.FromResult(sites); return Task.FromResult(sites);
} }
public Task<IEnumerable<SiteData>> GetAllByUserIdAsync(string userId, bool favorite)
{
var sites = Connection.Table<SiteData>().Where(f => f.UserId == userId && f.Favorite == favorite).Cast<SiteData>();
return Task.FromResult(sites);
}
} }
} }

View file

@ -44,6 +44,13 @@ namespace Bit.App.Services
return sites; return sites;
} }
public async Task<IEnumerable<Site>> GetAllAsync(bool favorites)
{
var data = await _siteRepository.GetAllByUserIdAsync(_authService.UserId, favorites);
var sites = data.Select(f => new Site(f));
return sites;
}
public async Task<ApiResult<SiteResponse>> SaveAsync(Site site) public async Task<ApiResult<SiteResponse>> SaveAsync(Site site)
{ {
ApiResult<SiteResponse> response = null; ApiResult<SiteResponse> response = null;