mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
mobile storage service
This commit is contained in:
parent
41321e3c9e
commit
d1c1aff7d9
1 changed files with 52 additions and 0 deletions
52
src/Core/Services/MobileStorageService.cs
Normal file
52
src/Core/Services/MobileStorageService.cs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
using Bit.Core.Abstractions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bit.Core.Services
|
||||||
|
{
|
||||||
|
public class MobileStorageService : IStorageService
|
||||||
|
{
|
||||||
|
private readonly IStorageService _preferencesStorageService;
|
||||||
|
private readonly IStorageService _liteDbStorageService;
|
||||||
|
|
||||||
|
private readonly HashSet<string> _preferenceStorageKeys = new HashSet<string>
|
||||||
|
{
|
||||||
|
Constants.LockOptionKey
|
||||||
|
};
|
||||||
|
|
||||||
|
public MobileStorageService(
|
||||||
|
IStorageService preferenceStorageService,
|
||||||
|
IStorageService liteDbStorageService)
|
||||||
|
{
|
||||||
|
_preferencesStorageService = preferenceStorageService;
|
||||||
|
_liteDbStorageService = liteDbStorageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<T> GetAsync<T>(string key)
|
||||||
|
{
|
||||||
|
if(_preferenceStorageKeys.Contains(key))
|
||||||
|
{
|
||||||
|
return _preferencesStorageService.GetAsync<T>(key);
|
||||||
|
}
|
||||||
|
return _liteDbStorageService.GetAsync<T>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SaveAsync<T>(string key, T obj)
|
||||||
|
{
|
||||||
|
if(_preferenceStorageKeys.Contains(key))
|
||||||
|
{
|
||||||
|
return _preferencesStorageService.SaveAsync(key, obj);
|
||||||
|
}
|
||||||
|
return _liteDbStorageService.SaveAsync(key, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task RemoveAsync(string key)
|
||||||
|
{
|
||||||
|
if(_preferenceStorageKeys.Contains(key))
|
||||||
|
{
|
||||||
|
return _preferencesStorageService.RemoveAsync(key);
|
||||||
|
}
|
||||||
|
return _liteDbStorageService.RemoveAsync(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue