mirror of
https://github.com/bitwarden/android.git
synced 2024-11-01 07:35:52 +03:00
use formatted key
This commit is contained in:
parent
86f1874379
commit
9042702c09
1 changed files with 15 additions and 13 deletions
|
@ -19,27 +19,27 @@ namespace Bit.Core.Services
|
||||||
var objType = typeof(T);
|
var objType = typeof(T);
|
||||||
if(objType == typeof(string))
|
if(objType == typeof(string))
|
||||||
{
|
{
|
||||||
var val = Xamarin.Essentials.Preferences.Get(key, default(string));
|
var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(string));
|
||||||
return Task.FromResult((T)(object)val);
|
return Task.FromResult((T)(object)val);
|
||||||
}
|
}
|
||||||
else if(objType == typeof(int))
|
else if(objType == typeof(int))
|
||||||
{
|
{
|
||||||
var val = Xamarin.Essentials.Preferences.Get(key, default(int));
|
var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(int));
|
||||||
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
||||||
}
|
}
|
||||||
else if(objType == typeof(long))
|
else if(objType == typeof(long))
|
||||||
{
|
{
|
||||||
var val = Xamarin.Essentials.Preferences.Get(key, default(long));
|
var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(long));
|
||||||
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
||||||
}
|
}
|
||||||
else if(objType == typeof(double))
|
else if(objType == typeof(double))
|
||||||
{
|
{
|
||||||
var val = Xamarin.Essentials.Preferences.Get(key, default(double));
|
var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(double));
|
||||||
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
||||||
}
|
}
|
||||||
else if(objType == typeof(DateTime))
|
else if(objType == typeof(DateTime))
|
||||||
{
|
{
|
||||||
var val = Xamarin.Essentials.Preferences.Get(key, default(DateTime));
|
var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(DateTime));
|
||||||
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
return Task.FromResult((T)Convert.ChangeType(val, objType));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -50,31 +50,32 @@ namespace Bit.Core.Services
|
||||||
|
|
||||||
public Task SaveAsync<T>(string key, T obj)
|
public Task SaveAsync<T>(string key, T obj)
|
||||||
{
|
{
|
||||||
|
var formattedKey = string.Format(_keyFormat, key);
|
||||||
if(obj == null)
|
if(obj == null)
|
||||||
{
|
{
|
||||||
return RemoveAsync(key);
|
return RemoveAsync(formattedKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
var objType = typeof(T);
|
var objType = typeof(T);
|
||||||
if(objType == typeof(string))
|
if(objType == typeof(string))
|
||||||
{
|
{
|
||||||
Xamarin.Essentials.Preferences.Set(key, obj as string);
|
Xamarin.Essentials.Preferences.Set(formattedKey, obj as string);
|
||||||
}
|
}
|
||||||
else if(objType == typeof(int))
|
else if(objType == typeof(int))
|
||||||
{
|
{
|
||||||
Xamarin.Essentials.Preferences.Set(key, (obj as int?).Value);
|
Xamarin.Essentials.Preferences.Set(formattedKey, (obj as int?).Value);
|
||||||
}
|
}
|
||||||
else if(objType == typeof(long))
|
else if(objType == typeof(long))
|
||||||
{
|
{
|
||||||
Xamarin.Essentials.Preferences.Set(key, (obj as long?).Value);
|
Xamarin.Essentials.Preferences.Set(formattedKey, (obj as long?).Value);
|
||||||
}
|
}
|
||||||
else if(objType == typeof(double))
|
else if(objType == typeof(double))
|
||||||
{
|
{
|
||||||
Xamarin.Essentials.Preferences.Set(key, (obj as double?).Value);
|
Xamarin.Essentials.Preferences.Set(formattedKey, (obj as double?).Value);
|
||||||
}
|
}
|
||||||
else if(objType == typeof(DateTime))
|
else if(objType == typeof(DateTime))
|
||||||
{
|
{
|
||||||
Xamarin.Essentials.Preferences.Set(key, (obj as DateTime?).Value);
|
Xamarin.Essentials.Preferences.Set(formattedKey, (obj as DateTime?).Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -85,9 +86,10 @@ namespace Bit.Core.Services
|
||||||
|
|
||||||
public Task RemoveAsync(string key)
|
public Task RemoveAsync(string key)
|
||||||
{
|
{
|
||||||
if(Xamarin.Essentials.Preferences.ContainsKey(key))
|
var formattedKey = string.Format(_keyFormat, key);
|
||||||
|
if(Xamarin.Essentials.Preferences.ContainsKey(formattedKey))
|
||||||
{
|
{
|
||||||
Xamarin.Essentials.Preferences.Remove(key);
|
Xamarin.Essentials.Preferences.Remove(formattedKey);
|
||||||
}
|
}
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue