mirror of
https://github.com/bitwarden/mobile
synced 2025-12-15 07:43:37 +00:00
repurpose vaultlistpage to also serve favorites page
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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>();
|
||||||
@@ -33,8 +35,11 @@ namespace Bit.App.Pages
|
|||||||
public ExtendedObservableCollection<VaultListPageModel.Folder> Folders { get; private set; } = new ExtendedObservableCollection<VaultListPageModel.Folder>();
|
public ExtendedObservableCollection<VaultListPageModel.Folder> Folders { get; private set; } = new ExtendedObservableCollection<VaultListPageModel.Folder>();
|
||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
|
{
|
||||||
|
if(!_favorites)
|
||||||
{
|
{
|
||||||
ToolbarItems.Add(new AddSiteToolBarItem(this));
|
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));
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user