Exemplo n.º 1
0
 public AttachmentViewCell(VaultViewCipherPageModel.Attachment attachment, Action tappedAction)
 {
     _tapped                    = tappedAction;
     Label.Text                 = attachment.Name;
     Detail.Text                = attachment.SizeName;
     Icon.Source                = "download.png";
     BackgroundColor            = Color.White;
     Detail.MinimumWidthRequest = 100;
 }
        private async Task OpenAttachmentAsync(Cipher cipher, VaultViewCipherPageModel.Attachment attachment)
        {
            if (!Helpers.CanAccessPremium() && !cipher.OrganizationUseTotp)
            {
                await DisplayAlert(null, AppResources.PremiumRequired, AppResources.Ok);

                return;
            }

            // 10 MB warning
            if (attachment.Size >= 10485760 && !(await DisplayAlert(
                                                     null, string.Format(AppResources.AttachmentLargeWarning, attachment.SizeName),
                                                     AppResources.Yes, AppResources.No)))
            {
                return;
            }

            if (!_deviceActionService.CanOpenFile(attachment.Name))
            {
                await DisplayAlert(null, AppResources.UnableToOpenFile, AppResources.Ok);

                return;
            }

            await _deviceActionService.ShowLoadingAsync(AppResources.Downloading);

            var data = await _cipherService.DownloadAndDecryptAttachmentAsync(attachment.Url, attachment.Key,
                                                                              cipher.OrganizationId);

            await _deviceActionService.HideLoadingAsync();

            if (data == null)
            {
                await DisplayAlert(null, AppResources.UnableToDownloadFile, AppResources.Ok);

                return;
            }

            if (!_deviceActionService.OpenFile(data, attachment.Id, attachment.Name))
            {
                await DisplayAlert(null, AppResources.UnableToOpenFile, AppResources.Ok);

                return;
            }
        }
Exemplo n.º 3
0
        private async Task OpenAttachmentAsync(Cipher cipher, VaultViewCipherPageModel.Attachment attachment)
        {
            if (!_tokenService.TokenPremium && !cipher.OrganizationUseTotp)
            {
                _userDialogs.Alert(AppResources.PremiumRequired);
                return;
            }

            // 10 MB warning
            if (attachment.Size >= 10485760 && !(await _userDialogs.ConfirmAsync(
                                                     string.Format(AppResources.AttachmentLargeWarning, attachment.SizeName), null,
                                                     AppResources.Yes, AppResources.No)))
            {
                return;
            }

            if (!_deviceActionService.CanOpenFile(attachment.Name))
            {
                await _userDialogs.AlertAsync(AppResources.UnableToOpenFile, null, AppResources.Ok);

                return;
            }

            _userDialogs.ShowLoading(AppResources.Downloading, MaskType.Black);
            var data = await _cipherService.DownloadAndDecryptAttachmentAsync(attachment.Url, cipher.OrganizationId);

            _userDialogs.HideLoading();
            if (data == null)
            {
                await _userDialogs.AlertAsync(AppResources.UnableToDownloadFile, null, AppResources.Ok);

                return;
            }

            if (!_deviceActionService.OpenFile(data, attachment.Id, attachment.Name))
            {
                await _userDialogs.AlertAsync(AppResources.UnableToOpenFile, null, AppResources.Ok);

                return;
            }
        }