From 470e08f1654e5e987a7a908ffe87356bf8335fa4 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Wed, 1 Mar 2023 13:28:28 -0300 Subject: [PATCH] [EC-1002] [BEEEP] Add ability to change language in app (#2299) * EC-1002 BEEEP Added ability to change language in app * EC-1002 fix format * EC-1002 Renamed IPreferencesStorageService to ISynchronousStorageService * EC-1002 Moved get/set Locale to the StateService and added the StorageMediatorService to a new way to interact with the storage. Later the StateService will only interact with this mediator instead of directly with the storage services, with this we have more control inside the mediator and we can have both sync and async methods to interact with storages handled by the mediator --- src/Android/MainApplication.cs | 9 ++- src/Android/Properties/AndroidManifest.xml | 4 +- src/App/Pages/Settings/OptionsPage.xaml | 16 +++++ src/App/Pages/Settings/OptionsPage.xaml.cs | 1 + .../Pages/Settings/OptionsPageViewModel.cs | 48 +++++++++++++- src/App/Resources/AppResources.Designer.cs | 36 +++++++++++ src/App/Resources/AppResources.resx | 12 ++++ src/App/Services/MobileI18nService.cs | 20 +++--- src/App/Services/PreferencesStorageService.cs | 43 ++++++++----- src/Core/Abstractions/II18nService.cs | 1 + src/Core/Abstractions/IStateService.cs | 3 + .../Abstractions/IStorageMediatorService.cs | 16 +++++ .../ISynchronousStorageService.cs | 9 +++ src/Core/Constants.cs | 1 + src/Core/Services/StateService.cs | 29 +++++++++ src/Core/Services/StorageMediatorOptions.cs | 8 +++ src/Core/Services/StorageMediatorService.cs | 62 +++++++++++++++++++ src/iOS.Core/Utilities/iOSCoreHelpers.cs | 9 ++- 18 files changed, 298 insertions(+), 29 deletions(-) create mode 100644 src/Core/Abstractions/IStorageMediatorService.cs create mode 100644 src/Core/Abstractions/ISynchronousStorageService.cs create mode 100644 src/Core/Services/StorageMediatorOptions.cs create mode 100644 src/Core/Services/StorageMediatorService.cs diff --git a/src/Android/MainApplication.cs b/src/Android/MainApplication.cs index db042bcf7..f0f094bc8 100644 --- a/src/Android/MainApplication.cs +++ b/src/Android/MainApplication.cs @@ -143,7 +143,8 @@ namespace Bit.Droid var secureStorageService = new SecureStorageService(); var cryptoPrimitiveService = new CryptoPrimitiveService(); var mobileStorageService = new MobileStorageService(preferencesStorage, liteDbStorage); - var stateService = new StateService(mobileStorageService, secureStorageService, messagingService); + var storageMediatorService = new StorageMediatorService(mobileStorageService, secureStorageService, preferencesStorage); + var stateService = new StateService(mobileStorageService, secureStorageService, storageMediatorService, messagingService); var stateMigrationService = new StateMigrationService(liteDbStorage, preferencesStorage, secureStorageService); var clipboardService = new ClipboardService(stateService); @@ -158,6 +159,7 @@ namespace Bit.Droid var cryptoService = new CryptoService(stateService, cryptoFunctionService); var passwordRepromptService = new MobilePasswordRepromptService(platformUtilsService, cryptoService); + ServiceContainer.Register(preferencesStorage); ServiceContainer.Register("broadcasterService", broadcasterService); ServiceContainer.Register("messagingService", messagingService); ServiceContainer.Register("localizeService", localizeService); @@ -165,6 +167,7 @@ namespace Bit.Droid ServiceContainer.Register("cryptoPrimitiveService", cryptoPrimitiveService); ServiceContainer.Register("storageService", mobileStorageService); ServiceContainer.Register("secureStorageService", secureStorageService); + ServiceContainer.Register(storageMediatorService); ServiceContainer.Register("stateService", stateService); ServiceContainer.Register("stateMigrationService", stateMigrationService); ServiceContainer.Register("clipboardService", clipboardService); @@ -197,7 +200,9 @@ namespace Bit.Droid private void Bootstrap() { - (ServiceContainer.Resolve("i18nService") as MobileI18nService).Init(); + var locale = ServiceContainer.Resolve().GetLocale(); + (ServiceContainer.Resolve("i18nService") as MobileI18nService) + .Init(locale != null ? new System.Globalization.CultureInfo(locale) : null); ServiceContainer.Resolve("authService").Init(); // Note: This is not awaited var bootstrapTask = BootstrapAsync(); diff --git a/src/Android/Properties/AndroidManifest.xml b/src/Android/Properties/AndroidManifest.xml index 3437c89d7..132622e50 100644 --- a/src/Android/Properties/AndroidManifest.xml +++ b/src/Android/Properties/AndroidManifest.xml @@ -45,11 +45,11 @@ - + - + \ No newline at end of file diff --git a/src/App/Pages/Settings/OptionsPage.xaml b/src/App/Pages/Settings/OptionsPage.xaml index 2f3abbf67..fb8a4966f 100644 --- a/src/App/Pages/Settings/OptionsPage.xaml +++ b/src/App/Pages/Settings/OptionsPage.xaml @@ -80,6 +80,22 @@ Text="{u:I18n ClearClipboardDescription}" StyleClass="box-footer-label" /> + + + +