public async Task SyncAsync() { if (!_connectivity.IsConnected) { AlertNoConnection(); return; } await _deviceActionService.ShowLoadingAsync(AppResources.Syncing); var succeeded = await _syncService.FullSyncAsync(true); await _deviceActionService.HideLoadingAsync(); if (succeeded) { _deviceActionService.Toast(AppResources.SyncingComplete); _googleAnalyticsService.TrackAppEvent("Synced"); } else { _deviceActionService.Toast(AppResources.SyncingFailed); } SetLastSync(); }
private async void PasswordButton2_Clicked(object sender, EventArgs e) { var page = new ToolsPasswordGeneratorPage((password) => { LoginPasswordCell.Entry.Text = password; _deviceActionService.Toast(AppResources.PasswordGenerated); }, _fromAutofill); await Navigation.PushForDeviceAsync(page); }
public async Task DismissRegisterAndLoginAsync(string email) { await Navigation.PopForDeviceAsync(); await Navigation.PushForDeviceAsync(new LoginPage(email)); _deviceActionService.Toast(AppResources.AccountCreated); }
public void ShowToast(string type, string title, string[] text, Dictionary <string, object> options = null) { if (text.Length > 0) { var longDuration = options != null && options.ContainsKey("longDuration") ? (bool)options["longDuration"] : false; _deviceActionService.Toast(text[0], longDuration); } }
private async void TotpButton_Clicked(object sender, EventArgs e) { var scanPage = new ScanPage((key) => { Device.BeginInvokeOnMainThread(async() => { await Navigation.PopModalAsync(); if (!string.IsNullOrWhiteSpace(key)) { LoginTotpCell.Entry.Text = key; _deviceActionService.Toast(AppResources.AuthenticatorKeyAdded); } else { await DisplayAlert(null, AppResources.AuthenticatorKeyReadError, AppResources.Ok); } }); }); await Navigation.PushModalAsync(new ExtendedNavigationPage(scanPage)); }
private void Init() { var folder = _folderService.GetByIdAsync(_folderId).GetAwaiter().GetResult(); if (folder == null) { // TODO: handle error. navigate back? should never happen... return; } NameCell = new FormEntryCell(AppResources.Name); NameCell.Entry.Text = folder.Name.Decrypt(); DeleteCell = new ExtendedTextCell { Text = AppResources.Delete, TextColor = Color.Red }; var mainTable = new ExtendedTableView { Intent = TableIntent.Settings, HasUnevenRows = true, Root = new TableRoot { new TableSection(Helpers.GetEmptyTableSectionTitle()) { NameCell }, new TableSection(Helpers.GetEmptyTableSectionTitle()) { DeleteCell } } }; if (Device.RuntimePlatform == Device.iOS) { mainTable.RowHeight = -1; mainTable.EstimatedRowHeight = 70; } else if (Device.RuntimePlatform == Device.Android) { mainTable.BottomPadding = 50; } var saveToolBarItem = new ToolbarItem(AppResources.Save, Helpers.ToolbarImage("envelope.png"), 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; } folder.Name = NameCell.Entry.Text.Encrypt(); _deviceActionService.ShowLoading(AppResources.Saving); var saveResult = await _folderService.SaveAsync(folder); _deviceActionService.HideLoading(); if (saveResult.Succeeded) { _deviceActionService.Toast(AppResources.FolderUpdated); _googleAnalyticsService.TrackAppEvent("EditedFolder"); await Navigation.PopForDeviceAsync(); } else if (saveResult.Errors.Count() > 0) { await DisplayAlert(AppResources.AnErrorHasOccurred, saveResult.Errors.First().Message, AppResources.Ok); } else { await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }, ToolbarItemOrder.Default, 0); Title = AppResources.EditFolder; Content = mainTable; ToolbarItems.Add(saveToolBarItem); if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.UWP) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } }
private void Init() { FieldsSection = new TableSection(Helpers.GetEmptyTableSectionTitle()); Table = new ExtendedTableView { Intent = TableIntent.Settings, EnableScrolling = true, HasUnevenRows = true, Root = new TableRoot { FieldsSection } }; NoDataLabel = new Label { Text = AppResources.NoCustomFields, HorizontalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(10, 40, 10, 0) }; SaveToolbarItem = new ToolbarItem(AppResources.Save, Helpers.ToolbarImage("envelope.png"), async() => { if (_lastAction.LastActionWasRecent() || _cipher == null) { return; } _lastAction = DateTime.UtcNow; if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (FieldsSection.Count > 0) { var fields = new List <Field>(); foreach (var cell in FieldsSection) { if (cell is FormEntryCell entryCell) { fields.Add(new Field { Name = string.IsNullOrWhiteSpace(entryCell.Label.Text) ? null : entryCell.Label.Text.Encrypt(_cipher.OrganizationId), Value = string.IsNullOrWhiteSpace(entryCell.Entry.Text) ? null : entryCell.Entry.Text.Encrypt(_cipher.OrganizationId), Type = entryCell.Entry.IsPassword ? FieldType.Hidden : FieldType.Text }); } else if (cell is ExtendedSwitchCell switchCell) { var value = switchCell.On ? "true" : "false"; fields.Add(new Field { Name = string.IsNullOrWhiteSpace(switchCell.Text) ? null : switchCell.Text.Encrypt(_cipher.OrganizationId), Value = value.Encrypt(_cipher.OrganizationId), Type = FieldType.Boolean }); } } _cipher.Fields = fields; } else { _cipher.Fields = null; } _deviceActionService.ShowLoading(AppResources.Saving); var saveTask = await _cipherService.SaveAsync(_cipher); _deviceActionService.HideLoading(); if (saveTask.Succeeded) { _deviceActionService.Toast(AppResources.CustomFieldsUpdated); _googleAnalyticsService.TrackAppEvent("UpdatedCustomFields"); await Navigation.PopForDeviceAsync(); } else if (saveTask.Errors.Count() > 0) { await DisplayAlert(AppResources.AnErrorHasOccurred, saveTask.Errors.First().Message, AppResources.Ok); } else { await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }, ToolbarItemOrder.Default, 0);
private void Init() { NameCell = new FormEntryCell(AppResources.Name); var table = new ExtendedTableView { Intent = TableIntent.Settings, EnableScrolling = false, HasUnevenRows = true, Root = new TableRoot { new TableSection(Helpers.GetEmptyTableSectionTitle()) { NameCell } } }; if (Device.RuntimePlatform == Device.iOS) { table.RowHeight = -1; table.EstimatedRowHeight = 70; } else if (Device.RuntimePlatform == Device.Android) { table.BottomPadding = 50; } var saveToolBarItem = new ToolbarItem(AppResources.Save, Helpers.ToolbarImage("envelope.png"), 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 folder = new Folder { Name = NameCell.Entry.Text.Encrypt() }; await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveResult = await _folderService.SaveAsync(folder); await _deviceActionService.HideLoadingAsync(); if (saveResult.Succeeded) { _deviceActionService.Toast(AppResources.FolderCreated); _googleAnalyticsService.TrackAppEvent("CreatedFolder"); await Navigation.PopForDeviceAsync(); } else if (saveResult.Errors.Count() > 0) { await DisplayAlert(AppResources.AnErrorHasOccurred, saveResult.Errors.First().Message, AppResources.Ok); } else { await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }, ToolbarItemOrder.Default, 0); Title = AppResources.AddFolder; Content = table; ToolbarItems.Add(saveToolBarItem); if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.UWP) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } }
private void InitSave() { var saveToolBarItem = new ToolbarItem(AppResources.Save, Helpers.ToolbarImage("envelope.png"), 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; } Cipher.Name = NameCell.Entry.Text.Encrypt(Cipher.OrganizationId); Cipher.Notes = string.IsNullOrWhiteSpace(NotesCell.Editor.Text) ? null : NotesCell.Editor.Text.Encrypt(Cipher.OrganizationId); Cipher.Favorite = FavoriteCell.On; switch (Cipher.Type) { case CipherType.Login: Cipher.Login = new Login { Uri = string.IsNullOrWhiteSpace(LoginUriCell.Entry.Text) ? null : LoginUriCell.Entry.Text.Encrypt(Cipher.OrganizationId), Username = string.IsNullOrWhiteSpace(LoginUsernameCell.Entry.Text) ? null : LoginUsernameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Password = string.IsNullOrWhiteSpace(LoginPasswordCell.Entry.Text) ? null : LoginPasswordCell.Entry.Text.Encrypt(Cipher.OrganizationId), Totp = string.IsNullOrWhiteSpace(LoginTotpCell.Entry.Text) ? null : LoginTotpCell.Entry.Text.Encrypt(Cipher.OrganizationId), }; break; case CipherType.SecureNote: Cipher.SecureNote = new SecureNote { Type = SecureNoteType.Generic }; break; case CipherType.Card: string brand; switch (CardBrandCell.Picker.SelectedIndex) { case 1: brand = "Visa"; break; case 2: brand = "Mastercard"; break; case 3: brand = "Amex"; break; case 4: brand = "Discover"; break; case 5: brand = "Diners Club"; break; case 6: brand = "JCB"; break; case 7: brand = "Maestro"; break; case 8: brand = "UnionPay"; break; case 9: brand = "Other"; break; default: brand = null; break; } var expMonth = CardExpMonthCell.Picker.SelectedIndex > 0 ? CardExpMonthCell.Picker.SelectedIndex.ToString() : null; Cipher.Card = new Card { CardholderName = string.IsNullOrWhiteSpace(CardNameCell.Entry.Text) ? null : CardNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Number = string.IsNullOrWhiteSpace(CardNumberCell.Entry.Text) ? null : CardNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), ExpYear = string.IsNullOrWhiteSpace(CardExpYearCell.Entry.Text) ? null : CardExpYearCell.Entry.Text.Encrypt(Cipher.OrganizationId), Code = string.IsNullOrWhiteSpace(CardCodeCell.Entry.Text) ? null : CardCodeCell.Entry.Text.Encrypt(Cipher.OrganizationId), Brand = string.IsNullOrWhiteSpace(brand) ? null : brand.Encrypt(Cipher.OrganizationId), ExpMonth = string.IsNullOrWhiteSpace(expMonth) ? null : expMonth.Encrypt(Cipher.OrganizationId) }; break; case CipherType.Identity: string title; switch (IdTitleCell.Picker.SelectedIndex) { case 1: title = AppResources.Mr; break; case 2: title = AppResources.Mrs; break; case 3: title = AppResources.Ms; break; case 4: title = AppResources.Dr; break; default: title = null; break; } Cipher.Identity = new Identity { Title = string.IsNullOrWhiteSpace(title) ? null : title.Encrypt(Cipher.OrganizationId), FirstName = string.IsNullOrWhiteSpace(IdFirstNameCell.Entry.Text) ? null : IdFirstNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), MiddleName = string.IsNullOrWhiteSpace(IdMiddleNameCell.Entry.Text) ? null : IdMiddleNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), LastName = string.IsNullOrWhiteSpace(IdLastNameCell.Entry.Text) ? null : IdLastNameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Username = string.IsNullOrWhiteSpace(IdUsernameCell.Entry.Text) ? null : IdUsernameCell.Entry.Text.Encrypt(Cipher.OrganizationId), Company = string.IsNullOrWhiteSpace(IdCompanyCell.Entry.Text) ? null : IdCompanyCell.Entry.Text.Encrypt(Cipher.OrganizationId), SSN = string.IsNullOrWhiteSpace(IdSsnCell.Entry.Text) ? null : IdSsnCell.Entry.Text.Encrypt(Cipher.OrganizationId), PassportNumber = string.IsNullOrWhiteSpace(IdPassportNumberCell.Entry.Text) ? null : IdPassportNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), LicenseNumber = string.IsNullOrWhiteSpace(IdLicenseNumberCell.Entry.Text) ? null : IdLicenseNumberCell.Entry.Text.Encrypt(Cipher.OrganizationId), Email = string.IsNullOrWhiteSpace(IdEmailCell.Entry.Text) ? null : IdEmailCell.Entry.Text.Encrypt(Cipher.OrganizationId), Phone = string.IsNullOrWhiteSpace(IdPhoneCell.Entry.Text) ? null : IdPhoneCell.Entry.Text.Encrypt(Cipher.OrganizationId), Address1 = string.IsNullOrWhiteSpace(IdAddress1Cell.Entry.Text) ? null : IdAddress1Cell.Entry.Text.Encrypt(Cipher.OrganizationId), Address2 = string.IsNullOrWhiteSpace(IdAddress2Cell.Entry.Text) ? null : IdAddress2Cell.Entry.Text.Encrypt(Cipher.OrganizationId), Address3 = string.IsNullOrWhiteSpace(IdAddress3Cell.Entry.Text) ? null : IdAddress3Cell.Entry.Text.Encrypt(Cipher.OrganizationId), City = string.IsNullOrWhiteSpace(IdCityCell.Entry.Text) ? null : IdCityCell.Entry.Text.Encrypt(Cipher.OrganizationId), State = string.IsNullOrWhiteSpace(IdStateCell.Entry.Text) ? null : IdStateCell.Entry.Text.Encrypt(Cipher.OrganizationId), PostalCode = string.IsNullOrWhiteSpace(IdPostalCodeCell.Entry.Text) ? null : IdPostalCodeCell.Entry.Text.Encrypt(Cipher.OrganizationId), Country = string.IsNullOrWhiteSpace(IdCountryCell.Entry.Text) ? null : IdCountryCell.Entry.Text.Encrypt(Cipher.OrganizationId) }; break; default: break; } if (FolderCell.Picker.SelectedIndex > 0) { Cipher.FolderId = Folders.ElementAt(FolderCell.Picker.SelectedIndex - 1).Id; } else { Cipher.FolderId = null; } _deviceActionService.ShowLoading(AppResources.Saving); var saveTask = await _cipherService.SaveAsync(Cipher); _deviceActionService.HideLoading(); if (saveTask.Succeeded) { _deviceActionService.Toast(AppResources.ItemUpdated); _googleAnalyticsService.TrackAppEvent("EditedCipher"); await Navigation.PopForDeviceAsync(); } else if (saveTask.Errors.Count() > 0) { await DisplayAlert(AppResources.AnErrorHasOccurred, saveTask.Errors.First().Message, AppResources.Ok); } else { await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }, ToolbarItemOrder.Default, 0); ToolbarItems.Add(saveToolBarItem); }
private void Init() { _canUseAttachments = _cryptoService.EncKey != null; SubscribeFileResult(true); var selectButton = new ExtendedButton { Text = AppResources.ChooseFile, Command = new Command(async() => await _deviceActionService.SelectFileAsync()), Style = (Style)Application.Current.Resources["btn-primaryAccent"], FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button)) }; FileLabel = new Label { Text = AppResources.NoFileChosen, Style = (Style)Application.Current.Resources["text-muted"], FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), HorizontalTextAlignment = TextAlignment.Center }; AddNewStackLayout = new StackLayout { Children = { selectButton, FileLabel }, Orientation = StackOrientation.Vertical, Padding = new Thickness(20, Helpers.OnPlatform(iOS: 10, Android: 20), 20, 20), VerticalOptions = LayoutOptions.Start }; NewTable = new ExtendedTableView { Intent = TableIntent.Settings, HasUnevenRows = true, NoFooter = true, EnableScrolling = false, EnableSelection = false, VerticalOptions = LayoutOptions.Start, Margin = new Thickness(0, Helpers.OnPlatform(iOS: 10, Android: 30), 0, 0), WrappingStackLayout = () => NoDataStackLayout, Root = new TableRoot { new TableSection(AppResources.AddNewAttachment) { new ExtendedViewCell { View = AddNewStackLayout, BackgroundColor = Color.White } } } }; ListView = new ExtendedListView(ListViewCachingStrategy.RecycleElement) { ItemsSource = PresentationAttchments, HasUnevenRows = true, ItemTemplate = new DataTemplate(() => new VaultAttachmentsViewCell()), VerticalOptions = LayoutOptions.FillAndExpand }; NoDataLabel = new Label { Text = AppResources.NoAttachments, HorizontalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), Style = (Style)Application.Current.Resources["text-muted"] }; NoDataStackLayout = new RedrawableStackLayout { VerticalOptions = LayoutOptions.Start, Spacing = 0, Margin = new Thickness(0, 40, 0, 0) }; SaveToolbarItem = new ToolbarItem(AppResources.Save, Helpers.ToolbarImage("envelope.png"), async() => { if (_lastAction.LastActionWasRecent() || _cipher == null) { return; } _lastAction = DateTime.UtcNow; if (!_canUseAttachments) { await ShowUpdateKeyAsync(); return; } if (!_connectivity.IsConnected) { AlertNoConnection(); return; } if (_fileBytes == null) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.File), AppResources.Ok); return; } await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveTask = await _cipherService.EncryptAndSaveAttachmentAsync(_cipher, _fileBytes, FileLabel.Text); await _deviceActionService.HideLoadingAsync(); if (saveTask.Succeeded) { _fileBytes = null; FileLabel.Text = AppResources.NoFileChosen; _deviceActionService.Toast(AppResources.AttachementAdded); _googleAnalyticsService.TrackAppEvent("AddedAttachment"); await LoadAttachmentsAsync(); } else if (saveTask.Errors.Count() > 0) { await DisplayAlert(AppResources.AnErrorHasOccurred, saveTask.Errors.First().Message, AppResources.Ok); } else { await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }, ToolbarItemOrder.Default, 0); Title = AppResources.Attachments; Content = ListView; if (Device.RuntimePlatform == Device.iOS) { ListView.RowHeight = -1; NewTable.RowHeight = -1; NewTable.EstimatedRowHeight = 44; NewTable.HeightRequest = 180; ListView.BackgroundColor = Color.Transparent; ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Close)); } else if (Device.RuntimePlatform == Device.Android) { ListView.BottomPadding = 50; } }