Generate password cell added to add/edit site pages. Delete callback from generate password page.

This commit is contained in:
Kyle Spearrin 2016-07-07 00:27:29 -04:00
parent b7869ed763
commit 6b996e3a98
3 changed files with 74 additions and 29 deletions

View file

@ -16,13 +16,15 @@ namespace Bit.App.Pages
private readonly IPasswordGenerationService _passwordGenerationService; private readonly IPasswordGenerationService _passwordGenerationService;
private readonly ISettings _settings; private readonly ISettings _settings;
private readonly IClipboardService _clipboardService; private readonly IClipboardService _clipboardService;
private readonly Action<string> _passwordValueAction;
public ToolsPasswordGeneratorPage() public ToolsPasswordGeneratorPage(Action<string> passwordValueAction = null)
{ {
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();
_passwordGenerationService = Resolver.Resolve<IPasswordGenerationService>(); _passwordGenerationService = Resolver.Resolve<IPasswordGenerationService>();
_settings = Resolver.Resolve<ISettings>(); _settings = Resolver.Resolve<ISettings>();
_clipboardService = Resolver.Resolve<IClipboardService>(); _clipboardService = Resolver.Resolve<IClipboardService>();
_passwordValueAction = passwordValueAction;
Init(); Init();
} }
@ -57,8 +59,6 @@ namespace Bit.App.Pages
regenerateCell.Tapped += RegenerateCell_Tapped; ; regenerateCell.Tapped += RegenerateCell_Tapped; ;
var copyCell = new ExtendedTextCell { Text = "Copy Password", TextColor = buttonColor }; var copyCell = new ExtendedTextCell { Text = "Copy Password", TextColor = buttonColor };
copyCell.Tapped += CopyCell_Tapped; copyCell.Tapped += CopyCell_Tapped;
var saveCell = new ExtendedTextCell { Text = "Save Password", TextColor = buttonColor };
saveCell.Tapped += SaveCell_Tapped;
var table = new ExtendedTableView var table = new ExtendedTableView
{ {
@ -78,10 +78,6 @@ namespace Bit.App.Pages
{ {
regenerateCell, regenerateCell,
copyCell copyCell
},
new TableSection
{
saveCell
} }
} }
}; };
@ -90,7 +86,7 @@ namespace Bit.App.Pages
{ {
table.RowHeight = -1; table.RowHeight = -1;
table.EstimatedRowHeight = 44; table.EstimatedRowHeight = 44;
ToolbarItems.Add(new DismissModalToolBarItem(this, "Close")); ToolbarItems.Add(new DismissModalToolBarItem(this, _passwordValueAction == null ? "Close" : "Cancel"));
} }
var stackLayout = new StackLayout var stackLayout = new StackLayout
@ -108,6 +104,15 @@ namespace Bit.App.Pages
VerticalOptions = LayoutOptions.FillAndExpand VerticalOptions = LayoutOptions.FillAndExpand
}; };
var selectToolBarItem = new ToolbarItem("Select", null, async () =>
{
_passwordValueAction(Password.Text);
await Navigation.PopModalAsync();
}, ToolbarItemOrder.Default, 0);
ToolbarItems.Add(selectToolBarItem);
Title = "Generate Password"; Title = "Generate Password";
Content = scrollView; Content = scrollView;
BindingContext = Model; BindingContext = Model;
@ -130,11 +135,6 @@ namespace Bit.App.Pages
Model.Password = _passwordGenerationService.GeneratePassword(); Model.Password = _passwordGenerationService.GeneratePassword();
} }
private void SaveCell_Tapped(object sender, EventArgs e)
{
}
private void CopyCell_Tapped(object sender, EventArgs e) private void CopyCell_Tapped(object sender, EventArgs e)
{ {
CopyPassword(); CopyPassword();

View file

@ -29,15 +29,17 @@ namespace Bit.App.Pages
Init(); Init();
} }
public FormEntryCell PasswordCell { get; private set; }
private void Init() private void Init()
{ {
var notesCell = new FormEditorCell(height: 90); var notesCell = new FormEditorCell(height: 90);
var passwordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor); PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: passwordCell.Entry); var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
usernameCell.Entry.DisableAutocapitalize = true; usernameCell.Entry.DisableAutocapitalize = true;
usernameCell.Entry.Autocorrect = false; usernameCell.Entry.Autocorrect = false;
usernameCell.Entry.FontFamily = passwordCell.Entry.FontFamily = "Courier"; usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = "Courier";
var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry); var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry); var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry);
@ -50,6 +52,13 @@ namespace Bit.App.Pages
} }
var folderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); var folderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray());
var generateCell = new ExtendedTextCell
{
Text = "Generate Password",
ShowDisclousure = true
};
generateCell.Tapped += GenerateCell_Tapped; ;
var favoriteCell = new ExtendedSwitchCell { Text = "Favorite" }; var favoriteCell = new ExtendedSwitchCell { Text = "Favorite" };
var table = new ExtendedTableView var table = new ExtendedTableView
@ -57,7 +66,6 @@ namespace Bit.App.Pages
Intent = TableIntent.Settings, Intent = TableIntent.Settings,
EnableScrolling = true, EnableScrolling = true,
HasUnevenRows = true, HasUnevenRows = true,
EnableSelection = false,
Root = new TableRoot Root = new TableRoot
{ {
new TableSection("Site Information") new TableSection("Site Information")
@ -65,11 +73,12 @@ namespace Bit.App.Pages
nameCell, nameCell,
uriCell, uriCell,
usernameCell, usernameCell,
passwordCell, PasswordCell,
folderCell generateCell
}, },
new TableSection new TableSection
{ {
folderCell,
favoriteCell favoriteCell
}, },
new TableSection(AppResources.Notes) new TableSection(AppResources.Notes)
@ -93,7 +102,7 @@ namespace Bit.App.Pages
return; return;
} }
if(string.IsNullOrWhiteSpace(passwordCell.Entry.Text)) if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
{ {
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok); await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok);
return; return;
@ -110,7 +119,7 @@ namespace Bit.App.Pages
Uri = uriCell.Entry.Text?.Encrypt(), Uri = uriCell.Entry.Text?.Encrypt(),
Name = nameCell.Entry.Text?.Encrypt(), Name = nameCell.Entry.Text?.Encrypt(),
Username = usernameCell.Entry.Text?.Encrypt(), Username = usernameCell.Entry.Text?.Encrypt(),
Password = passwordCell.Entry.Text?.Encrypt(), Password = PasswordCell.Entry.Text?.Encrypt(),
Notes = notesCell.Editor.Text?.Encrypt(), Notes = notesCell.Editor.Text?.Encrypt(),
Favorite = favoriteCell.On Favorite = favoriteCell.On
}; };
@ -143,6 +152,16 @@ namespace Bit.App.Pages
} }
} }
private void GenerateCell_Tapped(object sender, EventArgs e)
{
var page = new ToolsPasswordGeneratorPage((password) =>
{
PasswordCell.Entry.Text = password;
_userDialogs.SuccessToast("Password generated.");
});
Navigation.PushModalAsync(new ExtendedNavigationPage(page));
}
private void AlertNoConnection() private void AlertNoConnection()
{ {
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok); DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);

