Ejemplo n.º 1
0
        public async Task MigrateAccount()
        {
            await _deviceActionService.ShowLoadingAsync(AppResources.Loading);

            await _keyConnectorService.MigrateUser();

            await _syncService.FullSyncAsync(true);

            await _deviceActionService.HideLoadingAsync();
        }
Ejemplo n.º 2
0
        public async Task Execute(IActionFlowParmeters parameters)
        {
            try
            {
                await _deviceActionService.ShowLoadingAsync(AppResources.DeletingYourAccount);

                await _apiService.DeleteAccountAsync(new Core.Models.Request.DeleteAccountRequest
                {
                    MasterPasswordHash = parameters.VerificationType == Core.Enums.VerificationType.MasterPassword ? parameters.Secret : (string)null,
                    OTP = parameters.VerificationType == Core.Enums.VerificationType.OTP ? parameters.Secret : (string)null
                });

                await _deviceActionService.HideLoadingAsync();

                _messagingService.Send("logout");

                await _platformUtilsService.ShowDialogAsync(AppResources.YourAccountHasBeenPermanentlyDeleted);
            }
            catch (ApiException apiEx)
            {
                await _deviceActionService.HideLoadingAsync();

                if (apiEx?.Error != null)
                {
                    await _platformUtilsService.ShowDialogAsync(apiEx.Error.GetSingleMessage(), AppResources.AnErrorHasOccurred);
                }
            }
            catch (System.Exception ex)
            {
                await _deviceActionService.HideLoadingAsync();

                _logger.Exception(ex);
                await _platformUtilsService.ShowDialogAsync(AppResources.AnErrorHasOccurred);
            }
        }
Ejemplo n.º 3
0
        private async Task SubmitAsync()
        {
            if (string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                  AppResources.EmailAddress), AppResources.Ok);

                return;
            }

            var request = new PasswordHintRequest
            {
                Email = EmailCell.Entry.Text
            };

            await _deviceActionService.ShowLoadingAsync(AppResources.Submitting);

            var response = await _accountApiRepository.PostPasswordHintAsync(request);

            await _deviceActionService.HideLoadingAsync();

            if (!response.Succeeded)
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok);

                return;
            }
            else
            {
                await DisplayAlert(null, AppResources.PasswordHintAlert, AppResources.Ok);
            }

            await Navigation.PopAsync();
        }
        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();
        }
Ejemplo n.º 5
0
        public async Task SubmitAsync()
        {
            if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
            {
                await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
                                                            AppResources.InternetConnectionRequiredTitle);

                return;
            }
            if (string.IsNullOrWhiteSpace(Email))
            {
                await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
                                        string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress),
                                        AppResources.Ok);

                return;
            }

            // Cozy customization, Email is not an email, it represents the Cozy URL as in
            // the login page : email validation check is disabled.
            if (false && !Email.Contains("@"))
            {
                await Page.DisplayAlert(AppResources.AnErrorHasOccurred, AppResources.InvalidEmail, AppResources.Ok);

                return;
            }

            #region cozy
            var cozyURL = Email;
            await _cozyClientService.ConfigureEnvironmentFromCozyURLAsync(cozyURL);

            #endregion

            try
            {
                await _deviceActionService.ShowLoadingAsync(AppResources.Submitting);

                await _apiService.PostPasswordHintAsync(
                    new Core.Models.Request.PasswordHintRequest {
                    Email = Email
                });

                await _deviceActionService.HideLoadingAsync();

                await Page.DisplayAlert(null, AppResources.PasswordHintAlert, AppResources.Ok);

                await Page.Navigation.PopModalAsync();
            }
            catch (ApiException e)
            {
                await _deviceActionService.HideLoadingAsync();

                if (e?.Error != null)
                {
                    await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(),
                                                                AppResources.AnErrorHasOccurred);
                }
            }
        }
        public async Task DeleteAccountAsync()
        {
            try
            {
                if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
                {
                    await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
                                                                AppResources.InternetConnectionRequiredTitle, AppResources.Ok);

                    return;
                }

                var(password, valid) = await _passwordRepromptService.ShowPasswordPromptAndGetItAsync();

                if (!valid)
                {
                    return;
                }

                await _deviceActionService.ShowLoadingAsync(AppResources.DeletingYourAccount);

                var masterPasswordHashKey = await _cryptoService.HashPasswordAsync(password, null);

                await _apiService.DeleteAccountAsync(new Core.Models.Request.DeleteAccountRequest
                {
                    MasterPasswordHash = masterPasswordHashKey
                });

                await _deviceActionService.HideLoadingAsync();

                _messagingService.Send("logout");

                await _platformUtilsService.ShowDialogAsync(AppResources.YourAccountHasBeenPermanentlyDeleted);
            }
            catch (ApiException apiEx)
            {
                await _deviceActionService.HideLoadingAsync();

                if (apiEx?.Error != null)
                {
                    await _platformUtilsService.ShowDialogAsync(apiEx.Error.GetSingleMessage(), AppResources.AnErrorHasOccurred);
                }
            }
            catch (System.Exception ex)
            {
                await _deviceActionService.HideLoadingAsync();

#if !FDROID
                Crashes.TrackError(ex);
#endif
                await _platformUtilsService.ShowDialogAsync(AppResources.AnErrorHasOccurred);
            }
        }
