2022-01-24 21:21:52 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
2021-05-13 20:36:20 +02:00
|
|
|
|
using System.Linq;
|
2019-05-31 20:18:32 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2021-11-24 20:09:39 +01:00
|
|
|
|
using Bit.App.Abstractions;
|
2021-05-13 20:36:20 +02:00
|
|
|
|
using Bit.App.Controls;
|
2021-11-24 20:09:39 +01:00
|
|
|
|
using Bit.App.Pages.Accounts;
|
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Bit.Core.Utilities;
|
2019-03-28 01:12:44 +01:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
2019-03-28 22:10:10 +01:00
|
|
|
|
namespace Bit.App.Pages
|
2019-03-28 01:12:44 +01:00
|
|
|
|
{
|
2019-05-14 17:53:41 +02:00
|
|
|
|
public partial class SettingsPage : BaseContentPage
|
2019-03-28 01:12:44 +01:00
|
|
|
|
{
|
2019-05-31 04:45:48 +02:00
|
|
|
|
private readonly IDeviceActionService _deviceActionService;
|
2019-05-31 20:15:37 +02:00
|
|
|
|
private readonly TabsPage _tabsPage;
|
2019-05-14 15:09:35 +02:00
|
|
|
|
private SettingsPageViewModel _vm;
|
|
|
|
|
|
2019-05-31 20:15:37 +02:00
|
|
|
|
public SettingsPage(TabsPage tabsPage)
|
2019-03-28 01:12:44 +01:00
|
|
|
|
{
|
2019-05-31 20:15:37 +02:00
|
|
|
|
_tabsPage = tabsPage;
|
2019-03-28 01:12:44 +01:00
|
|
|
|
InitializeComponent();
|
2019-05-31 04:45:48 +02:00
|
|
|
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
2019-05-14 15:09:35 +02:00
|
|
|
|
_vm = BindingContext as SettingsPageViewModel;
|
|
|
|
|
_vm.Page = this;
|
2019-03-28 01:12:44 +01:00
|
|
|
|
}
|
2019-05-14 17:53:41 +02:00
|
|
|
|
|
2019-05-31 20:18:32 +02:00
|
|
|
|
public async Task InitAsync()
|
2019-05-16 20:55:18 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.InitAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 18:05:18 +02:00
|
|
|
|
public void BuildList()
|
|
|
|
|
{
|
|
|
|
|
_vm.BuildList();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 20:15:37 +02:00
|
|
|
|
protected override bool OnBackButtonPressed()
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android && _tabsPage != null)
|
2019-05-31 20:15:37 +02:00
|
|
|
|
{
|
|
|
|
|
_tabsPage.ResetToVaultPage();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return base.OnBackButtonPressed();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 21:21:52 +01:00
|
|
|
|
void ActivateTimePicker(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var stackLayout = (ExtendedStackLayout)sender;
|
|
|
|
|
SettingsPageListItem item = (SettingsPageListItem)stackLayout.BindingContext;
|
|
|
|
|
if (item.ShowTimeInput)
|
|
|
|
|
{
|
|
|
|
|
var timePicker = stackLayout.Children.Where(x => x is TimePicker).FirstOrDefault();
|
|
|
|
|
((TimePicker)timePicker)?.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 15:42:38 +02:00
|
|
|
|
async void OnTimePickerPropertyChanged(object sender, PropertyChangedEventArgs args)
|
|
|
|
|
{
|
2022-04-26 17:21:17 +02:00
|
|
|
|
var s = (TimePicker)sender;
|
2021-09-23 15:42:38 +02:00
|
|
|
|
var time = s.Time.TotalMinutes;
|
|
|
|
|
if (s.IsFocused && args.PropertyName == "Time")
|
|
|
|
|
{
|
|
|
|
|
await _vm.VaultTimeoutAsync(false, (int)time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 20:36:20 +02:00
|
|
|
|
private async void RowSelected(object sender, SelectionChangedEventArgs e)
|
2019-05-14 17:53:41 +02:00
|
|
|
|
{
|
2021-05-13 20:36:20 +02:00
|
|
|
|
((ExtendedCollectionView)sender).SelectedItem = null;
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (!DoOnce())
|
2019-05-14 17:53:41 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-05-13 20:36:20 +02:00
|
|
|
|
if (!(e.CurrentSelection?.FirstOrDefault() is SettingsPageListItem item))
|
2019-05-14 17:53:41 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (item.Name == AppResources.Sync)
|
2019-05-14 18:05:30 +02:00
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new SyncPage()));
|
|
|
|
|
}
|
2020-11-17 15:37:57 +01:00
|
|
|
|
else if (item.Name == AppResources.AutofillServices)
|
2019-05-31 04:45:48 +02:00
|
|
|
|
{
|
2020-11-17 15:37:57 +01:00
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new AutofillServicesPage(this)));
|
2019-05-31 04:45:48 +02:00
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.PasswordAutofill)
|
2019-05-31 04:45:48 +02:00
|
|
|
|
{
|
2019-07-02 19:15:00 +02:00
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new AutofillPage()));
|
2019-05-31 04:45:48 +02:00
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.AppExtension)
|
2019-05-31 04:45:48 +02:00
|
|
|
|
{
|
2019-07-02 19:15:00 +02:00
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new ExtensionPage()));
|
2019-05-31 04:45:48 +02:00
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.Options)
|
2019-05-29 15:08:47 +02:00
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new OptionsPage()));
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.Folders)
|
2019-05-14 23:02:24 +02:00
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new FoldersPage()));
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.About)
|
2019-05-15 15:14:49 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.AboutAsync();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.HelpAndFeedback)
|
2019-05-15 18:54:48 +02:00
|
|
|
|
{
|
|
|
|
|
_vm.Help();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.FingerprintPhrase)
|
2019-05-15 18:54:48 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.FingerprintAsync();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.RateTheApp)
|
2019-05-15 19:09:49 +02:00
|
|
|
|
{
|
|
|
|
|
_vm.Rate();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.ImportItems)
|
2019-05-15 19:26:55 +02:00
|
|
|
|
{
|
|
|
|
|
_vm.Import();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.ExportVault)
|
2019-05-15 19:26:55 +02:00
|
|
|
|
{
|
2020-02-14 22:10:58 +01:00
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new ExportVaultPage()));
|
2019-05-15 19:26:55 +02:00
|
|
|
|
}
|
2021-08-04 21:46:28 +02:00
|
|
|
|
else if (item.Name == AppResources.LearnOrg)
|
2019-05-15 19:26:55 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.ShareAsync();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.WebVault)
|
2019-05-15 19:26:55 +02:00
|
|
|
|
{
|
|
|
|
|
_vm.WebVault();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.ChangeMasterPassword)
|
2019-05-15 19:26:55 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.ChangePasswordAsync();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.TwoStepLogin)
|
2019-05-15 19:26:55 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.TwoStepAsync();
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.LogOut)
|
2019-05-15 19:26:55 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.LogOutAsync();
|
|
|
|
|
}
|
2021-11-24 20:09:39 +01:00
|
|
|
|
else if (item.Name == AppResources.DeleteAccount)
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new DeleteAccountPage()));
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.LockNow)
|
2019-05-15 21:47:50 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.LockAsync();
|
|
|
|
|
}
|
2020-05-29 18:26:36 +02:00
|
|
|
|
else if (item.Name == AppResources.VaultTimeout)
|
2019-05-16 20:55:18 +02:00
|
|
|
|
{
|
2020-05-29 18:26:36 +02:00
|
|
|
|
await _vm.VaultTimeoutAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (item.Name == AppResources.VaultTimeoutAction)
|
|
|
|
|
{
|
|
|
|
|
await _vm.VaultTimeoutActionAsync();
|
2019-05-16 20:55:18 +02:00
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (item.Name == AppResources.UnlockWithPIN)
|
2019-05-16 21:54:21 +02:00
|
|
|
|
{
|
|
|
|
|
await _vm.UpdatePinAsync();
|
|
|
|
|
}
|
2019-07-22 16:12:14 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-08 14:25:13 +02:00
|
|
|
|
var biometricName = AppResources.Biometrics;
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (Device.RuntimePlatform == Device.iOS)
|
2019-07-22 16:12:14 +02:00
|
|
|
|
{
|
2019-10-23 15:11:48 +02:00
|
|
|
|
var supportsFace = await _deviceActionService.SupportsFaceBiometricAsync();
|
2020-06-08 14:25:13 +02:00
|
|
|
|
biometricName = supportsFace ? AppResources.FaceID : AppResources.TouchID;
|
2019-07-22 16:12:14 +02:00
|
|
|
|
}
|
2020-06-08 14:25:13 +02:00
|
|
|
|
if (item.Name == string.Format(AppResources.UnlockWith, biometricName))
|
2019-10-23 15:24:34 +02:00
|
|
|
|
{
|
2020-06-08 14:25:13 +02:00
|
|
|
|
await _vm.UpdateBiometricAsync();
|
2019-07-22 16:12:14 +02:00
|
|
|
|
}
|
2019-05-16 23:30:07 +02:00
|
|
|
|
}
|
2019-05-14 17:53:41 +02:00
|
|
|
|
}
|
2019-03-28 01:12:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|