1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-25 10:26:02 +02:00

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

View File

@ -29,15 +29,17 @@ namespace Bit.App.Pages
Init();
}
public FormEntryCell PasswordCell { get; private set; }
private void Init()
{
var notesCell = new FormEditorCell(height: 90);
var passwordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: passwordCell.Entry);
PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
usernameCell.Entry.DisableAutocapitalize = true;
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 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 generateCell = new ExtendedTextCell
{
Text = "Generate Password",
ShowDisclousure = true
};
generateCell.Tapped += GenerateCell_Tapped; ;
var favoriteCell = new ExtendedSwitchCell { Text = "Favorite" };
var table = new ExtendedTableView
@ -57,7 +66,6 @@ namespace Bit.App.Pages
Intent = TableIntent.Settings,
EnableScrolling = true,
HasUnevenRows = true,
EnableSelection = false,
Root = new TableRoot
{
new TableSection("Site Information")
@ -65,11 +73,12 @@ namespace Bit.App.Pages
nameCell,
uriCell,
usernameCell,
passwordCell,
folderCell
PasswordCell,
generateCell
},
new TableSection
{
folderCell,
favoriteCell
},
new TableSection(AppResources.Notes)
@ -93,7 +102,7 @@ namespace Bit.App.Pages
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);
return;
@ -110,7 +119,7 @@ namespace Bit.App.Pages
Uri = uriCell.Entry.Text?.Encrypt(),
Name = nameCell.Entry.Text?.Encrypt(),
Username = usernameCell.Entry.Text?.Encrypt(),
Password = passwordCell.Entry.Text?.Encrypt(),
Password = PasswordCell.Entry.Text?.Encrypt(),
Notes = notesCell.Editor.Text?.Encrypt(),
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()
{
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);

View File

@ -30,6 +30,8 @@ namespace Bit.App.Pages
Init();
}
public FormEntryCell PasswordCell { get; private set; }
private void Init()
{
var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult();
@ -41,20 +43,27 @@ namespace Bit.App.Pages
var notesCell = new FormEditorCell(height: 90);
notesCell.Editor.Text = site.Notes?.Decrypt();
var passwordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
passwordCell.Entry.Text = site.Password?.Decrypt();
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: passwordCell.Entry);
PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
PasswordCell.Entry.Text = site.Password?.Decrypt();
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
usernameCell.Entry.Text = site.Username?.Decrypt();
usernameCell.Entry.DisableAutocapitalize = true;
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);
uriCell.Entry.Text = site.Uri?.Decrypt();
var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry);
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 folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy(f => f.Name?.Decrypt());
int selectedIndex = 0;
@ -93,11 +102,12 @@ namespace Bit.App.Pages
nameCell,
uriCell,
usernameCell,
passwordCell,
folderCell
PasswordCell,
generateCell
},
new TableSection
{
folderCell,
favoriteCell
},
new TableSection(AppResources.Notes)
@ -125,7 +135,7 @@ namespace Bit.App.Pages
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);
return;
@ -140,7 +150,7 @@ namespace Bit.App.Pages
site.Uri = uriCell.Entry.Text?.Encrypt();
site.Name = nameCell.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.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)
{
if(!_connectivity.IsConnected)