1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-30 04:17:55 +02:00
bitwarden-mobile/src/App/Pages/Settings/OptionsPageViewModel.cs

74 lines
2.4 KiB
C#
Raw Normal View History

2019-05-29 15:08:47 +02:00
using Bit.App.Abstractions;
using Bit.App.Resources;
2019-05-29 15:36:57 +02:00
using Bit.Core;
2019-05-29 15:08:47 +02:00
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using System.Threading.Tasks;
namespace Bit.App.Pages
{
public class OptionsPageViewModel : BaseViewModel
{
private readonly IDeviceActionService _deviceActionService;
private readonly IPlatformUtilsService _platformUtilsService;
2019-05-29 15:36:57 +02:00
private readonly IStorageService _storageService;
private readonly ITotpService _totpService;
private readonly IStateService _stateService;
private bool _disableFavicon;
private bool _disableAutoTotpCopy;
2019-05-29 15:08:47 +02:00
public OptionsPageViewModel()
{
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
2019-05-29 15:36:57 +02:00
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_totpService = ServiceContainer.Resolve<ITotpService>("totpService");
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
2019-05-29 15:08:47 +02:00
PageTitle = AppResources.Options;
}
2019-05-29 15:36:57 +02:00
public bool DisableFavicon
{
get => _disableFavicon;
set
{
if(SetProperty(ref _disableFavicon, value))
{
var task = UpdateDisableFaviconAsync();
}
}
}
public bool DisableAutoTotpCopy
{
get => _disableAutoTotpCopy;
set
{
if(SetProperty(ref _disableAutoTotpCopy, value))
{
var task = UpdateAutoTotpCopyAsync();
}
}
}
public async Task InitAsync()
{
DisableAutoTotpCopy = !(await _totpService.IsAutoCopyEnabledAsync());
DisableFavicon = await _storageService.GetAsync<bool>(Constants.DisableFaviconKey);
}
private async Task UpdateAutoTotpCopyAsync()
{
await _storageService.SaveAsync(Constants.DisableAutoTotpCopyKey, DisableAutoTotpCopy);
}
private async Task UpdateDisableFaviconAsync()
{
await _storageService.SaveAsync(Constants.DisableFaviconKey, DisableFavicon);
await _stateService.SaveAsync(Constants.DisableFaviconKey, DisableFavicon);
}
2019-05-29 15:08:47 +02:00
}
}