From a23852355119fb9c4d20f67d112706b8e3657fde Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 14 Jun 2016 23:23:05 -0400 Subject: [PATCH] repurpose vaultlistpage to also serve favorites page --- .../Abstractions/Repositories/ISiteRepository.cs | 1 + src/App/Abstractions/Services/ISiteService.cs | 1 + src/App/Pages/MainPage.cs | 4 ++-- src/App/Pages/VaultListSitesPage.cs | 13 +++++++++---- src/App/Repositories/SiteRepository.cs | 6 ++++++ src/App/Services/SiteService.cs | 7 +++++++ 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/App/Abstractions/Repositories/ISiteRepository.cs b/src/App/Abstractions/Repositories/ISiteRepository.cs index c16edea2b..48169bae4 100644 --- a/src/App/Abstractions/Repositories/ISiteRepository.cs +++ b/src/App/Abstractions/Repositories/ISiteRepository.cs @@ -8,5 +8,6 @@ namespace Bit.App.Abstractions public interface ISiteRepository : IRepository { Task> GetAllByUserIdAsync(string userId); + Task> GetAllByUserIdAsync(string userId, bool favorite); } } diff --git a/src/App/Abstractions/Services/ISiteService.cs b/src/App/Abstractions/Services/ISiteService.cs index 0f3bde43a..1b828c35d 100644 --- a/src/App/Abstractions/Services/ISiteService.cs +++ b/src/App/Abstractions/Services/ISiteService.cs @@ -9,6 +9,7 @@ namespace Bit.App.Abstractions { Task GetByIdAsync(string id); Task> GetAllAsync(); + Task> GetAllAsync(bool favorites); Task> SaveAsync(Site site); Task> DeleteAsync(string id); } diff --git a/src/App/Pages/MainPage.cs b/src/App/Pages/MainPage.cs index f354a470f..85303a2ea 100644 --- a/src/App/Pages/MainPage.cs +++ b/src/App/Pages/MainPage.cs @@ -13,8 +13,8 @@ namespace Bit.App.Pages TintColor = Color.FromHex("ffffff"); var settingsNavigation = new ExtendedNavigationPage(new SettingsPage()); - var favoritesNavigation = new ExtendedNavigationPage(new VaultListSitesPage()); - var vaultNavigation = new ExtendedNavigationPage(new VaultListSitesPage()); + var favoritesNavigation = new ExtendedNavigationPage(new VaultListSitesPage(true)); + var vaultNavigation = new ExtendedNavigationPage(new VaultListSitesPage(false)); var syncNavigation = new ExtendedNavigationPage(new SyncPage()); favoritesNavigation.Title = AppResources.Favorites; diff --git a/src/App/Pages/VaultListSitesPage.cs b/src/App/Pages/VaultListSitesPage.cs index 2f07d60e3..1afcbe88f 100644 --- a/src/App/Pages/VaultListSitesPage.cs +++ b/src/App/Pages/VaultListSitesPage.cs @@ -19,9 +19,11 @@ namespace Bit.App.Pages private readonly ISiteService _siteService; private readonly IUserDialogs _userDialogs; private readonly IClipboardService _clipboardService; + private readonly bool _favorites; - public VaultListSitesPage() + public VaultListSitesPage(bool favorites) { + _favorites = favorites; _folderService = Resolver.Resolve(); _siteService = Resolver.Resolve(); _userDialogs = Resolver.Resolve(); @@ -34,7 +36,10 @@ namespace Bit.App.Pages private void Init() { - ToolbarItems.Add(new AddSiteToolBarItem(this)); + if(!_favorites) + { + ToolbarItems.Add(new AddSiteToolBarItem(this)); + } var listView = new ListView { @@ -47,7 +52,7 @@ namespace Bit.App.Pages }; listView.ItemSelected += SiteSelected; - Title = AppResources.MyVault; + Title = _favorites ? AppResources.Favorites : AppResources.MyVault; Content = listView; } @@ -60,7 +65,7 @@ namespace Bit.App.Pages private async Task LoadFoldersAsync() { 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 noneFolder = new VaultListPageModel.Folder(sites.Where(s => s.FolderId == null)); diff --git a/src/App/Repositories/SiteRepository.cs b/src/App/Repositories/SiteRepository.cs index 1c76cd0b3..3dbe90775 100644 --- a/src/App/Repositories/SiteRepository.cs +++ b/src/App/Repositories/SiteRepository.cs @@ -18,5 +18,11 @@ namespace Bit.App.Repositories var sites = Connection.Table().Where(f => f.UserId == userId).Cast(); return Task.FromResult(sites); } + + public Task> GetAllByUserIdAsync(string userId, bool favorite) + { + var sites = Connection.Table().Where(f => f.UserId == userId && f.Favorite == favorite).Cast(); + return Task.FromResult(sites); + } } } diff --git a/src/App/Services/SiteService.cs b/src/App/Services/SiteService.cs index f993d2e6f..421ecdc4f 100644 --- a/src/App/Services/SiteService.cs +++ b/src/App/Services/SiteService.cs @@ -44,6 +44,13 @@ namespace Bit.App.Services return sites; } + public async Task> GetAllAsync(bool favorites) + { + var data = await _siteRepository.GetAllByUserIdAsync(_authService.UserId, favorites); + var sites = data.Select(f => new Site(f)); + return sites; + } + public async Task> SaveAsync(Site site) { ApiResult response = null;