Ejemplo n.º 7
0
        private async Task LogIn()
        {
            if (string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                  AppResources.EmailAddress), AppResources.Ok);

                return;
            }

            if (string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                                  AppResources.MasterPassword), AppResources.Ok);

                return;
            }

            await _deviceActionService.ShowLoadingAsync(AppResources.LoggingIn);

            var result = await _authService.TokenPostAsync(EmailCell.Entry.Text, PasswordCell.Entry.Text);

            await _deviceActionService.HideLoadingAsync();

            if (!result.Success)
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, result.ErrorMessage, AppResources.Ok);

                return;
            }

            PasswordCell.Entry.Text = string.Empty;

            if (result.TwoFactorRequired)
            {
                _googleAnalyticsService.TrackAppEvent("LoggedIn To Two-step");
                await Navigation.PushAsync(new LoginTwoFactorPage(EmailCell.Entry.Text, result));

                return;
            }

            _googleAnalyticsService.TrackAppEvent("LoggedIn");

            if (Device.RuntimePlatform == Device.Android)
            {
                _pushNotification.Register();
            }

            var task = Task.Run(async() => await _syncService.FullSyncAsync(true));

            Application.Current.MainPage = new MainPage();
        }
Ejemplo n.º 8
0
        public async Task SubmitAsync()
        {
            if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.None)
            {
                await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
                                                            AppResources.InternetConnectionRequiredTitle);

                return;
            }
            if (string.IsNullOrWhiteSpace(Email))
            {
                await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
                                        string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress),
                                        AppResources.Ok);

                return;
            }
            if (!Email.Contains("@"))
            {
                await Page.DisplayAlert(AppResources.AnErrorHasOccurred, AppResources.InvalidEmail, AppResources.Ok);

                return;
            }

            try
            {
                await _deviceActionService.ShowLoadingAsync(AppResources.Submitting);

                await _apiService.PostPasswordHintAsync(
                    new Core.Models.Request.PasswordHintRequest {
                    Email = Email
                });

                await _deviceActionService.HideLoadingAsync();

                await Page.DisplayAlert(null, AppResources.PasswordHintAlert, AppResources.Ok);

                await Page.Navigation.PopModalAsync();
            }
            catch (ApiException e)
            {
                await _deviceActionService.HideLoadingAsync();

                if (e?.Error != null)
                {
                    await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(),
                                                                AppResources.AnErrorHasOccurred);
                }
            }
        }
