private void Init() { // Name NameCell = new FormEntryCell(AppResources.Name); if (!string.IsNullOrWhiteSpace(_defaultName)) { NameCell.Entry.Text = _defaultName; } // Notes NotesCell = new FormEditorCell(Keyboard.Text, _type == CipherType.SecureNote ? 500 : 180); // Folders var folderOptions = new List <string> { AppResources.FolderNone }; Folders = _folderService.GetAllAsync().GetAwaiter().GetResult() .OrderBy(f => f.Name?.Decrypt()).ToList(); var selectedIndex = 0; var i = 1; foreach (var folder in Folders) { if (folder.Id == _defaultFolderId) { selectedIndex = i; } folderOptions.Add(folder.Name.Decrypt()); i++; } FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); FolderCell.Picker.SelectedIndex = selectedIndex; // Favorite FavoriteCell = new ExtendedSwitchCell { Text = AppResources.Favorite }; InitTable(); InitSave(); Title = AppResources.AddItem; Content = Table; if (Device.RuntimePlatform == Device.iOS) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } }
private void Init() { var login = _loginService.GetByIdAsync(_loginId).GetAwaiter().GetResult(); if (login == null) { // TODO: handle error. navigate back? should never happen... return; } NotesCell = new FormEditorCell(height: 90); NotesCell.Editor.Text = login.Notes?.Decrypt(); PasswordCell = new FormEntryCell(AppResources.Password, isPassword: true, nextElement: NotesCell.Editor, useButton: true); PasswordCell.Entry.Text = login.Password?.Decrypt(); PasswordCell.Button.Image = "eye"; PasswordCell.Entry.DisableAutocapitalize = true; PasswordCell.Entry.Autocorrect = false; PasswordCell.Entry.FontFamily = Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier"); UsernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry); UsernameCell.Entry.Text = login.Username?.Decrypt(); UsernameCell.Entry.DisableAutocapitalize = true; UsernameCell.Entry.Autocorrect = false; UriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: UsernameCell.Entry); UriCell.Entry.Text = login.Uri?.Decrypt(); NameCell = new FormEntryCell(AppResources.Name, nextElement: UriCell.Entry); NameCell.Entry.Text = login.Name?.Decrypt(); GenerateCell = new ExtendedTextCell { Text = AppResources.GeneratePassword, ShowDisclousure = true }; var folderOptions = new List <string> { AppResources.FolderNone }; var folders = _folderService.GetAllAsync().GetAwaiter().GetResult() .OrderBy(f => f.Name?.Decrypt()).ToList(); int selectedIndex = 0; int i = 0; foreach (var folder in folders) { i++; if (folder.Id == login.FolderId) { selectedIndex = i; } folderOptions.Add(folder.Name.Decrypt()); } FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); FolderCell.Picker.SelectedIndex = selectedIndex; var favoriteCell = new ExtendedSwitchCell { Text = AppResources.Favorite, On = login.Favorite }; DeleteCell = new ExtendedTextCell { Text = AppResources.Delete, TextColor = Color.Red }; var table = new ExtendedTableView { Intent = TableIntent.Settings, EnableScrolling = true, HasUnevenRows = true, Root = new TableRoot { new TableSection(AppResources.LoginInformation) { NameCell, UriCell, UsernameCell, PasswordCell, GenerateCell }, new TableSection { FolderCell, favoriteCell }, new TableSection(AppResources.Notes) { NotesCell }, new TableSection { DeleteCell } } }; if (Device.OS == TargetPlatform.iOS) { table.RowHeight = -1; table.EstimatedRowHeight = 70; } else if (Device.OS == TargetPlatform.Android) { PasswordCell.Button.WidthRequest = 40; } var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() => { if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (string.IsNullOrWhiteSpace(NameCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); return; } login.Uri = UriCell.Entry.Text?.Encrypt(); login.Name = NameCell.Entry.Text?.Encrypt(); login.Username = UsernameCell.Entry.Text?.Encrypt(); login.Password = PasswordCell.Entry.Text?.Encrypt(); login.Notes = NotesCell.Editor.Text?.Encrypt(); login.Favorite = favoriteCell.On; if (FolderCell.Picker.SelectedIndex > 0) { login.FolderId = folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id; } else { login.FolderId = null; } _userDialogs.ShowLoading(AppResources.Saving, MaskType.Black); var saveTask = await _loginService.SaveAsync(login); _userDialogs.HideLoading(); if (saveTask.Succeeded) { await Navigation.PopForDeviceAsync(); _userDialogs.Toast(AppResources.LoginUpdated); _googleAnalyticsService.TrackAppEvent("EditeLogin"); } else if (saveTask.Errors.Count() > 0) { await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred); } else { await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); } }, ToolbarItemOrder.Default, 0); Title = AppResources.EditLogin; Content = table; ToolbarItems.Add(saveToolBarItem); if (Device.OS == TargetPlatform.iOS) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } }
private void Init() { Cipher = _cipherService.GetByIdAsync(_cipherId).GetAwaiter().GetResult(); if (Cipher == null) { // TODO: handle error. navigate back? should never happen... return; } // Name NameCell = new FormEntryCell(AppResources.Name); NameCell.Entry.Text = Cipher.Name?.Decrypt(Cipher.OrganizationId); // Notes NotesCell = new FormEditorCell(Keyboard.Text, Cipher.Type == CipherType.SecureNote ? 500 : 180); NotesCell.Editor.Text = Cipher.Notes?.Decrypt(Cipher.OrganizationId); // Folders var folderOptions = new List <string> { AppResources.FolderNone }; Folders = _folderService.GetAllAsync().GetAwaiter().GetResult() .OrderBy(f => f.Name?.Decrypt()).ToList(); int selectedIndex = 0; int i = 0; foreach (var folder in Folders) { i++; if (folder.Id == Cipher.FolderId) { selectedIndex = i; } folderOptions.Add(folder.Name.Decrypt()); } FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); FolderCell.Picker.SelectedIndex = selectedIndex; // Favorite FavoriteCell = new ExtendedSwitchCell { Text = AppResources.Favorite, On = Cipher.Favorite }; // Delete DeleteCell = new ExtendedTextCell { Text = AppResources.Delete, TextColor = Color.Red }; InitTable(); InitSave(); Title = AppResources.EditItem; Content = Table; if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } }
private void Init() { var notesCell = new FormEditorCell(height: 90); PasswordCell = new FormEntryCell(AppResources.Password, isPassword: true, nextElement: notesCell.Editor, useButton: true); PasswordCell.Button.Image = "eye"; PasswordCell.Button.Clicked += PasswordButton_Clicked; PasswordCell.Entry.DisableAutocapitalize = true; PasswordCell.Entry.Autocorrect = false; PasswordCell.Entry.FontFamily = Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier"); var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry); usernameCell.Entry.DisableAutocapitalize = true; usernameCell.Entry.Autocorrect = false; var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry); var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry); var folderOptions = new List <string> { AppResources.FolderNone }; var folders = _folderService.GetAllAsync().GetAwaiter().GetResult() .OrderBy(f => f.Name?.Decrypt()).ToList(); foreach (var folder in folders) { folderOptions.Add(folder.Name.Decrypt()); } var folderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); var generateCell = new ExtendedTextCell { Text = AppResources.GeneratePassword, ShowDisclousure = true }; generateCell.Tapped += GenerateCell_Tapped;; var favoriteCell = new ExtendedSwitchCell { Text = AppResources.Favorite }; var table = new ExtendedTableView { Intent = TableIntent.Settings, EnableScrolling = true, HasUnevenRows = true, Root = new TableRoot { new TableSection(AppResources.SiteInformation) { nameCell, uriCell, usernameCell, PasswordCell, generateCell }, new TableSection { folderCell, favoriteCell }, new TableSection(AppResources.Notes) { notesCell } } }; if (Device.OS == TargetPlatform.iOS) { table.RowHeight = -1; table.EstimatedRowHeight = 70; } else if (Device.OS == TargetPlatform.Android) { PasswordCell.Button.WidthRequest = 40; } var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() => { if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (string.IsNullOrWhiteSpace(nameCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); return; } var site = new Site { Uri = uriCell.Entry.Text?.Encrypt(), Name = nameCell.Entry.Text?.Encrypt(), Username = usernameCell.Entry.Text?.Encrypt(), Password = PasswordCell.Entry.Text?.Encrypt(), Notes = notesCell.Editor.Text?.Encrypt(), Favorite = favoriteCell.On }; if (folderCell.Picker.SelectedIndex > 0) { site.FolderId = folders.ElementAt(folderCell.Picker.SelectedIndex - 1).Id; } _userDialogs.ShowLoading(AppResources.Saving, MaskType.Black); var saveTask = await _siteService.SaveAsync(site); _userDialogs.HideLoading(); if (saveTask.Succeeded) { await Navigation.PopForDeviceAsync(); _userDialogs.Toast(AppResources.NewSiteCreated); _googleAnalyticsService.TrackAppEvent("CreatedSite"); } else if (saveTask.Errors.Count() > 0) { await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred); } else { await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); } }, ToolbarItemOrder.Default, 0); Title = AppResources.AddSite; Content = table; ToolbarItems.Add(saveToolBarItem); if (Device.OS == TargetPlatform.iOS) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } }
private void Init() { NotesCell = new FormEditorCell(height: 180); NotesCell.Editor.Keyboard = Keyboard.Text; TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor, useButton: _deviceInfo.HasCamera); if (_deviceInfo.HasCamera) { TotpCell.Button.Image = "camera"; } TotpCell.Entry.DisableAutocapitalize = true; TotpCell.Entry.Autocorrect = false; TotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", WinPhone: "Courier"); PasswordCell = new FormEntryCell(AppResources.Password, isPassword: true, nextElement: TotpCell.Entry, useButton: true); PasswordCell.Button.Image = "eye"; PasswordCell.Entry.DisableAutocapitalize = true; PasswordCell.Entry.Autocorrect = false; PasswordCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", WinPhone: "Courier"); UsernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry); UsernameCell.Entry.DisableAutocapitalize = true; UsernameCell.Entry.Autocorrect = false; UriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: UsernameCell.Entry); if (!string.IsNullOrWhiteSpace(_defaultUri)) { UriCell.Entry.Text = _defaultUri; } NameCell = new FormEntryCell(AppResources.Name, nextElement: UriCell.Entry); if (!string.IsNullOrWhiteSpace(_defaultName)) { NameCell.Entry.Text = _defaultName; } var folderOptions = new List <string> { AppResources.FolderNone }; var folders = _folderService.GetAllAsync().GetAwaiter().GetResult() .OrderBy(f => f.Name?.Decrypt()).ToList(); foreach (var folder in folders) { folderOptions.Add(folder.Name.Decrypt()); } FolderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); GenerateCell = new ExtendedTextCell { Text = AppResources.GeneratePassword, ShowDisclousure = true }; var favoriteCell = new ExtendedSwitchCell { Text = AppResources.Favorite }; var table = new ExtendedTableView { Intent = TableIntent.Settings, EnableScrolling = true, HasUnevenRows = true, Root = new TableRoot { new TableSection(AppResources.LoginInformation) { NameCell, UriCell, UsernameCell, PasswordCell, GenerateCell }, new TableSection(" ") { TotpCell, FolderCell, favoriteCell }, new TableSection(AppResources.Notes) { NotesCell } } }; if (Device.RuntimePlatform == Device.iOS) { table.RowHeight = -1; table.EstimatedRowHeight = 70; } else if (Device.RuntimePlatform == Device.Android) { PasswordCell.Button.WidthRequest = 40; if (TotpCell.Button != null) { TotpCell.Button.WidthRequest = 40; } } var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() => { if (_lastAction.LastActionWasRecent()) { return; } _lastAction = DateTime.UtcNow; if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (string.IsNullOrWhiteSpace(NameCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); return; } var login = new Login { Name = NameCell.Entry.Text.Encrypt(), Uri = string.IsNullOrWhiteSpace(UriCell.Entry.Text) ? null : UriCell.Entry.Text.Encrypt(), Username = string.IsNullOrWhiteSpace(UsernameCell.Entry.Text) ? null : UsernameCell.Entry.Text.Encrypt(), Password = string.IsNullOrWhiteSpace(PasswordCell.Entry.Text) ? null : PasswordCell.Entry.Text.Encrypt(), Notes = string.IsNullOrWhiteSpace(NotesCell.Editor.Text) ? null : NotesCell.Editor.Text.Encrypt(), Totp = string.IsNullOrWhiteSpace(TotpCell.Entry.Text) ? null : TotpCell.Entry.Text.Encrypt(), Favorite = favoriteCell.On }; if (FolderCell.Picker.SelectedIndex > 0) { login.FolderId = folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id; } _userDialogs.ShowLoading(AppResources.Saving, MaskType.Black); var saveTask = await _loginService.SaveAsync(login); _userDialogs.HideLoading(); if (saveTask.Succeeded) { _userDialogs.Toast(AppResources.NewLoginCreated); if (_fromAutofill) { _googleAnalyticsService.TrackExtensionEvent("CreatedLogin"); } else { _googleAnalyticsService.TrackAppEvent("CreatedLogin"); } await Navigation.PopForDeviceAsync(); } else if (saveTask.Errors.Count() > 0) { await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred); } else { await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); } }, ToolbarItemOrder.Default, 0); Title = AppResources.AddLogin; Content = table; ToolbarItems.Add(saveToolBarItem); if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } }
private void Init() { var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult(); if (site == null) { // TODO: handle error. navigate back? should never happen... return; } var notesCell = new FormEditorCell(height: 90); notesCell.Editor.Text = site.Notes?.Decrypt(); 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 = Device.OnPlatform( iOS: "Courier", Android: "monospace", WinPhone: "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()).ToList(); int selectedIndex = 0; int i = 0; foreach (var folder in folders) { i++; if (folder.Id == site.FolderId) { selectedIndex = i; } folderOptions.Add(folder.Name.Decrypt()); } var folderCell = new FormPickerCell(AppResources.Folder, folderOptions.ToArray()); folderCell.Picker.SelectedIndex = selectedIndex; var favoriteCell = new ExtendedSwitchCell { Text = "Favorite", On = site.Favorite }; var deleteCell = new ExtendedTextCell { Text = AppResources.Delete, TextColor = Color.Red }; deleteCell.Tapped += DeleteCell_Tapped; var table = new ExtendedTableView { Intent = TableIntent.Settings, EnableScrolling = true, HasUnevenRows = true, Root = new TableRoot { new TableSection("Site Information") { nameCell, uriCell, usernameCell, PasswordCell, generateCell }, new TableSection { folderCell, favoriteCell }, new TableSection(AppResources.Notes) { notesCell }, new TableSection { deleteCell } } }; if (Device.OS == TargetPlatform.iOS) { table.RowHeight = -1; table.EstimatedRowHeight = 70; } var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async() => { if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok); return; } if (string.IsNullOrWhiteSpace(nameCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok); return; } 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.Notes = notesCell.Editor.Text?.Encrypt(); site.Favorite = favoriteCell.On; if (folderCell.Picker.SelectedIndex > 0) { site.FolderId = folders.ElementAt(folderCell.Picker.SelectedIndex - 1).Id; } else { site.FolderId = null; } _userDialogs.ShowLoading("Saving...", MaskType.Black); var saveTask = await _siteService.SaveAsync(site); _userDialogs.HideLoading(); if (saveTask.Succeeded) { await Navigation.PopForDeviceAsync(); _userDialogs.Toast("Site updated."); _googleAnalyticsService.TrackAppEvent("EditedSite"); } else if (saveTask.Errors.Count() > 0) { await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred); } else { await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); } }, ToolbarItemOrder.Default, 0); Title = "Edit Site"; Content = table; ToolbarItems.Add(saveToolBarItem); if (Device.OS == TargetPlatform.iOS) { ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel")); } }