View file

@ -30,6 +30,8 @@ namespace Bit.App.Pages
Init(); Init();
} }
public FormEntryCell PasswordCell { get; private set; }
private void Init() private void Init()
{ {
var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult(); var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult();
@ -41,20 +43,27 @@ namespace Bit.App.Pages
var notesCell = new FormEditorCell(height: 90); var notesCell = new FormEditorCell(height: 90);
notesCell.Editor.Text = site.Notes?.Decrypt(); notesCell.Editor.Text = site.Notes?.Decrypt();
var passwordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor); PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
passwordCell.Entry.Text = site.Password?.Decrypt(); PasswordCell.Entry.Text = site.Password?.Decrypt();
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: passwordCell.Entry); var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
usernameCell.Entry.Text = site.Username?.Decrypt(); usernameCell.Entry.Text = site.Username?.Decrypt();
usernameCell.Entry.DisableAutocapitalize = true; usernameCell.Entry.DisableAutocapitalize = true;
usernameCell.Entry.Autocorrect = false; usernameCell.Entry.Autocorrect = false;
usernameCell.Entry.FontFamily = passwordCell.Entry.FontFamily = "Courier"; usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = "Courier";
var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry); var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
uriCell.Entry.Text = site.Uri?.Decrypt(); uriCell.Entry.Text = site.Uri?.Decrypt();
var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry); var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry);
nameCell.Entry.Text = site.Name?.Decrypt(); nameCell.Entry.Text = site.Name?.Decrypt();
var generateCell = new ExtendedTextCell
{
Text = "Generate Password",
ShowDisclousure = true
};
generateCell.Tapped += GenerateCell_Tapped; ;
var folderOptions = new List<string> { AppResources.FolderNone }; var folderOptions = new List<string> { AppResources.FolderNone };
var folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy(f => f.Name?.Decrypt()); var folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy(f => f.Name?.Decrypt());
int selectedIndex = 0; int selectedIndex = 0;
@ -93,11 +102,12 @@ namespace Bit.App.Pages
nameCell, nameCell,
uriCell, uriCell,
usernameCell, usernameCell,
passwordCell, PasswordCell,
folderCell generateCell
}, },
new TableSection new TableSection
{ {
folderCell,
favoriteCell favoriteCell
}, },
new TableSection(AppResources.Notes) new TableSection(AppResources.Notes)
@ -125,7 +135,7 @@ namespace Bit.App.Pages
return; return;
} }
if(string.IsNullOrWhiteSpace(passwordCell.Entry.Text)) if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
{ {
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok); await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok);
return; return;
@ -140,7 +150,7 @@ namespace Bit.App.Pages
site.Uri = uriCell.Entry.Text?.Encrypt(); site.Uri = uriCell.Entry.Text?.Encrypt();
site.Name = nameCell.Entry.Text?.Encrypt(); site.Name = nameCell.Entry.Text?.Encrypt();
site.Username = usernameCell.Entry.Text?.Encrypt(); site.Username = usernameCell.Entry.Text?.Encrypt();
site.Password = passwordCell.Entry.Text?.Encrypt(); site.Password = PasswordCell.Entry.Text?.Encrypt();
site.Notes = notesCell.Editor.Text?.Encrypt(); site.Notes = notesCell.Editor.Text?.Encrypt();
site.Favorite = favoriteCell.On; site.Favorite = favoriteCell.On;
@ -176,6 +186,22 @@ namespace Bit.App.Pages
} }
} }
private async void GenerateCell_Tapped(object sender, EventArgs e)
{
if(!string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)
&& !await _userDialogs.ConfirmAsync("Are you sure you want to overwrite the current password?", null, AppResources.Yes, AppResources.No))
{
return;
}
var page = new ToolsPasswordGeneratorPage((password) =>
{
PasswordCell.Entry.Text = password;
_userDialogs.SuccessToast("Password generated.");
});
await Navigation.PushModalAsync(new ExtendedNavigationPage(page));
}
private async void DeleteCell_Tapped(object sender, EventArgs e) private async void DeleteCell_Tapped(object sender, EventArgs e)
{ {
if(!_connectivity.IsConnected) if(!_connectivity.IsConnected)