Ejemplo n.º 9
0
        public async Task SubmitAsync()
        {
            if (string.IsNullOrWhiteSpace(Email))
            {
                await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
                                        string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress),
                                        AppResources.Ok);

                return;
            }
            if (!Email.Contains("@"))
            {
                await Page.DisplayAlert(AppResources.AnErrorHasOccurred, AppResources.InvalidEmail, AppResources.Ok);

                return;
            }

            try
            {
                await _deviceActionService.ShowLoadingAsync(AppResources.Submitting);

                await _apiService.PostPasswordHintAsync(
                    new Core.Models.Request.PasswordHintRequest {
                    Email = Email
                });

                await _deviceActionService.HideLoadingAsync();

                await Page.DisplayAlert(null, AppResources.PasswordHintAlert, AppResources.Ok);

                await Page.Navigation.PopModalAsync();
            }
            catch (ApiException e)
            {
                await _deviceActionService.HideLoadingAsync();

                await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
            }
        }
Ejemplo n.º 10
0
        private async void CipherSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var cipher = e.SelectedItem as Cipher;

            if (cipher == null)
            {
                return;
            }

            string selection = null;

            if (!string.IsNullOrWhiteSpace(_uri))
            {
                var options = new List <string> {
                    AppResources.Autofill
                };
                if (cipher.Type == Enums.CipherType.Login && _connectivity.IsConnected)
                {
                    options.Add(AppResources.AutofillAndSave);
                }
                options.Add(AppResources.View);
                selection = await DisplayActionSheet(AppResources.AutofillOrView, AppResources.Cancel, null,
                                                     options.ToArray());
            }

            if (selection == AppResources.View || string.IsNullOrWhiteSpace(_uri))
            {
                var page = new VaultViewCipherPage(cipher.Type, cipher.Id);
                await Navigation.PushForDeviceAsync(page);
            }
            else if (selection == AppResources.Autofill || selection == AppResources.AutofillAndSave)
            {
                if (selection == AppResources.AutofillAndSave)
                {
                    if (!_connectivity.IsConnected)
                    {
                        Helpers.AlertNoConnection(this);
                    }
                    else
                    {
                        var uris = cipher.CipherModel.Login?.Uris?.ToList();
                        if (uris == null)
                        {
                            uris = new List <Models.LoginUri>();
                        }

                        uris.Add(new Models.LoginUri
                        {
                            Uri   = _uri.Encrypt(cipher.CipherModel.OrganizationId),
                            Match = null
                        });

                        cipher.CipherModel.Login.Uris = uris;

                        await _deviceActionService.ShowLoadingAsync(AppResources.Saving);

                        var saveTask = await _cipherService.SaveAsync(cipher.CipherModel);

                        await _deviceActionService.HideLoadingAsync();

                        if (saveTask.Succeeded)
                        {
                            _googleAnalyticsService.TrackAppEvent("AddedLoginUriDuringAutofill");
                        }
                    }
                }

                if (_deviceInfoService.Version < 21)
                {
                    Helpers.CipherMoreClickedAsync(this, cipher, !string.IsNullOrWhiteSpace(_uri));
                }
                else
                {
                    _googleAnalyticsService.TrackExtensionEvent("AutoFilled",
                                                                _uri.StartsWith("http") ? "Website" : "App");
                    _deviceActionService.Autofill(cipher);
                }
            }

            ((ListView)sender).SelectedItem = null;
        }
Ejemplo n.º 11
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));
            }
        }
Ejemplo n.º 12
0
        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
                    {
                        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),
                    };

                    Helpers.ProcessUrisSectionForSave(UrisSection, Cipher);
                    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;
                }

                Helpers.ProcessFieldsSectionForSave(FieldsSection, Cipher);

                await _deviceActionService.ShowLoadingAsync(AppResources.Saving);
                var saveTask = await _cipherService.SaveAsync(Cipher);
                await _deviceActionService.HideLoadingAsync();

                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);
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        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("save.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();

                await _deviceActionService.ShowLoadingAsync(AppResources.Saving);
                var saveResult = await _folderService.SaveAsync(folder);
                await _deviceActionService.HideLoadingAsync();

                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));
            }
        }