mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
* [PM-2658] Settings Reorganization Init (#2697) * PM-2658 Started settings reorganization (settings main + vault + about) * PM-2658 Added settings controls based on templates and implemented OtherSettingsPage * PM-2658 Fix format * [PM-3512] Settings Appearance (#2703) * PM-3512 Implemented new Appearance Settings * PM-3512 Fix format * [PM-3510] Implement Account Security Settings view (#2714) * PM-3510 Implemented Security settings view * PM-3510 Fix format * PM-3510 Added empty placeholder to pending login requests and also improved a11y on security settings view. * PM-3511 Implemented autofill settings view (#2735) * [PM-3695] Add Connect to Watch to Other settings (#2736) * PM-3511 Implemented autofill settings view * PM-3695 Add Connect to watch setting to other settings view * [PM-3693] Clear old Settings approach (#2737) * PM-3511 Implemented autofill settings view * PM-3693 Remove old Settings approach * PM-3845 Fix default dark theme description verbiage (#2759) * PM-3839 Fix allow screen capture and submit crash logs to init their state when the page appears (#2760) * PM-3834 Fix dialogs strings on settings (#2758) * [PM-3834] Fix import items link (#2782) * PM-3834 Fix import items link * PM-3834 Fix import items link, removed old link. * [PM-4092] Fix vault timeout policies on new Settings (#2796) * PM-4092 Fix vault timeout policy on settings for disabling controls and reset timeout when surpassing maximum * PM-4092 Removed testing hardcoding of policy data
112 lines
4.1 KiB
C#
112 lines
4.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using Bit.App.Abstractions;
|
|
using Bit.App.Resources;
|
|
using Bit.Core.Abstractions;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Utilities;
|
|
using Xamarin.CommunityToolkit.ObjectModel;
|
|
using Xamarin.Essentials;
|
|
|
|
namespace Bit.App.Pages
|
|
{
|
|
public partial class AutofillSettingsPageViewModel : BaseViewModel
|
|
{
|
|
private readonly IDeviceActionService _deviceActionService;
|
|
private readonly IAutofillHandler _autofillHandler;
|
|
private readonly IStateService _stateService;
|
|
private readonly IPlatformUtilsService _platformUtilsService;
|
|
|
|
private bool _inited;
|
|
private bool _copyTotpAutomatically;
|
|
|
|
public AutofillSettingsPageViewModel()
|
|
{
|
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>();
|
|
_autofillHandler = ServiceContainer.Resolve<IAutofillHandler>();
|
|
_stateService = ServiceContainer.Resolve<IStateService>();
|
|
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>();
|
|
|
|
DefaultUriMatchDetectionPickerViewModel = new PickerViewModel<UriMatchType>(
|
|
_deviceActionService,
|
|
ServiceContainer.Resolve<ILogger>(),
|
|
DefaultUriMatchDetectionChangingAsync,
|
|
AppResources.DefaultUriMatchDetection,
|
|
_ => _inited,
|
|
ex => HandleException(ex));
|
|
|
|
ToggleCopyTotpAutomaticallyCommand = CreateDefaultAsyncCommnad(ToggleCopyTotpAutomaticallyAsync, _ => _inited);
|
|
|
|
InitAndroidCommands();
|
|
InitIOSCommands();
|
|
}
|
|
|
|
public bool CopyTotpAutomatically
|
|
{
|
|
get => _copyTotpAutomatically;
|
|
set
|
|
{
|
|
if (SetProperty(ref _copyTotpAutomatically, value))
|
|
{
|
|
((ICommand)ToggleCopyTotpAutomaticallyCommand).Execute(null);
|
|
}
|
|
}
|
|
}
|
|
|
|
public PickerViewModel<UriMatchType> DefaultUriMatchDetectionPickerViewModel { get; }
|
|
|
|
public AsyncCommand ToggleCopyTotpAutomaticallyCommand { get; private set; }
|
|
|
|
public async Task InitAsync()
|
|
{
|
|
await InitAndroidAutofillSettingsAsync();
|
|
|
|
_copyTotpAutomatically = await _stateService.GetDisableAutoTotpCopyAsync() != true;
|
|
|
|
await InitDefaultUriMatchDetectionPickerViewModelAsync();
|
|
|
|
_inited = true;
|
|
|
|
await MainThread.InvokeOnMainThreadAsync(() =>
|
|
{
|
|
TriggerPropertyChanged(nameof(CopyTotpAutomatically));
|
|
|
|
ToggleUseAutofillServicesCommand.RaiseCanExecuteChanged();
|
|
ToggleUseInlineAutofillCommand.RaiseCanExecuteChanged();
|
|
ToggleUseAccessibilityCommand.RaiseCanExecuteChanged();
|
|
ToggleUseDrawOverCommand.RaiseCanExecuteChanged();
|
|
DefaultUriMatchDetectionPickerViewModel.SelectOptionCommand.RaiseCanExecuteChanged();
|
|
});
|
|
}
|
|
|
|
private async Task InitDefaultUriMatchDetectionPickerViewModelAsync()
|
|
{
|
|
var options = new Dictionary<UriMatchType, string>
|
|
{
|
|
[UriMatchType.Domain] = AppResources.BaseDomain,
|
|
[UriMatchType.Host] = AppResources.Host,
|
|
[UriMatchType.StartsWith] = AppResources.StartsWith,
|
|
[UriMatchType.RegularExpression] = AppResources.RegEx,
|
|
[UriMatchType.Exact] = AppResources.Exact,
|
|
[UriMatchType.Never] = AppResources.Never
|
|
};
|
|
|
|
var defaultUriMatchDetection = ((UriMatchType?)await _stateService.GetDefaultUriMatchAsync()) ?? UriMatchType.Domain;
|
|
|
|
DefaultUriMatchDetectionPickerViewModel.Init(options, defaultUriMatchDetection, UriMatchType.Domain);
|
|
}
|
|
|
|
private async Task ToggleCopyTotpAutomaticallyAsync()
|
|
{
|
|
await _stateService.SetDisableAutoTotpCopyAsync(!CopyTotpAutomatically);
|
|
}
|
|
|
|
private async Task<bool> DefaultUriMatchDetectionChangingAsync(UriMatchType type)
|
|
{
|
|
await _stateService.SetDefaultUriMatchAsync((int?)type);
|
|
return true;
|
|
}
|
|
}
|
|
}
|