1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-04 09:33:16 +00:00

conditions around opening file

This commit is contained in:
Kyle Spearrin
2017-07-13 09:01:00 -04:00
parent eec4be1845
commit fe5cc1f8f3
22 changed files with 251 additions and 158 deletions

View File

@@ -4,5 +4,6 @@
{
void CopyToClipboard(string text);
bool OpenFile(byte[] fileData, string id, string fileName);
bool CanOpenFile(string fileName);
}
}

View File

@@ -13,7 +13,7 @@ namespace Bit.App.Models
Id = data.Id;
Url = data.Url;
FileName = data.FileName != null ? new CipherString(data.FileName) : null;
Size = data.Size;
SetSize(data.Size);
SizeName = data.SizeName;
}
@@ -22,19 +22,30 @@ namespace Bit.App.Models
Id = response.Id;
Url = response.Url;
FileName = response.FileName != null ? new CipherString(response.FileName) : null;
Size = response.Size;
SetSize(response.Size);
SizeName = response.SizeName;
}
public string Id { get; set; }
public string Url { get; set; }
public CipherString FileName { get; set; }
public string Size { get; set; }
public long Size { get; set; }
public string SizeName { get; set; }
public AttachmentData ToAttachmentData(string loginId)
{
return new AttachmentData(this, loginId);
}
private void SetSize(string sizeString)
{
long size;
if(!long.TryParse(sizeString, out size))
{
size = 0;
}
Size = size;
}
}
}

View File

@@ -16,7 +16,7 @@ namespace Bit.App.Models.Data
LoginId = loginId;
Url = attachment.Url;
FileName = attachment.FileName?.EncryptedString;
Size = attachment.Size;
Size = attachment.Size.ToString();
SizeName = attachment.SizeName;
}

View File

@@ -223,7 +223,8 @@ namespace Bit.App.Models.Page
{
Id = attachment.Id,
Name = attachment.FileName?.Decrypt(login.OrganizationId),
Size = attachment.SizeName,
SizeName = attachment.SizeName,
Size = attachment.Size,
Url = attachment.Url
});
}
@@ -239,7 +240,8 @@ namespace Bit.App.Models.Page
{
public string Id { get; set; }
public string Name { get; set; }
public string Size { get; set; }
public string SizeName { get; set; }
public long Size { get; set; }
public string Url { get; set; }
}
}

View File

@@ -196,7 +196,7 @@ namespace Bit.App.Pages
{
AttachmentsSection.Add(new AttachmentViewCell(attachment, async () =>
{
await SaveAttachmentAsync(attachment);
await OpenAttachmentAsync(attachment);
}));
}
Table.Root.Add(AttachmentsSection);
@@ -211,8 +211,22 @@ namespace Bit.App.Pages
EditItem.Dispose();
}
private async Task SaveAttachmentAsync(VaultViewLoginPageModel.Attachment attachment)
private async Task OpenAttachmentAsync(VaultViewLoginPageModel.Attachment attachment)
{
// 20 MB warning
if(attachment.Size >= 20971520 && !(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 _loginService.DownloadAndDecryptAttachmentAsync(null, attachment.Url);
_userDialogs.HideLoading();
@@ -222,8 +236,7 @@ namespace Bit.App.Pages
return;
}
var opened = _deviceActionService.OpenFile(data, attachment.Id, attachment.Name);
if(!opened)
if(!_deviceActionService.OpenFile(data, attachment.Id, attachment.Name))
{
await _userDialogs.AlertAsync(AppResources.UnableToOpenFile, null, AppResources.Ok);
return;
@@ -269,8 +282,8 @@ namespace Bit.App.Pages
{
_tapped = tappedAction;
Label.Text = attachment.Name;
Detail.Text = attachment.Size;
Icon.Source = "user"; // TODO: download icon
Detail.Text = attachment.SizeName;
Icon.Source = "download";
BackgroundColor = Color.White;
Tapped += AttachmentViewCell_Tapped;
}

View File

@@ -151,6 +151,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to This attachment is {0} in size. Are you sure you want to download it onto your device?.
/// </summary>
public static string AttachmentLargeWarning {
get {
return ResourceManager.GetString("AttachmentLargeWarning", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Attachments.
/// </summary>
@@ -2006,7 +2015,7 @@ namespace Bit.App.Resources {
}
/// <summary>
/// Looks up a localized string similar to Unable to open this type of file on your device..
/// Looks up a localized string similar to Your device cannot open this type of tile..
/// </summary>
public static string UnableToOpenFile {
get {

View File

@@ -912,10 +912,14 @@
<value>Unable to download file.</value>
</data>
<data name="UnableToOpenFile" xml:space="preserve">
<value>Unable to open this type of file on your device.</value>
<value>Your device cannot open this type of tile.</value>
</data>
<data name="Downloading" xml:space="preserve">
<value>Downloading...</value>
<comment>Message shown when downloading a file</comment>
</data>
<data name="AttachmentLargeWarning" xml:space="preserve">
<value>This attachment is {0} in size. Are you sure you want to download it onto your device?</value>
<comment>The placeholder will show the file size of the attachment. Ex "25 MB"</comment>
</data>
</root>

View File

@@ -20,9 +20,9 @@ namespace Bit.App
private void Init()
{
//BaseAddress = new Uri("http://169.254.80.80:4000"); // Desktop from VS Android Emulator
//BaseAddress = new Uri("http://192.168.1.6:4000"); // Desktop
BaseAddress = new Uri("http://192.168.1.4:4000"); // Desktop
//BaseAddress = new Uri("https://preview-api.bitwarden.com"); // Preview
BaseAddress = new Uri("https://api.bitwarden.com"); // Production
// BaseAddress = new Uri("https://api.bitwarden.com"); // Production
DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
}

View File

@@ -20,9 +20,9 @@ namespace Bit.App
private void Init()
{
//BaseAddress = new Uri("http://169.254.80.80:33656"); // Desktop from VS Android Emulator
//BaseAddress = new Uri("http://192.168.1.6:33656"); // Desktop
BaseAddress = new Uri("http://192.168.1.4:33656"); // Desktop
//BaseAddress = new Uri("https://identity-api.bitwarden.com"); // Preview
BaseAddress = new Uri("https://identity.bitwarden.com"); // Production
//BaseAddress = new Uri("https://identity.bitwarden.com"); // Production
DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
}