From b7869ed763928e7a00f169657ec25ad66508a0e1 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 7 Jul 2016 00:00:12 -0400 Subject: [PATCH] order names in vault. getbyid can now return null if not found (use find instead of get) --- src/App/Models/Page/VaultListPageModel.cs | 2 +- .../Pages/Settings/SettingsEditFolderPage.cs | 6 ++++ src/App/Pages/Settings/SettingsPage.cs | 20 +++++++++++- src/App/Pages/Vault/VaultEditSitePage.cs | 32 +++++++++++++++++++ src/App/Pages/Vault/VaultListSitesPage.cs | 3 +- src/App/Pages/Vault/VaultViewSitePage.cs | 6 ++-- src/App/Repositories/Repository.cs | 2 +- 7 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/App/Models/Page/VaultListPageModel.cs b/src/App/Models/Page/VaultListPageModel.cs index 623ebf739..e2456be16 100644 --- a/src/App/Models/Page/VaultListPageModel.cs +++ b/src/App/Models/Page/VaultListPageModel.cs @@ -32,7 +32,7 @@ namespace Bit.App.Models.Page { public Folder(IEnumerable sites, string folderId = null) { - var pageSites = sites.Select(s => new Site(s, folderId)); + var pageSites = sites.Select(s => new Site(s, folderId)).OrderBy(s => s.Name); AddRange(pageSites); } diff --git a/src/App/Pages/Settings/SettingsEditFolderPage.cs b/src/App/Pages/Settings/SettingsEditFolderPage.cs index 74e1dc03d..dd4c6635c 100644 --- a/src/App/Pages/Settings/SettingsEditFolderPage.cs +++ b/src/App/Pages/Settings/SettingsEditFolderPage.cs @@ -107,6 +107,12 @@ namespace Bit.App.Pages private async void DeleteCell_Tapped(object sender, EventArgs e) { + if(!_connectivity.IsConnected) + { + AlertNoConnection(); + return; + } + // TODO: Validate the delete operation. ex. Cannot delete a folder that has sites in it? if(!await _userDialogs.ConfirmAsync(AppResources.DoYouReallyWantToDelete, null, AppResources.Yes, AppResources.No)) diff --git a/src/App/Pages/Settings/SettingsPage.cs b/src/App/Pages/Settings/SettingsPage.cs index e230b5cb7..e8eef922e 100644 --- a/src/App/Pages/Settings/SettingsPage.cs +++ b/src/App/Pages/Settings/SettingsPage.cs @@ -68,6 +68,13 @@ namespace Bit.App.Pages }; changeMasterPasswordCell.Tapped += ChangeMasterPasswordCell_Tapped; + var changeEmailCell = new ExtendedTextCell + { + Text = "Change Email", + ShowDisclousure = true + }; + changeEmailCell.Tapped += ChangeEmailCell_Tapped; + var foldersCell = new ExtendedTextCell { Text = "Folders", @@ -106,7 +113,8 @@ namespace Bit.App.Pages LockOptionsCell, FingerprintCell, PinCell, - changeMasterPasswordCell + changeMasterPasswordCell, + changeEmailCell }, new TableSection("Manage") { @@ -205,6 +213,16 @@ namespace Bit.App.Pages Device.OpenUri(new Uri("https://vault.bitwarden.com")); } + private async void ChangeEmailCell_Tapped(object sender, EventArgs e) + { + if(!await _userDialogs.ConfirmAsync("You can change your email address on the bitwarden.com web vault. Do you want to visit the website now?", null, AppResources.Yes, AppResources.Cancel)) + { + return; + } + + Device.OpenUri(new Uri("https://vault.bitwarden.com")); + } + private void FingerprintCell_Changed(object sender, EventArgs e) { var cell = sender as ExtendedSwitchCell; diff --git a/src/App/Pages/Vault/VaultEditSitePage.cs b/src/App/Pages/Vault/VaultEditSitePage.cs index 4f728e59e..e13ed9099 100644 --- a/src/App/Pages/Vault/VaultEditSitePage.cs +++ b/src/App/Pages/Vault/VaultEditSitePage.cs @@ -78,6 +78,9 @@ namespace Bit.App.Pages On = site.Favorite }; + var deleteCell = new ExtendedTextCell { Text = AppResources.Delete, TextColor = Color.Red }; + deleteCell.Tapped += DeleteCell_Tapped; + var table = new ExtendedTableView { Intent = TableIntent.Settings, @@ -100,6 +103,10 @@ namespace Bit.App.Pages new TableSection(AppResources.Notes) { notesCell + }, + new TableSection + { + deleteCell } } }; @@ -169,6 +176,31 @@ namespace Bit.App.Pages } } + private async void DeleteCell_Tapped(object sender, EventArgs e) + { + if(!_connectivity.IsConnected) + { + AlertNoConnection(); + return; + } + + if(!await _userDialogs.ConfirmAsync(AppResources.DoYouReallyWantToDelete, null, AppResources.Yes, AppResources.No)) + { + return; + } + + var deleteTask = _siteService.DeleteAsync(_siteId); + _userDialogs.ShowLoading("Deleting...", MaskType.Black); + await deleteTask; + _userDialogs.HideLoading(); + + if((await deleteTask).Succeeded) + { + await Navigation.PopModalAsync(); + _userDialogs.SuccessToast("Site deleted."); + } + } + private void AlertNoConnection() { DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok); diff --git a/src/App/Pages/Vault/VaultListSitesPage.cs b/src/App/Pages/Vault/VaultListSitesPage.cs index 399fc01dc..4bebed455 100644 --- a/src/App/Pages/Vault/VaultListSitesPage.cs +++ b/src/App/Pages/Vault/VaultListSitesPage.cs @@ -106,7 +106,8 @@ namespace Bit.App.Pages var folders = await _folderService.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))).OrderBy(f => f.Name).ToList(); var noneFolder = new VaultListPageModel.Folder(sites.Where(s => s.FolderId == null)); pageFolders.Add(noneFolder); diff --git a/src/App/Pages/Vault/VaultViewSitePage.cs b/src/App/Pages/Vault/VaultViewSitePage.cs index 253cb295b..c7d12a201 100644 --- a/src/App/Pages/Vault/VaultViewSitePage.cs +++ b/src/App/Pages/Vault/VaultViewSitePage.cs @@ -109,12 +109,12 @@ namespace Bit.App.Pages BindingContext = Model; } - protected override void OnAppearing() + protected async override void OnAppearing() { - var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult(); + var site = await _siteService.GetByIdAsync(_siteId); if(site == null) { - // TODO: handle error. navigate back? should never happen... + await Navigation.PopModalAsync(); return; } diff --git a/src/App/Repositories/Repository.cs b/src/App/Repositories/Repository.cs index 4f5799e0b..54b4af6b2 100644 --- a/src/App/Repositories/Repository.cs +++ b/src/App/Repositories/Repository.cs @@ -20,7 +20,7 @@ namespace Bit.App.Repositories public virtual Task GetByIdAsync(TId id) { - return Task.FromResult(Connection.Get(id)); + return Task.FromResult(Connection.Find(id)); } public virtual Task> GetAllAsync()