mirror of
https://github.com/bitwarden/android.git
synced 2024-12-20 08:12:26 +03:00
repurpose vaultlistpage to also serve favorites page
This commit is contained in:
parent
3c14eaf3f8
commit
a238523551
6 changed files with 26 additions and 6 deletions
|
@ -8,5 +8,6 @@ namespace Bit.App.Abstractions
|
|||
public interface ISiteRepository : IRepository<SiteData, string>
|
||||
{
|
||||
Task<IEnumerable<SiteData>> GetAllByUserIdAsync(string userId);
|
||||
Task<IEnumerable<SiteData>> GetAllByUserIdAsync(string userId, bool favorite);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Bit.App.Abstractions
|
|||
{
|
||||
Task<Site> GetByIdAsync(string id);
|
||||
Task<IEnumerable<Site>> GetAllAsync();
|
||||
Task<IEnumerable<Site>> GetAllAsync(bool favorites);
|
||||
Task<ApiResult<SiteResponse>> SaveAsync(Site site);
|
||||
Task<ApiResult<object>> DeleteAsync(string id);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<IFolderService>();
|
||||
_siteService = Resolver.Resolve<ISiteService>();
|
||||
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
||||
|
@ -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));
|
||||
|
|
|
@ -18,5 +18,11 @@ namespace Bit.App.Repositories
|
|||
var sites = Connection.Table<SiteData>().Where(f => f.UserId == userId).Cast<SiteData>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,13 @@ namespace Bit.App.Services
|
|||
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)
|
||||
{
|
||||
ApiResult<SiteResponse> response = null;
|
||||
|
|
Loading…
Reference in a new issue