1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-08 11:33:31 +00:00

attachment updates

This commit is contained in:
Kyle Spearrin
2017-07-24 10:34:22 -04:00
parent d14b23ca82
commit b920e7e95c
24 changed files with 142 additions and 31 deletions

View File

@@ -6,10 +6,11 @@ namespace Bit.App.Controls
public class VaultAttachmentsViewCell : LabeledRightDetailCell
{
public VaultAttachmentsViewCell()
: base(false)
{
Label.SetBinding(Label.TextProperty, nameof(VaultAttachmentsPageModel.Attachment.Name));
Detail.SetBinding(Label.TextProperty, nameof(VaultAttachmentsPageModel.Attachment.SizeName));
Icon.Source = "trash";
Detail.MinimumWidthRequest = 100;
BackgroundColor = Color.White;
if(Device.RuntimePlatform == Device.iOS)

View File

@@ -22,10 +22,13 @@ namespace Bit.App.Pages
private readonly IConnectivity _connectivity;
private readonly IDeviceActionService _deviceActiveService;
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly ITokenService _tokenService;
private readonly ICryptoService _cryptoService;
private readonly string _loginId;
private Login _login;
private byte[] _fileBytes;
private DateTime? _lastAction;
private bool _canUseAttachments = true;
public VaultAttachmentsPage(string loginId)
: base(true)
@@ -36,6 +39,8 @@ namespace Bit.App.Pages
_userDialogs = Resolver.Resolve<IUserDialogs>();
_deviceActiveService = Resolver.Resolve<IDeviceActionService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_tokenService = Resolver.Resolve<ITokenService>();
_cryptoService = Resolver.Resolve<ICryptoService>();
Init();
}
@@ -51,6 +56,8 @@ namespace Bit.App.Pages
private void Init()
{
_canUseAttachments = _cryptoService.EncKey != null;
SubscribeFileResult(true);
var selectButton = new ExtendedButton
{
@@ -103,10 +110,14 @@ namespace Bit.App.Pages
ItemsSource = PresentationAttchments,
HasUnevenRows = true,
ItemTemplate = new DataTemplate(() => new VaultAttachmentsViewCell()),
Footer = NewTable,
VerticalOptions = LayoutOptions.FillAndExpand
};
if(_tokenService.TokenPremium)
{
ListView.Footer = NewTable;
}
NoDataLabel = new Label
{
Text = AppResources.NoAttachments,
@@ -130,6 +141,13 @@ namespace Bit.App.Pages
}
_lastAction = DateTime.UtcNow;
if(!_canUseAttachments)
{
await ShowUpdateKeyAsync();
return;
}
if(!_connectivity.IsConnected)
{
AlertNoConnection();
@@ -168,7 +186,11 @@ namespace Bit.App.Pages
Title = AppResources.Attachments;
Content = ListView;
ToolbarItems.Add(saveToolBarItem);
if(_tokenService.TokenPremium)
{
ToolbarItems.Add(saveToolBarItem);
}
if(Device.RuntimePlatform == Device.iOS)
{
@@ -186,6 +208,11 @@ namespace Bit.App.Pages
base.OnAppearing();
ListView.ItemSelected += AttachmentSelected;
await LoadAttachmentsAsync();
if(_tokenService.TokenPremium && !_canUseAttachments)
{
await ShowUpdateKeyAsync();
}
}
protected override void OnDisappearing()
@@ -235,30 +262,28 @@ namespace Bit.App.Pages
((ListView)sender).SelectedItem = null;
var buttons = new List<string> { };
var selection = await DisplayActionSheet(attachment.Name, AppResources.Cancel, AppResources.Delete,
buttons.ToArray());
if(selection == AppResources.Delete)
if(!await _userDialogs.ConfirmAsync(AppResources.DoYouReallyWantToDelete, null, AppResources.Yes, AppResources.No))
{
_userDialogs.ShowLoading(AppResources.Deleting, MaskType.Black);
var saveTask = await _loginService.DeleteAttachmentAsync(_login, attachment.Id);
_userDialogs.HideLoading();
return;
}
if(saveTask.Succeeded)
{
_userDialogs.Toast(AppResources.AttachmentDeleted);
_googleAnalyticsService.TrackAppEvent("DeletedAttachment");
await LoadAttachmentsAsync();
}
else if(saveTask.Errors.Count() > 0)
{
await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{
await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
}
_userDialogs.ShowLoading(AppResources.Deleting, MaskType.Black);
var saveTask = await _loginService.DeleteAttachmentAsync(_login, attachment.Id);
_userDialogs.HideLoading();
if(saveTask.Succeeded)
{
_userDialogs.Toast(AppResources.AttachmentDeleted);
_googleAnalyticsService.TrackAppEvent("DeletedAttachment");
await LoadAttachmentsAsync();
}
else if(saveTask.Errors.Count() > 0)
{
await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{
await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
}
}
@@ -284,5 +309,15 @@ namespace Bit.App.Pages
SubscribeFileResult(true);
});
}
private async Task ShowUpdateKeyAsync()
{
var confirmed = await _userDialogs.ConfirmAsync(AppResources.UpdateKey, AppResources.FeatureUnavailable,
AppResources.LearnMore, AppResources.Cancel);
if(confirmed)
{
Device.OpenUri(new Uri("https://help.bitwarden.com"));
}
}
}
}

View File

@@ -231,7 +231,7 @@ namespace Bit.App.Pages
{
Table.Root.Remove(AttachmentsSection);
}
if(Model.ShowAttachments)
if(Model.ShowAttachments && _tokenService.TokenPremium)
{
AttachmentsSection = new TableSection(AppResources.Attachments);
AttachmentCells = new List<AttachmentViewCell>();

View File

@@ -1024,6 +1024,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Feature Unavailable.
/// </summary>
public static string FeatureUnavailable {
get {
return ResourceManager.GetString("FeatureUnavailable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to File.
/// </summary>
@@ -1267,6 +1276,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Learn More.
/// </summary>
public static string LearnMore {
get {
return ResourceManager.GetString("LearnMore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Length.
/// </summary>
@@ -1537,6 +1555,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Maximum file size is 100 MB..
/// </summary>
public static string MaxFileSize {
get {
return ResourceManager.GetString("MaxFileSize", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Minimum Numbers.
/// </summary>
@@ -2221,6 +2248,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to You cannot use this feature until you update your encryption key..
/// </summary>
public static string UpdateKey {
get {
return ResourceManager.GetString("UpdateKey", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to URI.
/// </summary>

View File

@@ -986,4 +986,16 @@
<data name="FileSource" xml:space="preserve">
<value>File Source</value>
</data>
<data name="FeatureUnavailable" xml:space="preserve">
<value>Feature Unavailable</value>
</data>
<data name="MaxFileSize" xml:space="preserve">
<value>Maximum file size is 100 MB.</value>
</data>
<data name="UpdateKey" xml:space="preserve">
<value>You cannot use this feature until you update your encryption key.</value>
</data>
<data name="LearnMore" xml:space="preserve">
<value>Learn More</value>
</data>
</root>