mirror of
https://github.com/bitwarden/mobile
synced 2025-12-18 17:23:18 +00:00
[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
This commit is contained in:
committed by
GitHub
parent
5164762f2e
commit
470e08f165
@@ -14,8 +14,11 @@ namespace Bit.Core.Services
|
||||
{
|
||||
public class StateService : IStateService
|
||||
{
|
||||
// TODO: Refactor this removing all storage services and use the IStorageMediatorService instead
|
||||
|
||||
private readonly IStorageService _storageService;
|
||||
private readonly IStorageService _secureStorageService;
|
||||
private readonly IStorageMediatorService _storageMediatorService;
|
||||
private readonly IMessagingService _messagingService;
|
||||
|
||||
private State _state;
|
||||
@@ -25,10 +28,12 @@ namespace Bit.Core.Services
|
||||
|
||||
public StateService(IStorageService storageService,
|
||||
IStorageService secureStorageService,
|
||||
IStorageMediatorService storageMediatorService,
|
||||
IMessagingService messagingService)
|
||||
{
|
||||
_storageService = storageService;
|
||||
_secureStorageService = secureStorageService;
|
||||
_storageMediatorService = storageMediatorService;
|
||||
_messagingService = messagingService;
|
||||
}
|
||||
|
||||
@@ -891,6 +896,16 @@ namespace Bit.Core.Services
|
||||
await SetValueAsync(Constants.AutoDarkThemeKey, value, await GetDefaultStorageOptionsAsync());
|
||||
}
|
||||
|
||||
public string GetLocale()
|
||||
{
|
||||
return _storageMediatorService.Get<string>(Constants.AppLocaleKey);
|
||||
}
|
||||
|
||||
public void SetLocale(string locale)
|
||||
{
|
||||
_storageMediatorService.Save(Constants.AppLocaleKey, locale);
|
||||
}
|
||||
|
||||
public async Task<bool?> GetAddSitePromptShownAsync(string userId = null)
|
||||
{
|
||||
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
|
||||
@@ -1222,11 +1237,13 @@ namespace Bit.Core.Services
|
||||
|
||||
// Helpers
|
||||
|
||||
[Obsolete("Use IStorageMediatorService instead")]
|
||||
private async Task<T> GetValueAsync<T>(string key, StorageOptions options)
|
||||
{
|
||||
return await GetStorageService(options).GetAsync<T>(key);
|
||||
}
|
||||
|
||||
[Obsolete("Use IStorageMediatorService instead")]
|
||||
private async Task SetValueAsync<T>(string key, T value, StorageOptions options)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -1237,11 +1254,17 @@ namespace Bit.Core.Services
|
||||
await GetStorageService(options).SaveAsync(key, value);
|
||||
}
|
||||
|
||||
[Obsolete("Use IStorageMediatorService instead")]
|
||||
private IStorageService GetStorageService(StorageOptions options)
|
||||
{
|
||||
return options.UseSecureStorage.GetValueOrDefault(false) ? _secureStorageService : _storageService;
|
||||
}
|
||||
|
||||
private async Task<string> ComposeKeyAsync(Func<string, string> userDependantKey, string userId = null)
|
||||
{
|
||||
return userDependantKey(userId ?? await GetActiveUserIdAsync());
|
||||
}
|
||||
|
||||
private async Task<Account> GetAccountAsync(StorageOptions options)
|
||||
{
|
||||
await CheckStateAsync();
|
||||
@@ -1437,6 +1460,12 @@ namespace Bit.Core.Services
|
||||
return requestedOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default options for storage.
|
||||
/// If it's only used for composing the constant key with the user id
|
||||
/// then use <see cref="ComposeKeyAsync(Func{string, string}, string)"/> instead
|
||||
/// which saves time if the user id is already known
|
||||
/// </summary>
|
||||
private async Task<StorageOptions> GetDefaultStorageOptionsAsync()
|
||||
{
|
||||
return new StorageOptions()
|
||||
|
||||
Reference in New Issue
Block a user