From b5747fbb44571921fca25b28c2ff2cba64ac7c9b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 22 Mar 2018 11:07:41 -0400 Subject: [PATCH] show/hide loading are async now --- src/Android/Resources/Resource.Designer.cs | 33 +++++++++++++++---- src/Android/Services/DeviceActionService.cs | 18 +++++----- .../Services/IDeviceActionService.cs | 4 +-- src/App/Pages/LoginPage.cs | 4 +-- src/App/Pages/LoginTwoFactorPage.cs | 4 +-- src/App/Pages/PasswordHintPage.cs | 4 +-- src/App/Pages/RegisterPage.cs | 4 +-- .../Pages/Settings/SettingsAddFolderPage.cs | 4 +-- .../Pages/Settings/SettingsEditFolderPage.cs | 8 ++--- src/App/Pages/Settings/SettingsSyncPage.cs | 4 +-- src/App/Pages/Vault/VaultAddCipherPage.cs | 4 +-- src/App/Pages/Vault/VaultAttachmentsPage.cs | 8 ++--- src/App/Pages/Vault/VaultEditCipherPage.cs | 8 ++--- src/App/Pages/Vault/VaultViewCipherPage.cs | 4 +-- src/UWP/Services/DeviceActionService.cs | 6 ++-- .../Services/NoopDeviceActionService.cs | 8 ++--- src/iOS/Services/DeviceActionService.cs | 17 ++++++---- 17 files changed, 85 insertions(+), 57 deletions(-) diff --git a/src/Android/Resources/Resource.Designer.cs b/src/Android/Resources/Resource.Designer.cs index 0b96097c2..81cb43c92 100644 --- a/src/Android/Resources/Resource.Designer.cs +++ b/src/Android/Resources/Resource.Designer.cs @@ -6506,17 +6506,17 @@ namespace Bit.Android // aapt resource value: 0x7f0a0051 public const int ApplicationName = 2131361873; - // aapt resource value: 0x7f0a00ab - public const int AutoFillServiceDescription = 2131361963; + // aapt resource value: 0x7f0a00b2 + public const int AutoFillServiceDescription = 2131361970; - // aapt resource value: 0x7f0a00aa - public const int AutoFillServiceSummary = 2131361962; + // aapt resource value: 0x7f0a00b1 + public const int AutoFillServiceSummary = 2131361969; // aapt resource value: 0x7f0a0050 public const int Hello = 2131361872; - // aapt resource value: 0x7f0a00ac - public const int MyVault = 2131361964; + // aapt resource value: 0x7f0a00b3 + public const int MyVault = 2131361971; // aapt resource value: 0x7f0a0027 public const int abc_action_bar_home_description = 2131361831; @@ -6671,6 +6671,27 @@ namespace Bit.Android // aapt resource value: 0x7f0a000f public const int common_signin_button_text_long = 2131361807; + // aapt resource value: 0x7f0a00ac + public const int default_web_client_id = 2131361964; + + // aapt resource value: 0x7f0a00ad + public const int firebase_database_url = 2131361965; + + // aapt resource value: 0x7f0a00aa + public const int gcm_defaultSenderId = 2131361962; + + // aapt resource value: 0x7f0a00ae + public const int google_api_key = 2131361966; + + // aapt resource value: 0x7f0a00ab + public const int google_app_id = 2131361963; + + // aapt resource value: 0x7f0a00af + public const int google_crash_reporting_api_key = 2131361967; + + // aapt resource value: 0x7f0a00b0 + public const int google_storage_bucket = 2131361968; + // aapt resource value: 0x7f0a0052 public const int hockeyapp_crash_dialog_app_name_fallback = 2131361874; diff --git a/src/Android/Services/DeviceActionService.cs b/src/Android/Services/DeviceActionService.cs index 48509380f..4918166a6 100644 --- a/src/Android/Services/DeviceActionService.cs +++ b/src/Android/Services/DeviceActionService.cs @@ -445,11 +445,11 @@ namespace Bit.Android.Services } } - public void ShowLoading(string text) + public async Task ShowLoadingAsync(string text) { if(_progressDialog != null) { - HideLoading(); + await HideLoadingAsync(); } var activity = (MainActivity)CurrentContext; @@ -459,16 +459,16 @@ namespace Bit.Android.Services _progressDialog.Show(); } - public void HideLoading() + public Task HideLoadingAsync() { - if(_progressDialog == null) + if(_progressDialog != null) { - return; + _progressDialog.Dismiss(); + _progressDialog.Dispose(); + _progressDialog = null; } - _progressDialog.Dismiss(); - _progressDialog.Dispose(); - _progressDialog = null; + return Task.FromResult(0); } public Task DisplayPromptAync(string title = null, string description = null, string text = null) @@ -487,7 +487,7 @@ namespace Bit.Android.Services { InputType = global::Android.Text.InputTypes.ClassText }; - + if(text == null) { text = string.Empty; diff --git a/src/App/Abstractions/Services/IDeviceActionService.cs b/src/App/Abstractions/Services/IDeviceActionService.cs index f7fc2006b..074fd86d9 100644 --- a/src/App/Abstractions/Services/IDeviceActionService.cs +++ b/src/App/Abstractions/Services/IDeviceActionService.cs @@ -6,8 +6,8 @@ namespace Bit.App.Abstractions { public interface IDeviceActionService { - void ShowLoading(string text); - void HideLoading(); + Task ShowLoadingAsync(string text); + Task HideLoadingAsync(); void Toast(string text, bool longDuration = false); void CopyToClipboard(string text); bool OpenFile(byte[] fileData, string id, string fileName); diff --git a/src/App/Pages/LoginPage.cs b/src/App/Pages/LoginPage.cs index 5d8a2bc47..832f81aba 100644 --- a/src/App/Pages/LoginPage.cs +++ b/src/App/Pages/LoginPage.cs @@ -179,9 +179,9 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(AppResources.LoggingIn); + await _deviceActionService.ShowLoadingAsync(AppResources.LoggingIn); var result = await _authService.TokenPostAsync(EmailCell.Entry.Text, PasswordCell.Entry.Text); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(!result.Success) { diff --git a/src/App/Pages/LoginTwoFactorPage.cs b/src/App/Pages/LoginTwoFactorPage.cs index f1923ebf7..606fb50e2 100644 --- a/src/App/Pages/LoginTwoFactorPage.cs +++ b/src/App/Pages/LoginTwoFactorPage.cs @@ -416,10 +416,10 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(string.Concat(AppResources.Validating, "...")); + await _deviceActionService.ShowLoadingAsync(string.Concat(AppResources.Validating, "...")); var response = await _authService.TokenPostTwoFactorAsync(_providerType.Value, token, RememberCell.On, _email, _masterPasswordHash, _key); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(!response.Success) { diff --git a/src/App/Pages/PasswordHintPage.cs b/src/App/Pages/PasswordHintPage.cs index c38ddb798..26c944f74 100644 --- a/src/App/Pages/PasswordHintPage.cs +++ b/src/App/Pages/PasswordHintPage.cs @@ -123,9 +123,9 @@ namespace Bit.App.Pages Email = EmailCell.Entry.Text }; - _deviceActionService.ShowLoading(AppResources.Submitting); + await _deviceActionService.ShowLoadingAsync(AppResources.Submitting); var response = await _accountApiRepository.PostPasswordHintAsync(request); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(!response.Succeeded) { diff --git a/src/App/Pages/RegisterPage.cs b/src/App/Pages/RegisterPage.cs index 310757075..0bd35dc50 100644 --- a/src/App/Pages/RegisterPage.cs +++ b/src/App/Pages/RegisterPage.cs @@ -204,9 +204,9 @@ namespace Bit.App.Pages Key = encKey.EncryptedString }; - _deviceActionService.ShowLoading(AppResources.CreatingAccount); + await _deviceActionService.ShowLoadingAsync(AppResources.CreatingAccount); var response = await _accountsApiRepository.PostRegisterAsync(request); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(!response.Succeeded) { diff --git a/src/App/Pages/Settings/SettingsAddFolderPage.cs b/src/App/Pages/Settings/SettingsAddFolderPage.cs index c18ba43d9..097e693de 100644 --- a/src/App/Pages/Settings/SettingsAddFolderPage.cs +++ b/src/App/Pages/Settings/SettingsAddFolderPage.cs @@ -85,9 +85,9 @@ namespace Bit.App.Pages Name = NameCell.Entry.Text.Encrypt() }; - _deviceActionService.ShowLoading(AppResources.Saving); + await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveResult = await _folderService.SaveAsync(folder); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(saveResult.Succeeded) { diff --git a/src/App/Pages/Settings/SettingsEditFolderPage.cs b/src/App/Pages/Settings/SettingsEditFolderPage.cs index b69413460..f1f94a5e1 100644 --- a/src/App/Pages/Settings/SettingsEditFolderPage.cs +++ b/src/App/Pages/Settings/SettingsEditFolderPage.cs @@ -97,9 +97,9 @@ namespace Bit.App.Pages folder.Name = NameCell.Entry.Text.Encrypt(); - _deviceActionService.ShowLoading(AppResources.Saving); + await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveResult = await _folderService.SaveAsync(folder); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(saveResult.Succeeded) { @@ -161,9 +161,9 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(AppResources.Deleting); + await _deviceActionService.ShowLoadingAsync(AppResources.Deleting); var deleteTask = await _folderService.DeleteAsync(_folderId); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(deleteTask.Succeeded) { diff --git a/src/App/Pages/Settings/SettingsSyncPage.cs b/src/App/Pages/Settings/SettingsSyncPage.cs index 392387111..dee0c477c 100644 --- a/src/App/Pages/Settings/SettingsSyncPage.cs +++ b/src/App/Pages/Settings/SettingsSyncPage.cs @@ -101,9 +101,9 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(AppResources.Syncing); + await _deviceActionService.ShowLoadingAsync(AppResources.Syncing); var succeeded = await _syncService.FullSyncAsync(true); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(succeeded) { _deviceActionService.Toast(AppResources.SyncingComplete); diff --git a/src/App/Pages/Vault/VaultAddCipherPage.cs b/src/App/Pages/Vault/VaultAddCipherPage.cs index d7ffe60b2..7f41c8b0a 100644 --- a/src/App/Pages/Vault/VaultAddCipherPage.cs +++ b/src/App/Pages/Vault/VaultAddCipherPage.cs @@ -775,9 +775,9 @@ namespace Bit.App.Pages Helpers.ProcessFieldsSectionForSave(FieldsSection, cipher); - _deviceActionService.ShowLoading(AppResources.Saving); + await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveTask = await _cipherService.SaveAsync(cipher); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(saveTask.Succeeded) { diff --git a/src/App/Pages/Vault/VaultAttachmentsPage.cs b/src/App/Pages/Vault/VaultAttachmentsPage.cs index a439ce25a..7aeb6f37c 100644 --- a/src/App/Pages/Vault/VaultAttachmentsPage.cs +++ b/src/App/Pages/Vault/VaultAttachmentsPage.cs @@ -154,9 +154,9 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(AppResources.Saving); + await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveTask = await _cipherService.EncryptAndSaveAttachmentAsync(_cipher, _fileBytes, FileLabel.Text); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(saveTask.Succeeded) { @@ -280,9 +280,9 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(AppResources.Deleting); + await _deviceActionService.ShowLoadingAsync(AppResources.Deleting); var saveTask = await _cipherService.DeleteAttachmentAsync(_cipher, attachment.Id); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(saveTask.Succeeded) { diff --git a/src/App/Pages/Vault/VaultEditCipherPage.cs b/src/App/Pages/Vault/VaultEditCipherPage.cs index 8d57bd973..40f2a52fd 100644 --- a/src/App/Pages/Vault/VaultEditCipherPage.cs +++ b/src/App/Pages/Vault/VaultEditCipherPage.cs @@ -639,9 +639,9 @@ namespace Bit.App.Pages Helpers.ProcessFieldsSectionForSave(FieldsSection, Cipher); - _deviceActionService.ShowLoading(AppResources.Saving); + await _deviceActionService.ShowLoadingAsync(AppResources.Saving); var saveTask = await _cipherService.SaveAsync(Cipher); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(saveTask.Succeeded) { @@ -892,9 +892,9 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(AppResources.Deleting); + await _deviceActionService.ShowLoadingAsync(AppResources.Deleting); var deleteTask = await _cipherService.DeleteAsync(_cipherId); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(deleteTask.Succeeded) { diff --git a/src/App/Pages/Vault/VaultViewCipherPage.cs b/src/App/Pages/Vault/VaultViewCipherPage.cs index 8da39c72c..f377121c3 100644 --- a/src/App/Pages/Vault/VaultViewCipherPage.cs +++ b/src/App/Pages/Vault/VaultViewCipherPage.cs @@ -462,9 +462,9 @@ namespace Bit.App.Pages return; } - _deviceActionService.ShowLoading(AppResources.Downloading); + await _deviceActionService.ShowLoadingAsync(AppResources.Downloading); var data = await _cipherService.DownloadAndDecryptAttachmentAsync(attachment.Url, cipher.OrganizationId); - _deviceActionService.HideLoading(); + await _deviceActionService.HideLoadingAsync(); if(data == null) { diff --git a/src/UWP/Services/DeviceActionService.cs b/src/UWP/Services/DeviceActionService.cs index d81bdfe43..8f1a57c19 100644 --- a/src/UWP/Services/DeviceActionService.cs +++ b/src/UWP/Services/DeviceActionService.cs @@ -151,14 +151,16 @@ namespace Bit.UWP.Services }.Show(); } - public void ShowLoading(string text) + public Task ShowLoadingAsync(string text) { _userDialogs.ShowLoading(text, MaskType.Black); + return Task.FromResult(0); } - public void HideLoading() + public Task HideLoadingAsync() { _userDialogs.HideLoading(); + return Task.FromResult(0); } public Task LaunchAppAsync(string appName, Xamarin.Forms.Page page) diff --git a/src/iOS.Core/Services/NoopDeviceActionService.cs b/src/iOS.Core/Services/NoopDeviceActionService.cs index 956e99a0c..8236c7003 100644 --- a/src/iOS.Core/Services/NoopDeviceActionService.cs +++ b/src/iOS.Core/Services/NoopDeviceActionService.cs @@ -48,9 +48,9 @@ namespace Bit.iOS.Core.Services return Task.FromResult(null); } - public void HideLoading() + public Task HideLoadingAsync() { - // do nothing + return Task.FromResult(0); } public Task LaunchAppAsync(string appName, Page page) @@ -83,9 +83,9 @@ namespace Bit.iOS.Core.Services return Task.FromResult(0); } - public void ShowLoading(string text) + public Task ShowLoadingAsync(string text) { - // do nothing + return Task.FromResult(0); } public void Toast(string text, bool longDuration = false) diff --git a/src/iOS/Services/DeviceActionService.cs b/src/iOS/Services/DeviceActionService.cs index 22ce2ff34..1967ec81b 100644 --- a/src/iOS/Services/DeviceActionService.cs +++ b/src/iOS/Services/DeviceActionService.cs @@ -286,13 +286,15 @@ namespace Bit.iOS.Services throw new NotImplementedException(); } - public void ShowLoading(string text) + public Task ShowLoadingAsync(string text) { if(_progressAlert != null) { - HideLoading(); + HideLoadingAsync().GetAwaiter().GetResult(); } + var result = new TaskCompletionSource(); + var loadingIndicator = new UIActivityIndicatorView(new CGRect(10, 5, 50, 50)); loadingIndicator.HidesWhenStopped = true; loadingIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray; @@ -303,19 +305,22 @@ namespace Bit.iOS.Services _progressAlert.View.Add(loadingIndicator); var vc = GetPresentedViewController(); - vc?.PresentViewController(_progressAlert, false, null); + vc?.PresentViewController(_progressAlert, false, () => result.TrySetResult(0)); + return result.Task; } - public void HideLoading() + public Task HideLoadingAsync() { + var result = new TaskCompletionSource(); if(_progressAlert == null) { - return; + result.TrySetResult(0); } - _progressAlert.DismissViewController(false, null); + _progressAlert.DismissViewController(false, () => result.TrySetResult(0)); _progressAlert.Dispose(); _progressAlert = null; + return result.Task; } public Task LaunchAppAsync(string appName, Page page)